src/Entity/District.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\DistrictRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=DistrictRepository::class)
  9.  */
  10. class District
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $districtName;
  22.     /**
  23.      * @ORM\OneToMany(targetEntity=Department::class, mappedBy="district")
  24.      */
  25.     private $departments;
  26.     public function __construct()
  27.     {
  28.         $this->departments = new ArrayCollection();
  29.     }
  30.     
  31.    
  32.     public function getId(): ?int
  33.     {
  34.         return $this->id;
  35.     }
  36.     public function getDistrictName(): ?string
  37.     {
  38.         return $this->districtName;
  39.     }
  40.     public function setDistrictName(string $districtName): self
  41.     {
  42.         $this->districtName $districtName;
  43.         return $this;
  44.     }
  45.     /**
  46.      * @return Collection|Department[]
  47.      */
  48.     public function getDepartments(): Collection
  49.     {
  50.         return $this->departments;
  51.     }
  52.     public function addDepartment(Department $department): self
  53.     {
  54.         if (!$this->departments->contains($department)) {
  55.             $this->departments[] = $department;
  56.             $department->setDistrict($this);
  57.         }
  58.         return $this;
  59.     }
  60.     public function removeDepartment(Department $department): self
  61.     {
  62.         if ($this->departments->contains($department)) {
  63.             $this->departments->removeElement($department);
  64.             // set the owning side to null (unless already changed)
  65.             if ($department->getDistrict() === $this) {
  66.                 $department->setDistrict(null);
  67.             }
  68.         }
  69.         return $this;
  70.     }
  71.     public function __toString(){
  72.         return $this->districtName;
  73.     }
  74. }