src/Entity/CountryState.php line 36

Open in your IDE?
  1. <?php
  2. /**
  3.  * @author Leo BANNHOLTZER (contact@scaledev.fr)
  4.  * @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
  5.  * @license commercial
  6.  */
  7. declare(strict_types=1);
  8. namespace App\Entity;
  9. use Symfony\Component\Uid\Uuid;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. use App\DoctrineExtensions\IsActiveEntity;
  13. use App\Repository\CountryStateRepository;
  14. use Doctrine\Common\Collections\Collection;
  15. use Doctrine\Common\Collections\ArrayCollection;
  16. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  17. use App\DoctrineExtensions\Timestampable\Traits\UserTimestampableEntity;
  18. use App\DoctrineExtensions\SoftDeleteable\Traits\UserSoftDeleteableEntity;
  19. /**
  20.  * @ORM\Entity(repositoryClass=CountryStateRepository::class)
  21.  * @ORM\Table(name="country_state", indexes={
  22.  *  @ORM\Index(name="name", columns={"name"}),
  23.  *  @ORM\Index(name="iso_code", columns={"iso_code"}),
  24.  *  @ORM\Index(name="is_active", columns={"is_active"}),
  25.  *  @ORM\Index(name="deleted_at", columns={"deleted_at"}),
  26.  *  @ORM\Index(name="created_at", columns={"created_at"}),
  27.  *  @ORM\Index(name="updated_at", columns={"updated_at"})
  28.  * })
  29.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=false)
  30.  */
  31. class CountryState implements \JsonSerializable
  32. {
  33.     use UserTimestampableEntity;
  34.     use UserSoftDeleteableEntity;
  35.     use IsActiveEntity;
  36.     /**
  37.      * @ORM\Id
  38.      * @ORM\Column(type="uuid")
  39.      * @ORM\GeneratedValue(strategy="CUSTOM")
  40.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  41.      */
  42.     private ?Uuid $id null;
  43.     /**
  44.      * @ORM\Column(type="string", length=64)
  45.      */
  46.     private string $name;
  47.     /**
  48.      * @ORM\Column(type="string", length=7, nullable=true)
  49.      */
  50.     private ?string $iso_code;
  51.     /**
  52.      * @ORM\ManyToOne(targetEntity=Country::class, inversedBy="countryStates")
  53.      * @ORM\JoinColumn(nullable=false)
  54.      */
  55.     private Country $country;
  56.     /**
  57.      * @ORM\OneToMany(targetEntity=Context::class, mappedBy="country_state", fetch="EXTRA_LAZY")
  58.      */
  59.     private Collection $contexts;
  60.     public function __construct()
  61.     {
  62.         $this->contexts = new ArrayCollection();
  63.     }
  64.     /**
  65.      * @return Uuid|null
  66.      */
  67.     public function getId(): ?Uuid
  68.     {
  69.         return $this->id;
  70.     }
  71.     /**
  72.      * @return string
  73.      */
  74.     public function getName(): string
  75.     {
  76.         return $this->name;
  77.     }
  78.     /**
  79.      * @param string $name
  80.      * @return $this
  81.      */
  82.     public function setName(string $name): self
  83.     {
  84.         $this->name $name;
  85.         return $this;
  86.     }
  87.     /**
  88.      * @return string|null
  89.      */
  90.     public function getIsoCode(): ?string
  91.     {
  92.         return $this->iso_code;
  93.     }
  94.     /**
  95.      * @param string|null $iso_code
  96.      * @return $this
  97.      */
  98.     public function setIsoCode(?string $iso_code): self
  99.     {
  100.         $this->iso_code $iso_code;
  101.         return $this;
  102.     }
  103.     /**
  104.      * @return Country
  105.      */
  106.     public function getCountry(): Country
  107.     {
  108.         return $this->country;
  109.     }
  110.     /**
  111.      * @param Country $country
  112.      * @return $this
  113.      */
  114.     public function setCountry(Country $country): self
  115.     {
  116.         $this->country $country;
  117.         return $this;
  118.     }
  119.     /**
  120.      * @return Collection|Context[]
  121.      */
  122.     public function getContexts(): Collection
  123.     {
  124.         return $this->contexts;
  125.     }
  126.     /**
  127.      * @param Context $context
  128.      * @return $this
  129.      */
  130.     public function addContext(Context $context): self
  131.     {
  132.         if (!$this->contexts->contains($context)) {
  133.             $this->contexts[] = $context;
  134.             $context->setCountryState($this);
  135.         }
  136.         return $this;
  137.     }
  138.     /**
  139.      * @return mixed
  140.      */
  141.     #[\ReturnTypeWillChange]
  142.     public function jsonSerialize()
  143.     {
  144.         return [
  145.             'id' => $this->id,
  146.             'name' => $this->name,
  147.             'iso_code' => $this->iso_code,
  148.             'country' => $this->country
  149.         ];
  150.     }
  151. }