src/Entity/Gos/Alert.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gos;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5.  * @ORM\Table()
  6.  * @ORM\Entity(repositoryClass="App\Repository\AlertRepository")
  7.  * @ORM\HasLifecycleCallbacks()
  8.  */
  9. class Alert
  10. {
  11.     /**
  12.      * @ORM\Id()
  13.      * @ORM\GeneratedValue()
  14.      * @ORM\Column(type="integer")
  15.      */
  16.     private $id;
  17.     /**
  18.      * @ORM\Column(type="boolean", nullable=true)
  19.      */
  20.     private $isActive;
  21.     /**
  22.      * @ORM\ManyToOne(targetEntity="App\Entity\Gos\AlertType", inversedBy="alerts")
  23.      * @ORM\JoinColumn()
  24.      */
  25.     private $type;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity="App\Entity\Gos\User", inversedBy="alerts")
  28.      * @ORM\JoinColumn()
  29.      */
  30.     private $user;
  31.     /**
  32.      * @ORM\ManyToOne(targetEntity="App\Entity\Gos\Coupon", inversedBy="alerts")
  33.      * @ORM\JoinTable()
  34.      */
  35.     private $coupon;
  36.     /**
  37.      * @ORM\ManyToOne(targetEntity="App\Entity\Gos\ProductVariant", inversedBy="alerts")
  38.      * @ORM\JoinTable()
  39.      */
  40.     private $productVariant;
  41.     /**
  42.      * @ORM\Column(type="integer")
  43.      */
  44.     private $triggerCondition;
  45.     /**
  46.      * @ORM\Column(type="datetime")
  47.      */
  48.     private $createdAt;
  49.     /**
  50.      * @ORM\Column(type="datetime", nullable=true)
  51.      */
  52.     private $updatedAt;
  53.     /** @ORM\PrePersist() */
  54.     public function prePersist()
  55.     {
  56.         $this->createdAt = new \DateTime();
  57.     }
  58.     /** @ORM\PreUpdate() */
  59.     public function preUpdate()
  60.     {
  61.         $this->updatedAt = new \DateTime();
  62.     }
  63.     public function __construct()
  64.     {
  65.         $this->isUnread false;
  66.     }
  67.     public function getId(): ?int
  68.     {
  69.         return $this->id;
  70.     }
  71.     public function getCreatedAt(): ?\DateTimeInterface
  72.     {
  73.         return $this->createdAt;
  74.     }
  75.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  76.     {
  77.         $this->createdAt $createdAt;
  78.         return $this;
  79.     }
  80.     public function getUpdatedAt(): ?\DateTimeInterface
  81.     {
  82.         return $this->updatedAt;
  83.     }
  84.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  85.     {
  86.         $this->updatedAt $updatedAt;
  87.         return $this;
  88.     }
  89.     public function getUser(): ?User
  90.     {
  91.         return $this->user;
  92.     }
  93.     public function setUser(?User $user): self
  94.     {
  95.         $this->user $user;
  96.         return $this;
  97.     }
  98.     public function getCoupon(): ?Coupon
  99.     {
  100.         return $this->coupon;
  101.     }
  102.     public function setCoupon(?Coupon $coupon): self
  103.     {
  104.         $this->coupon $coupon;
  105.         return $this;
  106.     }
  107.     public function getProductVariant(): ?ProductVariant
  108.     {
  109.         return $this->productVariant;
  110.     }
  111.     public function setProductVariant(?ProductVariant $productVariant): self
  112.     {
  113.         $this->productVariant $productVariant;
  114.         return $this;
  115.     }
  116.     public function getTriggerCondition(): ?int
  117.     {
  118.         return $this->triggerCondition;
  119.     }
  120.     public function setTriggerCondition(int $triggerCondition): self
  121.     {
  122.         $this->triggerCondition $triggerCondition;
  123.         return $this;
  124.     }
  125.     public function getIsActive(): ?bool
  126.     {
  127.         return $this->isActive;
  128.     }
  129.     public function setIsActive(?bool $isActive): self
  130.     {
  131.         $this->isActive $isActive;
  132.         return $this;
  133.     }
  134.     public function getIsTriggered(): bool
  135.     {
  136.         if ($this->getType()->getId() == 2)
  137.         {
  138.             if ($this->getCoupon()->getUsesLeft() <= $this->triggerCondition)
  139.             {
  140.                 return true;
  141.             }
  142.         }
  143.         elseif ($this->getType()->getId() == 1)
  144.         {
  145.             if ($this->getProductVariant()->getQuantityLeft() <= $this->triggerCondition)
  146.             {
  147.                 return true;
  148.             }
  149.         }
  150.         return false;
  151.     }
  152.     public function getType(): ?AlertType
  153.     {
  154.         return $this->type;
  155.     }
  156.     public function setType(?AlertType $type): self
  157.     {
  158.         $this->type $type;
  159.         return $this;
  160.     }
  161. }