src/Entity/Coupon.php line 22
<?php
namespace App\Entity;
use DateTime;
use App\Entity\Order;
use Symfony\Component\Uid\Ulid;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\CouponRepository;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Entity(repositoryClass: CouponRepository::class)]
#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: true)]
#[ORM\HasLifecycleCallbacks()]
// #[ApiResource(
// attributes: ["security" => "is_granted('ROLE_SUPER_ADMIN')"],
// )]
class Coupon
{
use Timestamps;
#[ORM\Id]
#[ORM\Column(type: 'ulid', unique: true)]
#[ORM\GeneratedValue(strategy: "CUSTOM")]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private ?Ulid $id = null;
#[ORM\Column(type: 'string', length: 255)]
private $name;
#[ORM\Column(type: 'string', length: 255)]
private $code;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $description;
#[ORM\Column(type: 'datetime', nullable: true)]
private $start_date;
#[ORM\Column(type: 'datetime', nullable: true)]
private $expire_date;
#[ORM\Column(type: 'integer')]
private $amount = 0;
#[ORM\Column(type: 'integer')]
private $usage_limit = 0;
#[ORM\Column(type: 'integer')]
private $usage_count = 0;
#[ORM\Column(type: 'boolean', nullable: true)]
private $is_active = true;
#[ORM\OneToMany(mappedBy: 'coupon', targetEntity: Order::class)]
private $orders;
public function __construct()
{
$this->start_date = new DateTime();
$this->expire_date = new DateTime();
$this->orders = new ArrayCollection();
}
public function __toString()
{
return $this->name . " " . "(-" . $this->amount . "%)";
}
public function getId(): ?Ulid
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getStartDate(): ?\DateTimeInterface
{
return $this->start_date;
}
public function setStartDate(\DateTimeInterface $start_date): self
{
$this->start_date = $start_date;
return $this;
}
public function getExpireDate(): ?\DateTimeInterface
{
return $this->expire_date;
}
public function setExpireDate(\DateTimeInterface $expire_date): self
{
$this->expire_date = $expire_date;
return $this;
}
public function getAmount(): ?int
{
return $this->amount;
}
public function setAmount(?int $amount): self
{
$this->amount = $amount;
return $this;
}
public function getUsageLimit(): ?int
{
return $this->usage_limit;
}
public function setUsageLimit(int $usage_limit): self
{
$this->usage_limit = $usage_limit;
return $this;
}
public function getUsageCount(): ?int
{
return $this->usage_count;
}
public function setUsageCount(int $usage_count): self
{
$this->usage_count = $usage_count;
return $this;
}
public function getIsActive(): ?bool
{
return $this->is_active;
}
public function setIsActive(?bool $is_active): self
{
$this->is_active = $is_active;
return $this;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setCoupon($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getCoupon() === $this) {
$order->setCoupon(null);
}
}
return $this;
}
public function isIsActive(): ?bool
{
return $this->is_active;
}
}