src/Flexy/ShopBundle/Entity/Shipping/Country.php line 21

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Shipping;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Entity\Payment\PaymentMethod;
  5. use App\Flexy\ShopBundle\Entity\Product\Product;
  6. use App\Repository\Flexy\ShopBundle\Entity\Shipping\CountryRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. #[ORM\Entity(repositoryClassCountryRepository::class)]
  13. #[ApiResource(
  14.     normalizationContext: ['groups' => ['read']],
  15.     denormalizationContext: ['groups' => ['write']],
  16. )]
  17. class Country
  18. {
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column]
  22.     #[Groups(['read''write'])]
  23.     private ?int $id null;
  24.     #[Groups(['read''write'])]
  25.     #[ORM\Column(length255nullabletrue)]
  26.     private ?string $name null;
  27.     #[Groups(['read''write'])]
  28.     #[ORM\Column(length255nullabletrue)]
  29.     private ?string $code null;
  30.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  31.     private ?string $description null;
  32.     #[ORM\Column(nullabletrue)]
  33.     private ?bool $isEnabled null;
  34.     #[ORM\ManyToMany(targetEntityShippingMethod::class, mappedBy'countries')]
  35.     private Collection $shippingMethods;
  36.     #[ORM\ManyToMany(targetEntityPaymentMethod::class, mappedBy'includedCountries')]
  37.     private Collection $paymentMethods;
  38.     #[ORM\ManyToMany(targetEntityProduct::class, mappedBy'shipToCountries')]
  39.     private Collection $shippingProducts;
  40.     
  41.     public function __construct()
  42.     {
  43.         $this->shippingMethods = new ArrayCollection();
  44.         $this->paymentMethods = new ArrayCollection();
  45.         $this->shippingProducts = new ArrayCollection();
  46.     }
  47.     public function __toString()
  48.     {
  49.         return (string)$this->name;
  50.     }
  51.     public function getId(): ?int
  52.     {
  53.         return $this->id;
  54.     }
  55.     public function getName(): ?string
  56.     {
  57.         return $this->name;
  58.     }
  59.     public function setName(?string $name): static
  60.     {
  61.         $this->name $name;
  62.         return $this;
  63.     }
  64.     public function getCode(): ?string
  65.     {
  66.         return $this->code;
  67.     }
  68.     public function setCode(?string $code): static
  69.     {
  70.         $this->code $code;
  71.         return $this;
  72.     }
  73.     public function getDescription(): ?string
  74.     {
  75.         return $this->description;
  76.     }
  77.     public function setDescription(?string $description): static
  78.     {
  79.         $this->description $description;
  80.         return $this;
  81.     }
  82.     public function isIsEnabled(): ?bool
  83.     {
  84.         return $this->isEnabled;
  85.     }
  86.     public function setIsEnabled(?bool $isEnabled): static
  87.     {
  88.         $this->isEnabled $isEnabled;
  89.         return $this;
  90.     }
  91.     /**
  92.      * @return Collection<int, ShippingMethod>
  93.      */
  94.     public function getShippingMethods(): Collection
  95.     {
  96.         return $this->shippingMethods;
  97.     }
  98.     public function addShippingMethod(ShippingMethod $shippingMethod): static
  99.     {
  100.         if (!$this->shippingMethods->contains($shippingMethod)) {
  101.             $this->shippingMethods->add($shippingMethod);
  102.         }
  103.         return $this;
  104.     }
  105.     public function removeShippingMethod(ShippingMethod $shippingMethod): static
  106.     {
  107.         $this->shippingMethods->removeElement($shippingMethod);
  108.         return $this;
  109.     }
  110.     /**
  111.      * @return Collection<int, PaymentMethod>
  112.      */
  113.     public function getPaymentMethods(): Collection
  114.     {
  115.         return $this->paymentMethods;
  116.     }
  117.     public function addPaymentMethod(PaymentMethod $paymentMethod): static
  118.     {
  119.         if (!$this->paymentMethods->contains($paymentMethod)) {
  120.             $this->paymentMethods->add($paymentMethod);
  121.             $paymentMethod->addIncludedCountry($this);
  122.         }
  123.         return $this;
  124.     }
  125.     public function removePaymentMethod(PaymentMethod $paymentMethod): static
  126.     {
  127.         if ($this->paymentMethods->removeElement($paymentMethod)) {
  128.             $paymentMethod->removeIncludedCountry($this);
  129.         }
  130.         return $this;
  131.     }
  132.     /**
  133.      * @return Collection<int, Product>
  134.      */
  135.     public function getShippingProducts(): Collection
  136.     {
  137.         return $this->shippingProducts;
  138.     }
  139.     public function addShippingProduct(Product $shippingProduct): static
  140.     {
  141.         if (!$this->shippingProducts->contains($shippingProduct)) {
  142.             $this->shippingProducts->add($shippingProduct);
  143.             $shippingProduct->addShipToCountry($this);
  144.         }
  145.         return $this;
  146.     }
  147.     public function removeShippingProduct(Product $shippingProduct): static
  148.     {
  149.         if ($this->shippingProducts->removeElement($shippingProduct)) {
  150.             $shippingProduct->removeShipToCountry($this);
  151.         }
  152.         return $this;
  153.     }
  154. }