src/Entity/Department.php line 16

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\DepartmentRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\UX\Turbo\Attribute\Broadcast;
  10. #[ORM\Entity(repositoryClassDepartmentRepository::class)]
  11. #[ApiResource]
  12. #[Broadcast]
  13. class Department
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     private ?int $id null;
  19.     #[ORM\Column(length255)]
  20.     private ?string $name null;
  21.     #[ORM\Column(typeTypes::TEXT)]
  22.     private ?string $description null;
  23.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'departments')]
  24.     private ?self $parent null;
  25.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class)]
  26.     private Collection $departments;
  27.     #[ORM\ManyToOne(inversedBy'departments')]
  28.     private ?Corporation $corporation null;
  29.     #[ORM\OneToMany(mappedBy'department'targetEntityPortalAdministrator::class)]
  30.     private Collection $portalAdministrators;
  31.     public function __construct()
  32.     {
  33.         $this->departments = new ArrayCollection();
  34.         $this->portalAdministrators = new ArrayCollection();
  35.     }
  36.     public function getId(): ?int
  37.     {
  38.         return $this->id;
  39.     }
  40.     public function __toString(): string
  41.     {
  42.        return $this->getName();
  43.     }
  44.     public function getName(): ?string
  45.     {
  46.         return $this->name;
  47.     }
  48.     public function setName(string $name): self
  49.     {
  50.         $this->name $name;
  51.         return $this;
  52.     }
  53.     public function getDescription(): ?string
  54.     {
  55.         return $this->description;
  56.     }
  57.     public function setDescription(string $description): self
  58.     {
  59.         $this->description $description;
  60.         return $this;
  61.     }
  62.     public function getParent(): ?self
  63.     {
  64.         return $this->parent;
  65.     }
  66.     public function setParent(?self $parent): self
  67.     {
  68.         $this->parent $parent;
  69.         return $this;
  70.     }
  71.     /**
  72.      * @return Collection<int, self>
  73.      */
  74.     public function getDepartments(): Collection
  75.     {
  76.         return $this->departments;
  77.     }
  78.     public function addDepartment(self $department): self
  79.     {
  80.         if (!$this->departments->contains($department)) {
  81.             $this->departments->add($department);
  82.             $department->setParent($this);
  83.         }
  84.         return $this;
  85.     }
  86.     public function removeDepartment(self $department): self
  87.     {
  88.         if ($this->departments->removeElement($department)) {
  89.             // set the owning side to null (unless already changed)
  90.             if ($department->getParent() === $this) {
  91.                 $department->setParent(null);
  92.             }
  93.         }
  94.         return $this;
  95.     }
  96.     public function getCorporation(): ?Corporation
  97.     {
  98.         return $this->corporation;
  99.     }
  100.     public function setCorporation(?Corporation $corporation): self
  101.     {
  102.         $this->corporation $corporation;
  103.         return $this;
  104.     }
  105.     /**
  106.      * @return Collection<int, PortalAdministrator>
  107.      */
  108.     public function getPortalAdministrators(): Collection
  109.     {
  110.         return $this->portalAdministrators;
  111.     }
  112.     public function addPortalAdministrator(PortalAdministrator $portalAdministrator): self
  113.     {
  114.         if (!$this->portalAdministrators->contains($portalAdministrator)) {
  115.             $this->portalAdministrators->add($portalAdministrator);
  116.             $portalAdministrator->setDepartment($this);
  117.         }
  118.         return $this;
  119.     }
  120.     public function removePortalAdministrator(PortalAdministrator $portalAdministrator): self
  121.     {
  122.         if ($this->portalAdministrators->removeElement($portalAdministrator)) {
  123.             // set the owning side to null (unless already changed)
  124.             if ($portalAdministrator->getDepartment() === $this) {
  125.                 $portalAdministrator->setDepartment(null);
  126.             }
  127.         }
  128.         return $this;
  129.     }
  130. }