<?phpnamespace App\Entity\Gos;use App\Repository\Gos\ColporteurVoucherRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;/** * @ORM\Entity(repositoryClass=ColporteurVoucherRepository::class) * @ORM\HasLifecycleCallbacks */class ColporteurVoucher{ /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255) */ private $name; /** * @ORM\Column(type="integer") */ private $quantity; /** * @ORM\ManyToOne(targetEntity=ProductVariant::class) * @ORM\JoinColumn(nullable=false) */ private $productVariant; /** * @ORM\Column(type="datetime") */ private $dateTo; /** * @ORM\OneToMany(targetEntity=Coupon::class, mappedBy="colporteurVoucher") */ private $coupons; /** * @ORM\Column(type="datetime") */ private $createdAt; /** * @ORM\Column(type="string", length=255) */ private $createdBy; public function __construct() { $this->coupons = new ArrayCollection(); } /** * @ORM\PrePersist() */ public function prePersist() { $this->createdAt = new \DateTime(); } public function getUsedCoupons(): array { $used = []; foreach ($this->coupons as $coupon) { /** @var Coupon $coupon */ if ($coupon->getUsesLeft() === 0) { $used[] = $coupon; } } return $used; } public function getId(): ?int { return $this->id; } public function getName(): ?string { return $this->name; } public function setName(string $name): self { $this->name = $name; return $this; } public function getQuantity(): ?int { return $this->quantity; } public function setQuantity(int $quantity): self { $this->quantity = $quantity; return $this; } public function getProductVariant(): ?ProductVariant { return $this->productVariant; } public function setProductVariant(?ProductVariant $productVariant): self { $this->productVariant = $productVariant; return $this; } public function getDateTo(): ?\DateTimeInterface { return $this->dateTo; } public function setDateTo(\DateTimeInterface $dateTo): self { $this->dateTo = $dateTo; return $this; } /** * @return Collection|Coupon[] */ public function getCoupons(): Collection { return $this->coupons; } public function addCoupon(Coupon $coupon): self { if (!$this->coupons->contains($coupon)) { $this->coupons[] = $coupon; $coupon->setColporteurVoucher($this); } return $this; } public function removeCoupon(Coupon $coupon): self { if ($this->coupons->contains($coupon)) { $this->coupons->removeElement($coupon); // set the owning side to null (unless already changed) if ($coupon->getColporteurVoucher() === $this) { $coupon->setColporteurVoucher(null); } } return $this; } public function getCreatedAt(): ?\DateTimeInterface { return $this->createdAt; } public function setCreatedAt(\DateTimeInterface $createdAt): self { $this->createdAt = $createdAt; return $this; } public function getCreatedBy(): ?string { return $this->createdBy; } public function setCreatedBy(string $createdBy): self { $this->createdBy = $createdBy; return $this; }}