src/Flexy/ShopBundle/Entity/Promotion/Promotion.php line 15
<?php
namespace App\Flexy\ShopBundle\Entity\Promotion;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Flexy\ShopBundle\Entity\Product\Product;
use App\Flexy\ShopBundle\Repository\Promotion\PromotionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource]
#[ORM\Entity(repositoryClass: PromotionRepository::class)]
class Promotion implements \Stringable
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'float')]
private ?float $value = 0;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $type = "simple";
#[ORM\Column(type: 'text', nullable: true)]
private ?string $description = null;
#[ORM\Column(type: 'string', length: 255)]
private ?string $code = null;
#[ORM\Column(type: 'string', length: 255)]
#[Assert\NotNull()]
private ?string $name = null;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $priority = null;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $usageLimit = null;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?\DateTimeImmutable $startAt = null;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?\DateTimeImmutable $endAt = null;
#[ORM\OneToMany(targetEntity: Coupon::class, mappedBy: 'promotion')]
private \Doctrine\Common\Collections\Collection|array $coupons;
#[ORM\OneToMany(targetEntity: PromotionRule::class, mappedBy: 'promotion', orphanRemoval: true)]
private \Doctrine\Common\Collections\Collection|array $promotionRules;
#[ORM\OneToMany(targetEntity: PromotionAction::class, mappedBy: 'promotion', orphanRemoval: true)]
private \Doctrine\Common\Collections\Collection|array $promotionActions;
#[ORM\OneToMany(targetEntity: Product::class, mappedBy: 'promotion')]
private \Doctrine\Common\Collections\Collection|array $products;
public function __toString(): string
{
return (string) $this->name;
}
public function __construct()
{
$this->coupons = new ArrayCollection();
$this->promotionRules = new ArrayCollection();
$this->promotionActions = new ArrayCollection();
$this->products = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getValue(): ?float
{
return $this->value;
}
public function setValue(float $value): self
{
$this->value = $value;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getPriority(): ?int
{
return $this->priority;
}
public function setPriority(?int $priority): self
{
$this->priority = $priority;
return $this;
}
public function getUsageLimit(): ?int
{
return $this->usageLimit;
}
public function setUsageLimit(?int $usageLimit): self
{
$this->usageLimit = $usageLimit;
return $this;
}
public function getStartAt(): ?\DateTimeImmutable
{
return $this->startAt;
}
public function setStartAt(?\DateTimeImmutable $startAt): self
{
$this->startAt = $startAt;
return $this;
}
public function getEndAt(): ?\DateTimeImmutable
{
return $this->endAt;
}
public function setEndAt(?\DateTimeImmutable $endAt): self
{
$this->endAt = $endAt;
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->setPromotion($this);
}
return $this;
}
public function removeCoupon(Coupon $coupon): self
{
if ($this->coupons->removeElement($coupon)) {
// set the owning side to null (unless already changed)
if ($coupon->getPromotion() === $this) {
$coupon->setPromotion(null);
}
}
return $this;
}
/**
* @return Collection|PromotionRule[]
*/
public function getPromotionRules(): Collection
{
return $this->promotionRules;
}
public function addPromotionRule(PromotionRule $promotionRule): self
{
if (!$this->promotionRules->contains($promotionRule)) {
$this->promotionRules[] = $promotionRule;
$promotionRule->setPromotion($this);
}
return $this;
}
public function removePromotionRule(PromotionRule $promotionRule): self
{
if ($this->promotionRules->removeElement($promotionRule)) {
// set the owning side to null (unless already changed)
if ($promotionRule->getPromotion() === $this) {
$promotionRule->setPromotion(null);
}
}
return $this;
}
/**
* @return Collection|PromotionAction[]
*/
public function getPromotionActions(): Collection
{
return $this->promotionActions;
}
public function addPromotionAction(PromotionAction $promotionAction): self
{
if (!$this->promotionActions->contains($promotionAction)) {
$this->promotionActions[] = $promotionAction;
$promotionAction->setPromotion($this);
}
return $this;
}
public function removePromotionAction(PromotionAction $promotionAction): self
{
if ($this->promotionActions->removeElement($promotionAction)) {
// set the owning side to null (unless already changed)
if ($promotionAction->getPromotion() === $this) {
$promotionAction->setPromotion(null);
}
}
return $this;
}
/**
* @return Collection|Product[]
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->setPromotion($this);
}
return $this;
}
public function removeProduct(Product $product): self
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getPromotion() === $this) {
$product->setPromotion(null);
}
}
return $this;
}
}