src/Entity/Gos/ColporteurVoucher.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gos;
  3. use App\Repository\Gos\ColporteurVoucherRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=ColporteurVoucherRepository::class)
  9.  * @ORM\HasLifecycleCallbacks
  10.  */
  11. class ColporteurVoucher
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=255)
  21.      */
  22.     private $name;
  23.     /**
  24.      * @ORM\Column(type="integer")
  25.      */
  26.     private $quantity;
  27.     /**
  28.      * @ORM\ManyToOne(targetEntity=ProductVariant::class)
  29.      * @ORM\JoinColumn(nullable=false)
  30.      */
  31.     private $productVariant;
  32.     /**
  33.      * @ORM\Column(type="datetime")
  34.      */
  35.     private $dateTo;
  36.     /**
  37.      * @ORM\OneToMany(targetEntity=Coupon::class, mappedBy="colporteurVoucher")
  38.      */
  39.     private $coupons;
  40.     /**
  41.      * @ORM\Column(type="datetime")
  42.      */
  43.     private $createdAt;
  44.     /**
  45.      * @ORM\Column(type="string", length=255)
  46.      */
  47.     private $createdBy;
  48.     public function __construct()
  49.     {
  50.         $this->coupons = new ArrayCollection();
  51.     }
  52.     /**
  53.      * @ORM\PrePersist()
  54.      */
  55.     public function prePersist()
  56.     {
  57.         $this->createdAt = new \DateTime();
  58.     }
  59.     public function getUsedCoupons(): array
  60.     {
  61.         $used = [];
  62.         foreach ($this->coupons as $coupon)
  63.         {
  64.             /** @var Coupon $coupon */
  65.             if ($coupon->getUsesLeft() === 0)
  66.             {
  67.                 $used[] = $coupon;
  68.             }
  69.         }
  70.         return $used;
  71.     }
  72.     public function getId(): ?int
  73.     {
  74.         return $this->id;
  75.     }
  76.     public function getName(): ?string
  77.     {
  78.         return $this->name;
  79.     }
  80.     public function setName(string $name): self
  81.     {
  82.         $this->name $name;
  83.         return $this;
  84.     }
  85.     public function getQuantity(): ?int
  86.     {
  87.         return $this->quantity;
  88.     }
  89.     public function setQuantity(int $quantity): self
  90.     {
  91.         $this->quantity $quantity;
  92.         return $this;
  93.     }
  94.     public function getProductVariant(): ?ProductVariant
  95.     {
  96.         return $this->productVariant;
  97.     }
  98.     public function setProductVariant(?ProductVariant $productVariant): self
  99.     {
  100.         $this->productVariant $productVariant;
  101.         return $this;
  102.     }
  103.     public function getDateTo(): ?\DateTimeInterface
  104.     {
  105.         return $this->dateTo;
  106.     }
  107.     public function setDateTo(\DateTimeInterface $dateTo): self
  108.     {
  109.         $this->dateTo $dateTo;
  110.         return $this;
  111.     }
  112.     /**
  113.      * @return Collection|Coupon[]
  114.      */
  115.     public function getCoupons(): Collection
  116.     {
  117.         return $this->coupons;
  118.     }
  119.     public function addCoupon(Coupon $coupon): self
  120.     {
  121.         if (!$this->coupons->contains($coupon)) {
  122.             $this->coupons[] = $coupon;
  123.             $coupon->setColporteurVoucher($this);
  124.         }
  125.         return $this;
  126.     }
  127.     public function removeCoupon(Coupon $coupon): self
  128.     {
  129.         if ($this->coupons->contains($coupon)) {
  130.             $this->coupons->removeElement($coupon);
  131.             // set the owning side to null (unless already changed)
  132.             if ($coupon->getColporteurVoucher() === $this) {
  133.                 $coupon->setColporteurVoucher(null);
  134.             }
  135.         }
  136.         return $this;
  137.     }
  138.     public function getCreatedAt(): ?\DateTimeInterface
  139.     {
  140.         return $this->createdAt;
  141.     }
  142.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  143.     {
  144.         $this->createdAt $createdAt;
  145.         return $this;
  146.     }
  147.     public function getCreatedBy(): ?string
  148.     {
  149.         return $this->createdBy;
  150.     }
  151.     public function setCreatedBy(string $createdBy): self
  152.     {
  153.         $this->createdBy $createdBy;
  154.         return $this;
  155.     }
  156. }