src/Entity/Coupons.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\CouponsRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use ApiPlatform\Metadata\ApiFilter;
  11. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  12. #[ORM\Entity(repositoryClassCouponsRepository::class)]
  13. #[ApiResource(
  14.     normalizationContext: ['groups' => ['coupon:read']],
  15.     denormalizationContext: ['groups' => ['coupon:write']],
  16.     order: ['id' => 'DESC'],
  17. )]
  18. #[ApiFilter(SearchFilter::class, properties: ['code' => 'exact'])]
  19. class Coupons
  20. {
  21.     #[Groups(['coupon:read''coupon:write''pre_order:read','cat:read'])]
  22.     #[ORM\Id]
  23.     #[ORM\GeneratedValue]
  24.     #[ORM\Column]
  25.     private ?int $id null;
  26.     #[Groups(['coupon:read''coupon:write''pre_order:read','cat:read'])]
  27.     #[ORM\Column(length255)]
  28.     private ?string $name null;
  29.     #[Groups(['coupon:read''coupon:write''pre_order:read','cat:read'])]
  30.     #[ORM\Column(length255)]
  31.     private ?string $code null;
  32.     #[Groups(['coupon:read''coupon:write''pre_order:read','cat:read'])]
  33.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  34.     private ?string $description null;
  35.     #[Groups(['coupon:read''coupon:write''pre_order:read','cat:read'])]
  36.     #[ORM\Column(nullabletrue)]
  37.     private ?float $sum null;
  38.     #[Groups(['coupon:read''coupon:write''pre_order:read','cat:read'])]
  39.     #[ORM\Column(nullabletrue)]
  40.     private ?float $percent null;
  41.     #[Groups(['coupon:read''coupon:write''pre_order:read'])]
  42.     #[ORM\ManyToMany(targetEntityCategory::class, inversedBy'coupons')]
  43.     private Collection $category;
  44.     #[Groups(['coupon:read''coupon:write''pre_order:read','cat:read'])]
  45.     #[ORM\ManyToMany(targetEntityUser::class, inversedBy'coupons')]
  46.     private Collection $users;
  47.     #[Groups(['coupon:read''coupon:write''cat:read'])]
  48.     #[ORM\OneToMany(mappedBy'coupons'targetEntityPreOrder::class)]
  49.     private Collection $pre_orders;
  50.     public function __construct()
  51.     {
  52.         $this->category = new ArrayCollection();
  53.         $this->users = new ArrayCollection();
  54.         $this->pre_orders = new ArrayCollection();
  55.     }
  56.     public function getId(): ?int
  57.     {
  58.         return $this->id;
  59.     }
  60.     public function getName(): ?string
  61.     {
  62.         return $this->name;
  63.     }
  64.     public function setName(string $name): self
  65.     {
  66.         $this->name $name;
  67.         return $this;
  68.     }
  69.     public function getCode(): ?string
  70.     {
  71.         return $this->code;
  72.     }
  73.     public function setCode(string $code): self
  74.     {
  75.         $this->code $code;
  76.         return $this;
  77.     }
  78.     public function getDescription(): ?string
  79.     {
  80.         return $this->description;
  81.     }
  82.     public function setDescription(?string $description): self
  83.     {
  84.         $this->description $description;
  85.         return $this;
  86.     }
  87.     public function getSum(): ?float
  88.     {
  89.         return $this->sum;
  90.     }
  91.     public function setSum(?float $sum): self
  92.     {
  93.         $this->sum $sum;
  94.         return $this;
  95.     }
  96.     public function getPercent(): ?float
  97.     {
  98.         return $this->percent;
  99.     }
  100.     public function setPercent(?float $percent): self
  101.     {
  102.         $this->percent $percent;
  103.         return $this;
  104.     }
  105.     /**
  106.      * @return Collection<int, Category>
  107.      */
  108.     public function getCategory(): Collection
  109.     {
  110.         return $this->category;
  111.     }
  112.     public function addCategory(Category $category): self
  113.     {
  114.         if (!$this->category->contains($category)) {
  115.             $this->category->add($category);
  116.         }
  117.         return $this;
  118.     }
  119.     public function removeCategory(Category $category): self
  120.     {
  121.         $this->category->removeElement($category);
  122.         return $this;
  123.     }
  124.     /**
  125.      * @return Collection<int, User>
  126.      */
  127.     public function getUsers(): Collection
  128.     {
  129.         return $this->users;
  130.     }
  131.     public function addUser(User $user): self
  132.     {
  133.         if (!$this->users->contains($user)) {
  134.             $this->users->add($user);
  135.         }
  136.         return $this;
  137.     }
  138.     public function removeUser(User $user): self
  139.     {
  140.         $this->users->removeElement($user);
  141.         return $this;
  142.     }
  143.     /**
  144.      * @return Collection<int, PreOrder>
  145.      */
  146.     public function getPreOrders(): Collection
  147.     {
  148.         return $this->pre_orders;
  149.     }
  150.     public function addPreOrder(PreOrder $preOrder): self
  151.     {
  152.         if (!$this->pre_orders->contains($preOrder)) {
  153.             $this->pre_orders->add($preOrder);
  154.             $preOrder->setCoupons($this);
  155.         }
  156.         return $this;
  157.     }
  158.     public function removePreOrder(PreOrder $preOrder): self
  159.     {
  160.         if ($this->pre_orders->removeElement($preOrder)) {
  161.             // set the owning side to null (unless already changed)
  162.             if ($preOrder->getCoupons() === $this) {
  163.                 $preOrder->setCoupons(null);
  164.             }
  165.         }
  166.         return $this;
  167.     }
  168. }