src/Entity/Geographical/Country.php line 37

  1. <?php
  2. /*
  3.  * This file is part of the Pellipop project.
  4.  *
  5.  * (c) Mobizel
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace App\Entity\Geographical;
  12. use App\Entity\IdentifiableTrait;
  13. use App\Repository\Geographical\CountryRepository;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Sylius\Component\Resource\Annotation\SyliusCrudRoutes;
  16. use Sylius\Component\Resource\Model\ResourceInterface;
  17. use Symfony\Component\Intl\Countries as IntlCountries;
  18. use Symfony\Component\Validator\Constraints as Assert;
  19. #[ORM\Entity(repositoryClassCountryRepository::class)]
  20. #[ORM\Table(name'app_country')]
  21. #[SyliusCrudRoutes(alias'app.country'path'/admin/countrys'section'backend'redirect'update'templates'backend/crud'grid'app_backend_country'except: ['show'], vars: [
  22.     'all' => [
  23.         'subheader' => 'app.ui.manage_your_countrys',
  24.         'templates' => [
  25.             'form' => 'backend/country/_form.html.twig',
  26.         ],
  27.     ],
  28.     'index' => [
  29.         'icon' => 'world',
  30.     ],
  31. ])]
  32. class Country implements ResourceInterface
  33. {
  34.     use IdentifiableTrait;
  35.     #[ORM\Column(type'string'length2)]
  36.     #[Assert\NotBlank]
  37.     private ?string $code null;
  38.     #[ORM\Column(type'boolean')]
  39.     private bool $enabled true;
  40.     #[ORM\Column(type'integer')]
  41.     #[Assert\NotBlankAssert\PositiveOrZero]
  42.     private int $shippingFees 0;
  43.     /**
  44.      * Get the value of code
  45.      *
  46.      * @return ?string
  47.      */
  48.     public function getCode(): ?string
  49.     {
  50.         return $this->code;
  51.     }
  52.     /**
  53.      * Set the value of code
  54.      *
  55.      * @return self
  56.      */
  57.     public function setCode($code): self
  58.     {
  59.         $this->code $code;
  60.         return $this;
  61.     }
  62.     /**
  63.      * Get the value of enabled
  64.      *
  65.      * @return bool
  66.      */
  67.     public function getEnabled(): bool
  68.     {
  69.         return $this->enabled;
  70.     }
  71.     /**
  72.      * Set the value of enabled
  73.      *
  74.      * @return self
  75.      */
  76.     public function setEnabled($enabled): self
  77.     {
  78.         $this->enabled $enabled;
  79.         return $this;
  80.     }
  81.     /**
  82.      * Get the value of shippingFees
  83.      *
  84.      * @return int
  85.      */
  86.     public function getShippingFees(): int
  87.     {
  88.         return $this->shippingFees;
  89.     }
  90.     /**
  91.      * Set the value of shippingFees
  92.      *
  93.      * @return self
  94.      */
  95.     public function setShippingFees($shippingFees): self
  96.     {
  97.         $this->shippingFees $shippingFees;
  98.         return $this;
  99.     }
  100.     /**
  101.      * Get name
  102.      *
  103.      * @return ?string
  104.      */
  105.     public function getName(?string $locale null): ?string
  106.     {
  107.         return IntlCountries::getName($this->code$locale);
  108.     }
  109.     /**
  110.      * Get name
  111.      *
  112.      * @return string
  113.      */
  114.     public function __toString(): string
  115.     {
  116.         return (string) ($this->getName() ?? $this->getCode());
  117.     }
  118. }