src/Entity/Customer.php line 60

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.         ),
  34.         new GetCollection(
  35.             paginationEnabledfalse,
  36.             order: ['name' => 'ASC']
  37.         ),
  38.         new Get(
  39.         ),
  40.         new Put(
  41.             security'user.isMasterAdmin()',
  42.         ),
  43.         new Delete(
  44.             security'user.isMasterAdmin()',
  45.         ),
  46.         new Post(
  47.             name'_api_/delete_customer',
  48.             uriTemplate'/delete_customer',
  49.             controllerDeleteCustomerController::class,
  50.             writefalse,
  51.             readfalse
  52.         ),
  53.     ]
  54. )]
  55. class Customer
  56. {
  57.     use AutoTimestampTrait;
  58.     #[ORM\Column(name'id'type'integer'nullablefalse)]
  59.     #[ORM\Id]
  60.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  61.     #[Groups(['customer.get''user.get'])]
  62.     private int $id;
  63.     #[ORM\Column(name'old_id'type'string'length255nullabletrue)]
  64.     private ?string $oldId null;
  65.     #[ORM\Column(name'code'type'string'length255nullabletrue)]
  66.     #[Assert\NotBlank]
  67.     #[Groups(['customer.get''user.get'])]
  68.     private ?string $code null;
  69.     #[ORM\Column(name'reference'type'string'length255nullabletrue)]
  70.     #[Groups(['customer.get''user.get'])]
  71.     private ?string $reference null;
  72.     #[ORM\Column(name'name'type'string'length255nullabletrue)]
  73.     #[Assert\NotBlank]
  74.     #[Groups(['customer.get''user.get''discussion.get'])]
  75.     private ?string $name null;
  76.     #[ORM\OneToMany(mappedBy'customer'targetEntityUser::class)]
  77.     private Collection $users;
  78. //    #[Groups(['customer.get'])]
  79.     #[ORM\OneToMany(mappedBy'customer'targetEntitySite::class)]
  80.     private Collection $sites;
  81.     #[ORM\Column(nullabletrue)]
  82.     #[Groups(['customer.get''user.get'])]
  83.     private ?int $year null;
  84.     public function __construct()
  85.     {
  86.         $this->users = new ArrayCollection();
  87.         $this->sites = new ArrayCollection();
  88.     }
  89.     /**
  90.      * @return Collection<int, Site>
  91.      */
  92.     public function getSites(): Collection
  93.     {
  94.         return $this->sites;
  95.     }
  96.     public function setSites($sites): self
  97.     {
  98.         $this->sites $sites;
  99.         return $this;
  100.     }
  101.     public function addSite(Site $site): self
  102.     {
  103.         if (!$this->sites->contains($site)) {
  104.             $this->sites->add($site);
  105.             $site->setCustomer($this);
  106.         }
  107.         return $this;
  108.     }
  109.     public function removeSite(Site $site): self
  110.     {
  111.         if ($this->sites->removeElement($site)) {
  112.             // set the owning side to null (unless already changed)
  113.             if ($site->getCustomer() === $this) {
  114.                 $site->setCustomer(null);
  115.             }
  116.         }
  117.         return $this;
  118.     }
  119.     public function getId(): ?int
  120.     {
  121.         return $this->id;
  122.     }
  123.     public function getOldId(): ?string
  124.     {
  125.         return $this->oldId;
  126.     }
  127.     public function setOldId(?string $oldId): self
  128.     {
  129.         $this->oldId $oldId;
  130.         return $this;
  131.     }
  132.     public function getCode(): ?string
  133.     {
  134.         return $this->code;
  135.     }
  136.     public function setCode(?string $code): self
  137.     {
  138.         $this->code $code;
  139.         return $this;
  140.     }
  141.     public function getReference(): ?string
  142.     {
  143.         return $this->reference;
  144.     }
  145.     public function setReference(?string $reference): self
  146.     {
  147.         $this->reference $reference;
  148.         return $this;
  149.     }
  150.     public function getName(): ?string
  151.     {
  152.         return $this->name;
  153.     }
  154.     public function setName(?string $name): self
  155.     {
  156.         $this->name $name;
  157.         return $this;
  158.     }
  159.     /**
  160.      * @return Collection<int, User>
  161.      */
  162.     public function getUsers(): Collection
  163.     {
  164.         return $this->users;
  165.     }
  166.     public function addUser(User $user): self
  167.     {
  168.         if (!$this->users->contains($user)) {
  169.             $this->users->add($user);
  170.             $user->setCustomer($this);
  171.         }
  172.         return $this;
  173.     }
  174.     public function removeUser(User $user): self
  175.     {
  176.         if ($this->users->removeElement($user)) {
  177.             // set the owning side to null (unless already changed)
  178.             if ($user->getCustomer() === $this) {
  179.                 $user->setCustomer(null);
  180.             }
  181.         }
  182.         return $this;
  183.     }
  184.     /*
  185.     public function getSites(): array
  186.     {
  187.         return $this->sites;
  188.     }
  189.     public function setSites($sites): self
  190.     {
  191.         $this->sites = $sites;
  192.         return $this;
  193.     }*/
  194.     public function getYear(): ?int
  195.     {
  196.         return $this->year;
  197.     }
  198.     public function setYear(?int $year): self
  199.     {
  200.         $this->year $year;
  201.         return $this;
  202.     }
  203. }