src/Entity/Coupon.php line 22

  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use App\Entity\Order;
  5. use Symfony\Component\Uid\Ulid;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Repository\CouponRepository;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. #[ORM\Entity(repositoryClassCouponRepository::class)]
  13. #[Gedmo\SoftDeleteable(fieldName'deletedAt'timeAwarefalsehardDeletetrue)]
  14. #[ORM\HasLifecycleCallbacks()]
  15. // #[ApiResource(
  16. //     attributes: ["security" => "is_granted('ROLE_SUPER_ADMIN')"],
  17. // )]
  18. class Coupon
  19. {
  20.     use Timestamps;
  21.     #[ORM\Id]
  22.     #[ORM\Column(type'ulid'uniquetrue)]
  23.     #[ORM\GeneratedValue(strategy"CUSTOM")]
  24.     #[ORM\CustomIdGenerator(class: UlidGenerator::class)]
  25.     private ?Ulid $id null;
  26.     #[ORM\Column(type'string'length255)]
  27.     private $name;
  28.     #[ORM\Column(type'string'length255)]
  29.     private $code;
  30.     #[ORM\Column(type'string'length255nullabletrue)]
  31.     private $description;
  32.     #[ORM\Column(type'datetime'nullabletrue)]
  33.     private $start_date;
  34.     #[ORM\Column(type'datetime'nullabletrue)]
  35.     private $expire_date;
  36.     #[ORM\Column(type'integer')]
  37.     private $amount 0;
  38.     #[ORM\Column(type'integer')]
  39.     private $usage_limit 0;
  40.     #[ORM\Column(type'integer')]
  41.     private $usage_count 0;
  42.     #[ORM\Column(type'boolean'nullabletrue)]
  43.     private $is_active true;
  44.     #[ORM\OneToMany(mappedBy'coupon'targetEntityOrder::class)]
  45.     private $orders;
  46.     public function __construct()
  47.     {
  48.         $this->start_date = new DateTime();
  49.         $this->expire_date = new DateTime();
  50.         $this->orders = new ArrayCollection();
  51.     }
  52.     public function __toString()
  53.     {
  54.         return $this->name " " "(-" $this->amount "%)";
  55.     }
  56.     public function getId(): ?Ulid
  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 getStartDate(): ?\DateTimeInterface
  88.     {
  89.         return $this->start_date;
  90.     }
  91.     public function setStartDate(\DateTimeInterface $start_date): self
  92.     {
  93.         $this->start_date $start_date;
  94.         return $this;
  95.     }
  96.     public function getExpireDate(): ?\DateTimeInterface
  97.     {
  98.         return $this->expire_date;
  99.     }
  100.     public function setExpireDate(\DateTimeInterface $expire_date): self
  101.     {
  102.         $this->expire_date $expire_date;
  103.         return $this;
  104.     }
  105.     public function getAmount(): ?int
  106.     {
  107.         return $this->amount;
  108.     }
  109.     public function setAmount(?int $amount): self
  110.     {
  111.         $this->amount $amount;
  112.         return $this;
  113.     }
  114.     public function getUsageLimit(): ?int
  115.     {
  116.         return $this->usage_limit;
  117.     }
  118.     public function setUsageLimit(int $usage_limit): self
  119.     {
  120.         $this->usage_limit $usage_limit;
  121.         return $this;
  122.     }
  123.     public function getUsageCount(): ?int
  124.     {
  125.         return $this->usage_count;
  126.     }
  127.     public function setUsageCount(int $usage_count): self
  128.     {
  129.         $this->usage_count $usage_count;
  130.         return $this;
  131.     }
  132.     public function getIsActive(): ?bool
  133.     {
  134.         return $this->is_active;
  135.     }
  136.     public function setIsActive(?bool $is_active): self
  137.     {
  138.         $this->is_active $is_active;
  139.         return $this;
  140.     }
  141.     /**
  142.      * @return Collection<int, Order>
  143.      */
  144.     public function getOrders(): Collection
  145.     {
  146.         return $this->orders;
  147.     }
  148.     public function addOrder(Order $order): self
  149.     {
  150.         if (!$this->orders->contains($order)) {
  151.             $this->orders[] = $order;
  152.             $order->setCoupon($this);
  153.         }
  154.         return $this;
  155.     }
  156.     public function removeOrder(Order $order): self
  157.     {
  158.         if ($this->orders->removeElement($order)) {
  159.             // set the owning side to null (unless already changed)
  160.             if ($order->getCoupon() === $this) {
  161.                 $order->setCoupon(null);
  162.             }
  163.         }
  164.         return $this;
  165.     }
  166.     public function isIsActive(): ?bool
  167.     {
  168.         return $this->is_active;
  169.     }
  170. }