src/Entity/Gos/CouponPending.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gos;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5.  * CouponPending
  6.  *
  7.  * @ORM\Table()
  8.  * @ORM\Entity(repositoryClass="App\Repository\CouponPendingRepository")
  9.  * @ORM\HasLifecycleCallbacks
  10.  */
  11. class CouponPending
  12. {
  13.     /**
  14.      * @var int
  15.      *
  16.      * @ORM\Column(name="id", type="integer")
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue(strategy="AUTO")
  19.      */
  20.     private $id;
  21.     /**
  22.      * @var string
  23.      *
  24.      * @ORM\Column(name="token", type="string", length=255)
  25.      */
  26.     private $token;
  27.     /**
  28.      * @ORM\ManyToOne(targetEntity="App\Entity\Gos\Cart", inversedBy="couponPending")
  29.      */
  30.     private $cart;
  31.     /**
  32.      * @ORM\ManyToOne(targetEntity="App\Entity\Gos\Coupon", inversedBy="couponPending", cascade={"persist"})
  33.      * @ORM\JoinColumn()
  34.      */
  35.     private $coupon;
  36.     /**
  37.      * @ORM\Column(type="datetime")
  38.      */
  39.     private $createdAt;
  40.     /**
  41.      * @ORM\Column(type="datetime", nullable=true)
  42.      */
  43.     private $updatedAt;
  44.     /** @ORM\PrePersist() */
  45.     public function prePersist()
  46.     {
  47.         $this->createdAt = new \DateTime();
  48.     }
  49.     /** @ORM\PreUpdate() */
  50.     public function preUpdate()
  51.     {
  52.         $this->updatedAt = new \DateTime();
  53.     }
  54.     public function __toString()
  55.     {
  56.         return (string)$this->token;
  57.     }
  58.     /**
  59.      * Get id
  60.      *
  61.      * @return integer
  62.      */
  63.     public function getId()
  64.     {
  65.         return $this->id;
  66.     }
  67.     /**
  68.      * Set token
  69.      *
  70.      * @param string $token
  71.      *
  72.      * @return CouponPending
  73.      */
  74.     public function setToken($token)
  75.     {
  76.         $this->token $token;
  77.         return $this;
  78.     }
  79.     /**
  80.      * Get token
  81.      *
  82.      * @return string
  83.      */
  84.     public function getToken()
  85.     {
  86.         return $this->token;
  87.     }
  88.     /**
  89.      * Set createdAt
  90.      *
  91.      * @param \DateTime $createdAt
  92.      *
  93.      * @return CouponPending
  94.      */
  95.     public function setCreatedAt($createdAt)
  96.     {
  97.         $this->createdAt $createdAt;
  98.         return $this;
  99.     }
  100.     /**
  101.      * Get createdAt
  102.      *
  103.      * @return \DateTime
  104.      */
  105.     public function getCreatedAt()
  106.     {
  107.         return $this->createdAt;
  108.     }
  109.     /**
  110.      * Set updatedAt
  111.      *
  112.      * @param \DateTime $updatedAt
  113.      *
  114.      * @return CouponPending
  115.      */
  116.     public function setUpdatedAt($updatedAt)
  117.     {
  118.         $this->updatedAt $updatedAt;
  119.         return $this;
  120.     }
  121.     /**
  122.      * Get updatedAt
  123.      *
  124.      * @return \DateTime
  125.      */
  126.     public function getUpdatedAt()
  127.     {
  128.         return $this->updatedAt;
  129.     }
  130.     /**
  131.      * Set cart
  132.      *
  133.      * @param \App\Entity\Gos\Cart $cart
  134.      *
  135.      * @return CouponPending
  136.      */
  137.     public function setCart(\App\Entity\Gos\Cart $cart null)
  138.     {
  139.         $this->cart $cart;
  140.         return $this;
  141.     }
  142.     /**
  143.      * Get cart
  144.      *
  145.      * @return \App\Entity\Gos\Cart
  146.      */
  147.     public function getCart()
  148.     {
  149.         return $this->cart;
  150.     }
  151.     /**
  152.      * Set coupon
  153.      *
  154.      * @param \App\Entity\Gos\Coupon $coupon
  155.      *
  156.      * @return CouponPending
  157.      */
  158.     public function setCoupon(\App\Entity\Gos\Coupon $coupon null)
  159.     {
  160.         $this->coupon $coupon;
  161.         return $this;
  162.     }
  163.     /**
  164.      * Get coupon
  165.      *
  166.      * @return \App\Entity\Gos\Coupon
  167.      */
  168.     public function getCoupon()
  169.     {
  170.         return $this->coupon;
  171.     }
  172.     public function getIsActive(): bool
  173.     {
  174.         if ($this->getCreatedAt() >= (new \DateTime('now'))->modify('-30 minutes')
  175.         && $this->getCoupon()
  176.         && $this->getCoupon()->getIsActive()
  177.         && $this->getCoupon()->getDateFrom() < new \DateTime('now')
  178.         && $this->getCoupon()->getDateTo() > new \DateTime('now'))
  179.         {
  180.             return true;
  181.         }
  182.         return false;
  183.     }
  184. }