src/Entity/Segmentation/Region.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Segmentation;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\Segmentation\RegionRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. /**
  10.  * @ORM\Entity(repositoryClass=RegionRepository::class)
  11.  */
  12. class Region
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="string", length=2)
  22.      * @Groups({
  23.      *     "Department:output",
  24.      * })
  25.      */
  26.     private $code;
  27.     /**
  28.      * @ORM\Column(type="string", length=255)
  29.      * @Groups({
  30.      *     "Department:output",
  31.      * })
  32.      */
  33.     private $name;
  34.     /**
  35.      * @ORM\OneToMany(targetEntity=Department::class, mappedBy="region")
  36.      */
  37.     private $departments;
  38.     public function __construct()
  39.     {
  40.         $this->departments = new ArrayCollection();
  41.     }
  42.     public function getId(): ?int
  43.     {
  44.         return $this->id;
  45.     }
  46.     public function getCode(): ?string
  47.     {
  48.         return $this->code;
  49.     }
  50.     public function setCode(string $code): self
  51.     {
  52.         $this->code $code;
  53.         return $this;
  54.     }
  55.     public function getName(): ?string
  56.     {
  57.         return $this->name;
  58.     }
  59.     public function setName(string $name): self
  60.     {
  61.         $this->name $name;
  62.         return $this;
  63.     }
  64.     /**
  65.      * @return Collection<int, Department>
  66.      */
  67.     public function getDepartments(): Collection
  68.     {
  69.         return $this->departments;
  70.     }
  71.     public function addDepartment(Department $department): self
  72.     {
  73.         if (!$this->departments->contains($department)) {
  74.             $this->departments[] = $department;
  75.             $department->setRegion($this);
  76.         }
  77.         return $this;
  78.     }
  79.     public function removeDepartment(Department $department): self
  80.     {
  81.         if ($this->departments->removeElement($department)) {
  82.             // set the owning side to null (unless already changed)
  83.             if ($department->getRegion() === $this) {
  84.                 $department->setRegion(null);
  85.             }
  86.         }
  87.         return $this;
  88.     }
  89. }