<?phpnamespace App\Entity\Gos;use Doctrine\ORM\Mapping as ORM;/** * CouponPending * * @ORM\Table() * @ORM\Entity(repositoryClass="App\Repository\CouponPendingRepository") * @ORM\HasLifecycleCallbacks */class CouponPending{ /** * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="token", type="string", length=255) */ private $token; /** * @ORM\ManyToOne(targetEntity="App\Entity\Gos\Cart", inversedBy="couponPending") */ private $cart; /** * @ORM\ManyToOne(targetEntity="App\Entity\Gos\Coupon", inversedBy="couponPending", cascade={"persist"}) * @ORM\JoinColumn() */ private $coupon; /** * @ORM\Column(type="datetime") */ private $createdAt; /** * @ORM\Column(type="datetime", nullable=true) */ private $updatedAt; /** @ORM\PrePersist() */ public function prePersist() { $this->createdAt = new \DateTime(); } /** @ORM\PreUpdate() */ public function preUpdate() { $this->updatedAt = new \DateTime(); } public function __toString() { return (string)$this->token; } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set token * * @param string $token * * @return CouponPending */ public function setToken($token) { $this->token = $token; return $this; } /** * Get token * * @return string */ public function getToken() { return $this->token; } /** * Set createdAt * * @param \DateTime $createdAt * * @return CouponPending */ public function setCreatedAt($createdAt) { $this->createdAt = $createdAt; return $this; } /** * Get createdAt * * @return \DateTime */ public function getCreatedAt() { return $this->createdAt; } /** * Set updatedAt * * @param \DateTime $updatedAt * * @return CouponPending */ public function setUpdatedAt($updatedAt) { $this->updatedAt = $updatedAt; return $this; } /** * Get updatedAt * * @return \DateTime */ public function getUpdatedAt() { return $this->updatedAt; } /** * Set cart * * @param \App\Entity\Gos\Cart $cart * * @return CouponPending */ public function setCart(\App\Entity\Gos\Cart $cart = null) { $this->cart = $cart; return $this; } /** * Get cart * * @return \App\Entity\Gos\Cart */ public function getCart() { return $this->cart; } /** * Set coupon * * @param \App\Entity\Gos\Coupon $coupon * * @return CouponPending */ public function setCoupon(\App\Entity\Gos\Coupon $coupon = null) { $this->coupon = $coupon; return $this; } /** * Get coupon * * @return \App\Entity\Gos\Coupon */ public function getCoupon() { return $this->coupon; } public function getIsActive(): bool { if ($this->getCreatedAt() >= (new \DateTime('now'))->modify('-30 minutes') && $this->getCoupon() && $this->getCoupon()->getIsActive() && $this->getCoupon()->getDateFrom() < new \DateTime('now') && $this->getCoupon()->getDateTo() > new \DateTime('now')) { return true; } return false; }}