src/Entity/Country.php line 26

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Repository\CountryRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping\Column;
  9. use Doctrine\ORM\Mapping\Entity;
  10. use Doctrine\ORM\Mapping\GeneratedValue;
  11. use Doctrine\ORM\Mapping\Id;
  12. use Doctrine\ORM\Mapping\ManyToOne;
  13. use Doctrine\ORM\Mapping\OneToMany;
  14. use Doctrine\ORM\Mapping\UniqueConstraint;
  15. use Symfony\Component\Serializer\Annotation\Ignore;
  16. use function Symfony\Component\String\u;
  17. #[ApiResource(attributes: ['route_prefix' => 'v1'])]
  18. #[Entity(CountryRepository::class)]
  19. #[UniqueConstraint('name', ['name'])]
  20. #[UniqueConstraint('iso_code', ['iso_code'])]
  21. class Country
  22. {
  23.     public const DEFAULT_ID 1000;
  24.     #[Id]
  25.     #[GeneratedValue]
  26.     #[Column(type'integer'options: ['unsigned' => true])]
  27.     private int $id;
  28.     #[Ignore]
  29.     #[ManyToOne(targetEntityRegion::class, inversedBy"countries")]
  30.     private ?Region $region null;
  31.     #[Column(type'string')]
  32.     private string $name;
  33.     #[Column(type'string'length2)]
  34.     private string $isoCode;
  35.     #[Column(type'boolean'options: ['default' => true])]
  36.     private bool $smsEnabled;
  37.     #[OneToMany('country'CountryPhoneCode::class)]
  38.     private Collection $phoneCodes;
  39.     #[Column(type'float'precision10scale2nullablefalseoptions: ['unsigned' => true])]
  40.     private float $cpmRate 1;
  41.     public function __construct()
  42.     {
  43.         $this->phoneCodes = new ArrayCollection();
  44.     }
  45.     public function __toString(): string
  46.     {
  47.         return u($this->getIsoCode())->upper()->toString();
  48.     }
  49.     public function getId(): ?int
  50.     {
  51.         return $this->id;
  52.     }
  53.     public function getRegion(): ?Region
  54.     {
  55.         return $this->region;
  56.     }
  57.     public function setRegion(?Region $region): void
  58.     {
  59.         $this->region $region;
  60.     }
  61.     public function setName(?string $name): self
  62.     {
  63.         $this->name $name;
  64.         return $this;
  65.     }
  66.     public function getName(): ?string
  67.     {
  68.         return $this->name;
  69.     }
  70.     public function setIsoCode(?string $isoCode): self
  71.     {
  72.         $this->isoCode $isoCode;
  73.         return $this;
  74.     }
  75.     public function getIsoCode(): ?string
  76.     {
  77.         return $this->isoCode;
  78.     }
  79.     public function isSmsEnabled(): bool
  80.     {
  81.         return $this->smsEnabled;
  82.     }
  83.     public function setSmsEnabled(bool $smsEnabled): static
  84.     {
  85.         $this->smsEnabled $smsEnabled;
  86.         return $this;
  87.     }
  88.     public function getPhoneCodes(): Collection
  89.     {
  90.         return $this->phoneCodes;
  91.     }
  92.     public function getCpmRate(): float
  93.     {
  94.         return $this->cpmRate;
  95.     }
  96.     public function setCpmRate(float $cpmRate): void
  97.     {
  98.         $this->cpmRate $cpmRate;
  99.     }
  100. }