src/Entity/CartRegion.php line 47

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  4. use ApiPlatform\Metadata\ApiFilter;
  5. use ApiPlatform\Metadata\ApiProperty;
  6. use ApiPlatform\Metadata\ApiResource;
  7. use ApiPlatform\Metadata\Delete;
  8. use ApiPlatform\Metadata\Get;
  9. use ApiPlatform\Metadata\GetCollection;
  10. use ApiPlatform\Metadata\Post;
  11. use ApiPlatform\Metadata\Put;
  12. use App\Entity\Trait\IdTrait;
  13. use App\Entity\Trait\StatTrait;
  14. use App\Entity\Trait\TimestampableTrait;
  15. use App\Entity\Trait\UuidTrait;
  16. use App\Repository\CartRegionRepository;
  17. use Doctrine\Common\Collections\ArrayCollection;
  18. use Doctrine\Common\Collections\Collection;
  19. use Doctrine\DBAL\Types\Types;
  20. use Doctrine\ORM\Mapping as ORM;
  21. use Symfony\Component\Serializer\Annotation\Groups;
  22. #[ApiResource(
  23.     description'Cart regions',
  24.     operations: [
  25.         new GetCollection(),
  26.         new Post(
  27.             denormalizationContext: ['groups' => ['write''post']],
  28.         ),
  29.         new Get(),
  30.         new Put(),
  31.         new Delete(),
  32.     ],
  33.     normalizationContext: ['groups' => [
  34.         'read',
  35.         'read:' self::class,
  36.     ]],
  37.     denormalizationContext: ['groups' => ['write']],
  38.     order: ['createdAt' => 'desc'],
  39.     security'is_granted("' self::class . '")',
  40.     extraProperties: ['standard_put' => false],
  41. )]
  42. #[ApiFilter(OrderFilter::class, properties: ['createdAt''workingTitle'])]
  43. #[ORM\Entity(repositoryClassCartRegionRepository::class)]
  44. class CartRegion
  45. {
  46.     use IdTrait;
  47.     use UuidTrait;
  48.     use TimestampableTrait;
  49.     use StatTrait;
  50.     #[ApiProperty(description'Working title')]
  51.     #[Groups(['read''write'])]
  52.     #[ORM\Column(typeTypes::STRINGlength511)]
  53.     private ?string $workingTitle null;
  54.     #[ApiProperty(description'Vat')]
  55.     #[Groups(['read:' self::class, 'write'])]
  56.     #[ORM\Column(nullabletrue)]
  57.     private ?int $vat 0;
  58.     #[ORM\OneToMany(mappedBy'region'targetEntityCartCountry::class)]
  59.     private Collection $countries;
  60.     public function __construct()
  61.     {
  62.         $this->setUuid();
  63.         $this->createdAt = new \DateTimeImmutable();
  64.         $this->updatedAt = new \DateTimeImmutable();
  65.         $this->countries = new ArrayCollection();
  66.     }
  67.     public function getVat(): ?int
  68.     {
  69.         return $this->vat;
  70.     }
  71.     public function setVat(?int $vat): static
  72.     {
  73.         $this->vat $vat;
  74.         return $this;
  75.     }
  76.     /**
  77.      * @return Collection<int, CartCountry>
  78.      */
  79.     public function getCountries(): Collection
  80.     {
  81.         return $this->countries;
  82.     }
  83.     public function addCountry(CartCountry $country): static
  84.     {
  85.         if (!$this->countries->contains($country)) {
  86.             $this->countries->add($country);
  87.             $country->setRegion($this);
  88.         }
  89.         return $this;
  90.     }
  91.     public function removeCountry(CartCountry $country): static
  92.     {
  93.         if ($this->countries->removeElement($country)) {
  94.             // set the owning side to null (unless already changed)
  95.             if ($country->getRegion() === $this) {
  96.                 $country->setRegion(null);
  97.             }
  98.         }
  99.         return $this;
  100.     }
  101.     public function getWorkingTitle(): ?string
  102.     {
  103.         return $this->workingTitle;
  104.     }
  105.     public function setWorkingTitle(?string $workingTitle): self
  106.     {
  107.         $this->workingTitle $workingTitle;
  108.         return $this;
  109.     }
  110. }