src/Entity/Department.php line 41

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\GetCollection;
  5. use ApiPlatform\Metadata\Get;
  6. use App\Controller\Api\Establishment\ApiEstablishmentGetByUserController;
  7. use App\Model\Wallet\WalletInterface;
  8. use App\Repository\DepartmentRepository;
  9. use App\State\User\UserEstablishmentDepartementsProvider;
  10. use App\Trait\ActivableTrait;
  11. use App\Trait\AuthorTrait;
  12. use App\Trait\CurrentStateTrait;
  13. use App\Trait\DateTrait;
  14. use App\Trait\DeletableTrait;
  15. use App\Trait\WalletTrait;
  16. use DateTimeImmutable;
  17. use Doctrine\Common\Collections\ArrayCollection;
  18. use Doctrine\Common\Collections\Collection;
  19. use Doctrine\DBAL\Types\Types;
  20. use Doctrine\ORM\Mapping as ORM;
  21. use Symfony\Component\Serializer\Annotation\Groups;
  22. #[ORM\Entity(repositoryClassDepartmentRepository::class)]
  23. #[ApiResource(
  24.     operations: [
  25.         new GetCollection(
  26.             normalizationContext: ['groups' => ['department:list']]
  27.         ),
  28.         new Get(),
  29.         new GetCollection(
  30.             uriTemplate'user/establishments/departments',
  31.             normalizationContext: ['groups' => ['department:list']],
  32.             providerUserEstablishmentDepartementsProvider::class
  33.         ),
  34.     ],
  35.     normalizationContext: ['groups' => ['department:list''department:view']]
  36. )]
  37. class Department implements WalletInterface
  38. {
  39.     use DateTrait {DateTrait::__construct as private dateConstruct;}
  40.     use ActivableTrait;
  41.     use CurrentStateTrait;
  42.     use DeletableTrait;
  43.     use WalletTrait;
  44.     use AuthorTrait;
  45.     #[ORM\Id]
  46.     #[ORM\GeneratedValue]
  47.     #[ORM\Column]
  48.     #[Groups(['department:list''article:list''order:list'])]
  49.     private ?int $id null;
  50.     #[ORM\Column(length255)]
  51.     #[Groups(['department:list''department:new''article:list''order:list'])]
  52.     private ?string $name null;
  53.     #[ORM\Column(typeTypes::TEXT)]
  54.     #[Groups(['department:view''department:new'])]
  55.     private ?string $content null;
  56.     #[ORM\Column(type"smallint"options: ["defaults" => 0])]
  57.     #[Groups(['department:list''department:view'])]
  58.     private ?int $level 0;
  59.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'departments')]
  60.     #[Groups(['department:list''department:new'])]
  61.     private ?self $parent null;
  62.     #[ORM\ManyToOne(inversedBy'departments')]
  63.     #[ORM\JoinColumn(nullablefalse)]
  64.     private ?Establishment $establishment null;
  65.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class)]
  66.     #[Groups(['department:view'])]
  67.     private Collection $departments;
  68.     #[ORM\OneToMany(mappedBy'department'targetEntityCollections::class)]
  69.     private Collection $collections;
  70.     #[ORM\OneToMany(mappedBy'department'targetEntityOrder::class, orphanRemovaltrue)]
  71.     private Collection $orders;
  72.     #[ORM\OneToMany(mappedBy'department'targetEntityClient::class)]
  73.     private Collection $clients;
  74.     #[ORM\OneToMany(mappedBy'department'targetEntityEmployee::class)]
  75.     private Collection $employees;
  76.     #[ORM\OneToMany(mappedBy'department'targetEntityArticleDepartment::class, orphanRemovaltrue)]
  77.     private Collection $articles;
  78.     #[ORM\Column]
  79.     #[Groups(['department:new'])]
  80.     private ?bool $isBookable null;
  81.     #[ORM\Column]
  82.     #[Groups(['department:new'])]
  83.     private ?bool $hasWallets null;
  84.     #[ORM\OneToMany(mappedBy'department'targetEntityLot::class)]
  85.     private Collection $lots;
  86.     #[ORM\Column]
  87.     #[Groups(['department:new'])]
  88.     private ?bool $isOnMenu false;
  89.     #[ORM\Column(length255nullabletrue)]
  90.     #[Groups(['department:new'])]
  91.     private ?string $onMenu null;
  92.     #[ORM\ManyToMany(targetEntityPlanning::class, mappedBy'departments')]
  93.     private Collection $plannings;
  94.     public function __construct()
  95.     {
  96.         $this->currentState 'draft';
  97.         $this->dateConstruct();
  98.         $this->departments = new ArrayCollection();
  99.         $this->orders = new ArrayCollection();
  100.         $this->clients = new ArrayCollection();
  101.         $this->employees = new ArrayCollection();
  102.         $this->articles = new ArrayCollection();
  103.         $this->lots = new ArrayCollection();
  104.     }
  105.     public function getId(): ?int
  106.     {
  107.         return $this->id;
  108.     }
  109.     public function getName(): ?string
  110.     {
  111.         return $this->name;
  112.     }
  113.     public function setName(string $name): self
  114.     {
  115.         $this->name $name;
  116.         return $this;
  117.     }
  118.     public function getContent(): ?string
  119.     {
  120.         return $this->content;
  121.     }
  122.     public function setContent(string $content): self
  123.     {
  124.         $this->content $content;
  125.         return $this;
  126.     }
  127.     public function getLevel(): ?int
  128.     {
  129.         return $this->level;
  130.     }
  131.     public function setLevel(int $level): self
  132.     {
  133.         $this->level $level;
  134.         return $this;
  135.     }
  136.     public function getParent(): ?self
  137.     {
  138.         return $this->parent;
  139.     }
  140.     public function setParent(?self $parent): self
  141.     {
  142.         $this->parent $parent;
  143.         return $this;
  144.     }
  145.     public function getEstablishment(): ?Establishment
  146.     {
  147.         return $this->establishment;
  148.     }
  149.     public function setEstablishment(?Establishment $establishment): self
  150.     {
  151.         $this->establishment $establishment;
  152.         return $this;
  153.     }
  154.     /**
  155.      * @return Collection<int, self>
  156.      */
  157.     public function getDepartments(): Collection
  158.     {
  159.         return $this->departments;
  160.     }
  161.     public function addDepartment(self $department): self
  162.     {
  163.         if (!$this->departments->contains($department)) {
  164.             $this->departments->add($department);
  165.             $department->setParent($this);
  166.         }
  167.         return $this;
  168.     }
  169.     public function removeDepartment(self $department): self
  170.     {
  171.         if ($this->departments->removeElement($department)) {
  172.             // set the owning side to null (unless already changed)
  173.             if ($department->getParent() === $this) {
  174.                 $department->setParent(null);
  175.             }
  176.         }
  177.         return $this;
  178.     }
  179.     /**
  180.      * @return Collection<int, Order>
  181.      */
  182.     public function getOrders(): Collection
  183.     {
  184.         return $this->orders;
  185.     }
  186.     public function addOrder(Order $order): self
  187.     {
  188.         if (!$this->orders->contains($order)) {
  189.             $this->orders->add($order);
  190.             $order->setDepartment($this);
  191.         }
  192.         return $this;
  193.     }
  194.     public function removeOrder(Order $order): self
  195.     {
  196.         if ($this->orders->removeElement($order)) {
  197.             // set the owning side to null (unless already changed)
  198.             if ($order->getDepartment() === $this) {
  199.                 $order->setDepartment(null);
  200.             }
  201.         }
  202.         return $this;
  203.     }
  204.     /**
  205.      * @return Collection<int, Client>
  206.      */
  207.     public function getClients(): Collection
  208.     {
  209.         return $this->clients;
  210.     }
  211.     public function addClient(Client $client): self
  212.     {
  213.         if (!$this->clients->contains($client)) {
  214.             $this->clients->add($client);
  215.             $client->setDepartment($this);
  216.         }
  217.         return $this;
  218.     }
  219.     public function removeClient(Client $client): self
  220.     {
  221.         if ($this->clients->removeElement($client)) {
  222.             // set the owning side to null (unless already changed)
  223.             if ($client->getDepartment() === $this) {
  224.                 $client->setDepartment(null);
  225.             }
  226.         }
  227.         return $this;
  228.     }
  229.     /**
  230.      * @return Collection<int, Employee>
  231.      */
  232.     public function getEmployees(): Collection
  233.     {
  234.         return $this->employees;
  235.     }
  236.     public function addEmployee(Employee $employee): self
  237.     {
  238.         if (!$this->employees->contains($employee)) {
  239.             $this->employees->add($employee);
  240.             $employee->setDepartment($this);
  241.         }
  242.         return $this;
  243.     }
  244.     public function removeEmployee(Employee $employee): self
  245.     {
  246.         if ($this->employees->removeElement($employee)) {
  247.             // set the owning side to null (unless already changed)
  248.             if ($employee->getDepartment() === $this) {
  249.                 $employee->setDepartment(null);
  250.             }
  251.         }
  252.         return $this;
  253.     }
  254.     /**
  255.      * @return Collection<int, ArticleDepartment>
  256.      */
  257.     public function getArticles(): Collection
  258.     {
  259.         return $this->articles;
  260.     }
  261.     public function addArticle(ArticleDepartment $article): self
  262.     {
  263.         if (!$this->articles->contains($article)) {
  264.             $this->articles->add($article);
  265.             $article->setDepartment($this);
  266.         }
  267.         return $this;
  268.     }
  269.     public function removeArticle(ArticleDepartment $article): self
  270.     {
  271.         if ($this->articles->removeElement($article)) {
  272.             // set the owning side to null (unless already changed)
  273.             if ($article->getDepartment() === $this) {
  274.                 $article->setDepartment(null);
  275.             }
  276.         }
  277.         return $this;
  278.     }
  279.     public function __serialize(): array
  280.     {
  281.         return [$this->id$this->name];
  282.     }
  283.     public function __unserialize(array $data): void
  284.     {
  285.         if (count($data) === 4) [$this->id$this->name] = $data;
  286.     }
  287.     public function isIsBookable(): ?bool
  288.     {
  289.         return $this->isBookable;
  290.     }
  291.     public function setIsBookable(bool $isBookable): self
  292.     {
  293.         $this->isBookable $isBookable;
  294.         return $this;
  295.     }
  296.     public function isHasWallets(): ?bool
  297.     {
  298.         return $this->hasWallets;
  299.     }
  300.     public function setHasWallets(bool $hasWallets): self
  301.     {
  302.         $this->hasWallets $hasWallets;
  303.         return $this;
  304.     }
  305.     /**
  306.      * @return Collection<int, Lot>
  307.      */
  308.     public function getLots(): Collection
  309.     {
  310.         return $this->lots;
  311.     }
  312.     public function addLot(Lot $lot): self
  313.     {
  314.         if (!$this->lots->contains($lot)) {
  315.             $this->lots->add($lot);
  316.             $lot->setDepartment($this);
  317.         }
  318.         return $this;
  319.     }
  320.     public function removeLot(Lot $lot): self
  321.     {
  322.         if ($this->lots->removeElement($lot)) {
  323.             // set the owning side to null (unless already changed)
  324.             if ($lot->getDepartment() === $this) {
  325.                 $lot->setDepartment(null);
  326.             }
  327.         }
  328.         return $this;
  329.     }
  330.     public function isIsOnMenu(): ?bool
  331.     {
  332.         return $this->isOnMenu;
  333.     }
  334.     public function setIsOnMenu(bool $isOnMenu): self
  335.     {
  336.         $this->isOnMenu $isOnMenu;
  337.         return $this;
  338.     }
  339.     public function getOnMenu(): ?string
  340.     {
  341.         return $this->onMenu;
  342.     }
  343.     public function setOnMenu(?string $onMenu): self
  344.     {
  345.         $this->onMenu $onMenu;
  346.         return $this;
  347.     }
  348.     public function increaseLevel(?int $param)
  349.     {
  350.     }
  351.     /**
  352.      * @return Collection<int, Planning>
  353.      */
  354.     public function getPlannings(): Collection
  355.     {
  356.         return $this->plannings;
  357.     }
  358.     public function addPlanning(Planning $planning): static
  359.     {
  360.         if (!$this->plannings->contains($planning)) {
  361.             $this->plannings->add($planning);
  362.             $planning->addDepartment($this);
  363.         }
  364.         return $this;
  365.     }
  366.     public function removePlanning(Planning $planning): static
  367.     {
  368.         if ($this->plannings->removeElement($planning)) {
  369.             $planning->removeDepartment($this);
  370.         }
  371.         return $this;
  372.     }
  373.     public function __toString(): string
  374.     {
  375.         $departmentParent $this->getParent();
  376.         $departmentParent $departmentParent " [$departmentParent]" "";
  377.         return $this->name $departmentParent;
  378.     }
  379. }