src/Entity/Department.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\DepartmentRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassDepartmentRepository::class)]
  8. class Department
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     private ?int $id null;
  14.     #[ORM\Column(length255)]
  15.     private ?string $name null;
  16.     #[ORM\Column(length255)]
  17.     private ?string $nameEn null;
  18.     #[ORM\ManyToOne(inversedBy'departments')]
  19.     #[ORM\JoinColumn(nullablefalse)]
  20.     private ?Region $region null;
  21.     #[ORM\OneToMany(mappedBy'department'targetEntitySchool::class)]
  22.     private Collection $schools;
  23.     #[ORM\OneToMany(mappedBy'departmentInspect'targetEntityUser::class)]
  24.     private Collection $users;
  25.     public function __construct()
  26.     {
  27.         $this->schools = new ArrayCollection();
  28.         $this->users = new ArrayCollection();
  29.     }
  30.     public function getId(): ?int
  31.     {
  32.         return $this->id;
  33.     }
  34.     public function getName(): ?string
  35.     {
  36.         return $this->name;
  37.     }
  38.     public function setName(string $name): static
  39.     {
  40.         $this->name $name;
  41.         return $this;
  42.     }
  43.     public function getNameEn(): ?string
  44.     {
  45.         return $this->nameEn;
  46.     }
  47.     public function setNameEn(string $nameEn): static
  48.     {
  49.         $this->nameEn $nameEn;
  50.         return $this;
  51.     }
  52.     public function getRegion(): ?Region
  53.     {
  54.         return $this->region;
  55.     }
  56.     public function setRegion(?Region $region): static
  57.     {
  58.         $this->region $region;
  59.         return $this;
  60.     }
  61.     /**
  62.      * @return Collection<int, School>
  63.      */
  64.     public function getSchools(): Collection
  65.     {
  66.         return $this->schools;
  67.     }
  68.     public function addSchool(School $school): static
  69.     {
  70.         if (!$this->schools->contains($school)) {
  71.             $this->schools->add($school);
  72.             $school->setDepartment($this);
  73.         }
  74.         return $this;
  75.     }
  76.     public function removeSchool(School $school): static
  77.     {
  78.         if ($this->schools->removeElement($school)) {
  79.             // set the owning side to null (unless already changed)
  80.             if ($school->getDepartment() === $this) {
  81.                 $school->setDepartment(null);
  82.             }
  83.         }
  84.         return $this;
  85.     }
  86.     /**
  87.      * @return Collection<int, User>
  88.      */
  89.     public function getUsers(): Collection
  90.     {
  91.         return $this->users;
  92.     }
  93.     public function addUser(User $user): static
  94.     {
  95.         if (!$this->users->contains($user)) {
  96.             $this->users->add($user);
  97.             $user->setDepartmentInspect($this);
  98.         }
  99.         return $this;
  100.     }
  101.     public function removeUser(User $user): static
  102.     {
  103.         if ($this->users->removeElement($user)) {
  104.             // set the owning side to null (unless already changed)
  105.             if ($user->getDepartmentInspect() === $this) {
  106.                 $user->setDepartmentInspect(null);
  107.             }
  108.         }
  109.         return $this;
  110.     }
  111. }