src/Entity/Customer.php line 61

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Controller\Action\DeleteCustomerController;
  4. use App\Controller\Action\DeleteSitesController;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use ApiPlatform\Metadata\ApiResource;
  9. use ApiPlatform\Metadata\Delete;
  10. use ApiPlatform\Metadata\Get;
  11. use ApiPlatform\Metadata\GetCollection;
  12. use ApiPlatform\Metadata\Post;
  13. use ApiPlatform\Metadata\Put;
  14. use App\Controller\Action\SiteTreeAction;
  15. use App\Traits\AutoTimestampTrait;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. use Symfony\Component\Serializer\Annotation\Groups;
  18. #[ORM\Table(name'customer')]
  19. #[ORM\Entity]
  20. #[ORM\HasLifecycleCallbacks]
  21. #[ApiResource(
  22.     normalizationContext: ['groups' => ['customer.get','user.get''discussion.get']],
  23.     operations: [
  24.         new Post(
  25.             security'user.isMasterAdmin()',
  26.         ),
  27.         new Get(
  28.             name'_api_/customers/tree',
  29.             uriTemplate'/customers/tree',
  30.             controllerSiteTreeAction::class,
  31.             writefalse,
  32.             readfalse,
  33.             cacheHeaders: ['max_age' => 3600'shared_max_age' => 3600]
  34.         ),
  35.         new GetCollection(
  36.             paginationEnabledfalse,
  37.             order: ['name' => 'ASC']
  38.         ),
  39.         new Get(
  40.         ),
  41.         new Put(
  42.             security'user.isMasterAdmin()',
  43.         ),
  44.         new Delete(
  45.             security'user.isMasterAdmin()',
  46.         ),
  47.         new Post(
  48.             name'_api_/delete_customer',
  49.             uriTemplate'/delete_customer',
  50.             controllerDeleteCustomerController::class,
  51.             writefalse,
  52.             readfalse
  53.         ),
  54.     ]
  55. )]
  56. class Customer
  57. {
  58.     use AutoTimestampTrait;
  59.     #[ORM\Column(name'id'type'integer'nullablefalse)]
  60.     #[ORM\Id]
  61.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  62.     #[Groups(['customer.get''user.get'])]
  63.     private int $id;
  64.     #[ORM\Column(name'old_id'type'string'length255nullabletrue)]
  65.     private ?string $oldId null;
  66.     #[ORM\Column(name'code'type'string'length255nullabletrue)]
  67.     #[Assert\NotBlank]
  68.     #[Groups(['customer.get''user.get'])]
  69.     private ?string $code null;
  70.     #[ORM\Column(name'reference'type'string'length255nullabletrue)]
  71.     #[Groups(['customer.get''user.get'])]
  72.     private ?string $reference null;
  73.     #[ORM\Column(name'name'type'string'length255nullabletrue)]
  74.     #[Assert\NotBlank]
  75.     #[Groups(['customer.get''user.get''discussion.get'])]
  76.     private ?string $name null;
  77.     #[ORM\OneToMany(mappedBy'customer'targetEntityUser::class)]
  78.     private Collection $users;
  79. //    #[Groups(['customer.get'])]
  80.     #[ORM\OneToMany(mappedBy'customer'targetEntitySite::class)]
  81.     private Collection $sites;
  82.     #[ORM\Column(nullabletrue)]
  83.     #[Groups(['customer.get''user.get'])]
  84.     private ?int $year null;
  85.     public function __construct()
  86.     {
  87.         $this->users = new ArrayCollection();
  88.         $this->sites = new ArrayCollection();
  89.     }
  90.     /**
  91.      * @return Collection<int, Site>
  92.      */
  93.     public function getSites(): Collection
  94.     {
  95.         return $this->sites;
  96.     }
  97.     public function setSites($sites): self
  98.     {
  99.         $this->sites $sites;
  100.         return $this;
  101.     }
  102.     public function addSite(Site $site): self
  103.     {
  104.         if (!$this->sites->contains($site)) {
  105.             $this->sites->add($site);
  106.             $site->setCustomer($this);
  107.         }
  108.         return $this;
  109.     }
  110.     public function removeSite(Site $site): self
  111.     {
  112.         if ($this->sites->removeElement($site)) {
  113.             // set the owning side to null (unless already changed)
  114.             if ($site->getCustomer() === $this) {
  115.                 $site->setCustomer(null);
  116.             }
  117.         }
  118.         return $this;
  119.     }
  120.     public function getId(): ?int
  121.     {
  122.         return $this->id;
  123.     }
  124.     public function getOldId(): ?string
  125.     {
  126.         return $this->oldId;
  127.     }
  128.     public function setOldId(?string $oldId): self
  129.     {
  130.         $this->oldId $oldId;
  131.         return $this;
  132.     }
  133.     public function getCode(): ?string
  134.     {
  135.         return $this->code;
  136.     }
  137.     public function setCode(?string $code): self
  138.     {
  139.         $this->code $code;
  140.         return $this;
  141.     }
  142.     public function getReference(): ?string
  143.     {
  144.         return $this->reference;
  145.     }
  146.     public function setReference(?string $reference): self
  147.     {
  148.         $this->reference $reference;
  149.         return $this;
  150.     }
  151.     public function getName(): ?string
  152.     {
  153.         return $this->name;
  154.     }
  155.     public function setName(?string $name): self
  156.     {
  157.         $this->name $name;
  158.         return $this;
  159.     }
  160.     /**
  161.      * @return Collection<int, User>
  162.      */
  163.     public function getUsers(): Collection
  164.     {
  165.         return $this->users;
  166.     }
  167.     public function addUser(User $user): self
  168.     {
  169.         if (!$this->users->contains($user)) {
  170.             $this->users->add($user);
  171.             $user->setCustomer($this);
  172.         }
  173.         return $this;
  174.     }
  175.     public function removeUser(User $user): self
  176.     {
  177.         if ($this->users->removeElement($user)) {
  178.             // set the owning side to null (unless already changed)
  179.             if ($user->getCustomer() === $this) {
  180.                 $user->setCustomer(null);
  181.             }
  182.         }
  183.         return $this;
  184.     }
  185.     /*
  186.     public function getSites(): array
  187.     {
  188.         return $this->sites;
  189.     }
  190.     public function setSites($sites): self
  191.     {
  192.         $this->sites = $sites;
  193.         return $this;
  194.     }*/
  195.     public function getYear(): ?int
  196.     {
  197.         return $this->year;
  198.     }
  199.     public function setYear(?int $year): self
  200.     {
  201.         $this->year $year;
  202.         return $this;
  203.     }
  204. }