src/Entity/Country.php line 19

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. use App\Repository\CountryRepository;
  9. /**
  10.  * Country
  11.  *
  12.  * @ORM\Table(name="country", indexes={@ORM\Index(name="regionID", columns={"region_id"})})
  13.  * @ORM\Entity(repositoryClass=CountryRepository::class)
  14.  */
  15. class Country
  16. {
  17.     /**
  18.      * @var int
  19.      *
  20.      * @ORM\Column(name="id", type="smallint", nullable=false)
  21.      * @ORM\Id
  22.      * @ORM\GeneratedValue(strategy="IDENTITY")
  23.      * @Groups({CspCountry::SERIALIZATION_GROUP_COUNTRIES_PER_CSP})
  24.      */
  25.     private $id;
  26.     /**
  27.      * @var string
  28.      *
  29.      * @ORM\Column(name="name", type="string", length=60, nullable=false)
  30.      * @Groups({
  31.      *     CspCountry::SERIALIZATION_GROUP_COUNTRIES_PER_CSP, 
  32.      *     CustomerExcludeCsp::SERIALIZATION_GROUP_EXCLUDED_CSP_COUNTRY,
  33.      *     CspCountry::SERIALIZATION_GROUP_GET_ITEM
  34.      * })
  35.      */
  36.     private $name;
  37.     /**
  38.      * @var \Region
  39.      *
  40.      * @ORM\ManyToOne(targetEntity="Region")
  41.      * @ORM\JoinColumns({
  42.      *   @ORM\JoinColumn(name="region_id", referencedColumnName="id")
  43.      * })
  44.      */
  45.     private $region;
  46.     /**
  47.      * @var \Doctrine\Common\Collections\Collection
  48.      *
  49.      * @ORM\ManyToMany(targetEntity="Csp", mappedBy="country")
  50.      */
  51.     private $csp;
  52.     /**
  53.      * Constructor
  54.      */
  55.     public function __construct()
  56.     {
  57.         $this->csp = new \Doctrine\Common\Collections\ArrayCollection();
  58.     }
  59.     public function getId(): ?int
  60.     {
  61.         return $this->id;
  62.     }
  63.     public function getName(): ?string
  64.     {
  65.         return $this->name;
  66.     }
  67.     public function setName(string $name): self
  68.     {
  69.         $this->name $name;
  70.         return $this;
  71.     }
  72.     public function getRegion(): ?Region
  73.     {
  74.         return $this->region;
  75.     }
  76.     public function setRegion(?Region $region): self
  77.     {
  78.         $this->region $region;
  79.         return $this;
  80.     }
  81.     /**
  82.      * @return Collection<int, Csp>
  83.      */
  84.     public function getCsp(): Collection
  85.     {
  86.         return $this->csp;
  87.     }
  88.     public function addCsp(Csp $csp): self
  89.     {
  90.         if (!$this->csp->contains($csp)) {
  91.             $this->csp[] = $csp;
  92.             $csp->addCountry($this);
  93.         }
  94.         return $this;
  95.     }
  96.     public function removeCsp(Csp $csp): self
  97.     {
  98.         if ($this->csp->removeElement($csp)) {
  99.             $csp->removeCountry($this);
  100.         }
  101.         return $this;
  102.     }
  103. }