src/Entity/Coupons.php line 24

  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'])]
  42.     #[ORM\ManyToMany(targetEntityCategory::class, inversedBy'coupons')]
  43.     private Collection $category;
  44.     #[Groups(['coupon:read''coupon:write''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.     #[Groups(['coupon:read''coupon:write''pre_order:read','cat:read'])]
  51.     #[ORM\Column(length100nullabletrue)]
  52.     private ?string $status null;
  53.     public function __construct()
  54.     {
  55.         $this->category = new ArrayCollection();
  56.         $this->users = new ArrayCollection();
  57.         $this->pre_orders = new ArrayCollection();
  58.     }
  59.     public function getId(): ?int
  60.     {
  61.         return $this->id;
  62.     }
  63.     public function getName(): ?string
  64.     {
  65.         return $this->name;
  66.     }
  67.     public function setName(string $name): self
  68.     {
  69.         $this->name $name;
  70.         return $this;
  71.     }
  72.     public function getCode(): ?string
  73.     {
  74.         return $this->code;
  75.     }
  76.     public function setCode(string $code): self
  77.     {
  78.         $this->code $code;
  79.         return $this;
  80.     }
  81.     public function getDescription(): ?string
  82.     {
  83.         return $this->description;
  84.     }
  85.     public function setDescription(?string $description): self
  86.     {
  87.         $this->description $description;
  88.         return $this;
  89.     }
  90.     public function getSum(): ?float
  91.     {
  92.         return $this->sum;
  93.     }
  94.     public function setSum(?float $sum): self
  95.     {
  96.         $this->sum $sum;
  97.         return $this;
  98.     }
  99.     public function getPercent(): ?float
  100.     {
  101.         return $this->percent;
  102.     }
  103.     public function setPercent(?float $percent): self
  104.     {
  105.         $this->percent $percent;
  106.         return $this;
  107.     }
  108.     /**
  109.      * @return Collection<int, Category>
  110.      */
  111.     public function getCategory(): Collection
  112.     {
  113.         return $this->category;
  114.     }
  115.     public function addCategory(Category $category): self
  116.     {
  117.         if (!$this->category->contains($category)) {
  118.             $this->category->add($category);
  119.         }
  120.         return $this;
  121.     }
  122.     public function removeCategory(Category $category): self
  123.     {
  124.         $this->category->removeElement($category);
  125.         return $this;
  126.     }
  127.     /**
  128.      * @return Collection<int, User>
  129.      */
  130.     public function getUsers(): Collection
  131.     {
  132.         return $this->users;
  133.     }
  134.     public function addUser(User $user): self
  135.     {
  136.         if (!$this->users->contains($user)) {
  137.             $this->users->add($user);
  138.         }
  139.         return $this;
  140.     }
  141.     public function removeUser(User $user): self
  142.     {
  143.         $this->users->removeElement($user);
  144.         return $this;
  145.     }
  146.     /**
  147.      * @return Collection<int, PreOrder>
  148.      */
  149.     public function getPreOrders(): Collection
  150.     {
  151.         return $this->pre_orders;
  152.     }
  153.     public function addPreOrder(PreOrder $preOrder): self
  154.     {
  155.         if (!$this->pre_orders->contains($preOrder)) {
  156.             $this->pre_orders->add($preOrder);
  157.             $preOrder->setCoupons($this);
  158.         }
  159.         return $this;
  160.     }
  161.     public function removePreOrder(PreOrder $preOrder): self
  162.     {
  163.         if ($this->pre_orders->removeElement($preOrder)) {
  164.             // set the owning side to null (unless already changed)
  165.             if ($preOrder->getCoupons() === $this) {
  166.                 $preOrder->setCoupons(null);
  167.             }
  168.         }
  169.         return $this;
  170.     }
  171.     public function getStatus(): ?string
  172.     {
  173.         return $this->status;
  174.     }
  175.     public function setStatus(?string $status): static
  176.     {
  177.         $this->status $status;
  178.         return $this;
  179.     }
  180. }