src/Flexy/ShopBundle/Entity/Promotion/Promotion.php line 15

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Promotion;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Entity\Product\Product;
  5. use App\Flexy\ShopBundle\Repository\Promotion\PromotionRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. #[ApiResource]
  11. #[ORM\Entity(repositoryClassPromotionRepository::class)]
  12. class Promotion implements \Stringable
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column(type'integer')]
  17.     private $id;
  18.     #[ORM\Column(type'float')]
  19.     
  20.     private ?float $value 0;
  21.     #[ORM\Column(type'string'length255nullabletrue)]
  22.     private ?string $type "simple";
  23.     #[ORM\Column(type'text'nullabletrue)]
  24.     private ?string $description null;
  25.     #[ORM\Column(type'string'length255)]
  26.     private ?string $code null;
  27.     #[ORM\Column(type'string'length255)]
  28.     #[Assert\NotNull()]
  29.     private ?string $name null;
  30.     #[ORM\Column(type'integer'nullabletrue)]
  31.     private ?int $priority null;
  32.     #[ORM\Column(type'integer'nullabletrue)]
  33.     private ?int $usageLimit null;
  34.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  35.     private ?\DateTimeImmutable $startAt null;
  36.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  37.     private ?\DateTimeImmutable $endAt null;
  38.     #[ORM\OneToMany(targetEntityCoupon::class, mappedBy'promotion')]
  39.     private \Doctrine\Common\Collections\Collection|array $coupons;
  40.     #[ORM\OneToMany(targetEntityPromotionRule::class, mappedBy'promotion'orphanRemovaltrue)]
  41.     private \Doctrine\Common\Collections\Collection|array $promotionRules;
  42.     #[ORM\OneToMany(targetEntityPromotionAction::class, mappedBy'promotion'orphanRemovaltrue)]
  43.     private \Doctrine\Common\Collections\Collection|array $promotionActions;
  44.     #[ORM\OneToMany(targetEntityProduct::class, mappedBy'promotion')]
  45.     private \Doctrine\Common\Collections\Collection|array $products;
  46.     public function __toString(): string
  47.     {
  48.         return (string) $this->name;
  49.     }
  50.     public function __construct()
  51.     {
  52.         $this->coupons = new ArrayCollection();
  53.         $this->promotionRules = new ArrayCollection();
  54.         $this->promotionActions = new ArrayCollection();
  55.         $this->products = new ArrayCollection();
  56.     }
  57.     public function getId(): ?int
  58.     {
  59.         return $this->id;
  60.     }
  61.     public function getValue(): ?float
  62.     {
  63.         return $this->value;
  64.     }
  65.     public function setValue(float $value): self
  66.     {
  67.         $this->value $value;
  68.         return $this;
  69.     }
  70.     public function getType(): ?string
  71.     {
  72.         return $this->type;
  73.     }
  74.     public function setType(?string $type): self
  75.     {
  76.         $this->type $type;
  77.         return $this;
  78.     }
  79.     public function getDescription(): ?string
  80.     {
  81.         return $this->description;
  82.     }
  83.     public function setDescription(?string $description): self
  84.     {
  85.         $this->description $description;
  86.         return $this;
  87.     }
  88.     public function getCode(): ?string
  89.     {
  90.         return $this->code;
  91.     }
  92.     public function setCode(string $code): self
  93.     {
  94.         $this->code $code;
  95.         return $this;
  96.     }
  97.     public function getName(): ?string
  98.     {
  99.         return $this->name;
  100.     }
  101.     public function setName(string $name): self
  102.     {
  103.         $this->name $name;
  104.         return $this;
  105.     }
  106.     public function getPriority(): ?int
  107.     {
  108.         return $this->priority;
  109.     }
  110.     public function setPriority(?int $priority): self
  111.     {
  112.         $this->priority $priority;
  113.         return $this;
  114.     }
  115.     public function getUsageLimit(): ?int
  116.     {
  117.         return $this->usageLimit;
  118.     }
  119.     public function setUsageLimit(?int $usageLimit): self
  120.     {
  121.         $this->usageLimit $usageLimit;
  122.         return $this;
  123.     }
  124.     public function getStartAt(): ?\DateTimeImmutable
  125.     {
  126.         return $this->startAt;
  127.     }
  128.     public function setStartAt(?\DateTimeImmutable $startAt): self
  129.     {
  130.         $this->startAt $startAt;
  131.         return $this;
  132.     }
  133.     public function getEndAt(): ?\DateTimeImmutable
  134.     {
  135.         return $this->endAt;
  136.     }
  137.     public function setEndAt(?\DateTimeImmutable $endAt): self
  138.     {
  139.         $this->endAt $endAt;
  140.         return $this;
  141.     }
  142.     /**
  143.      * @return Collection|Coupon[]
  144.      */
  145.     public function getCoupons(): Collection
  146.     {
  147.         return $this->coupons;
  148.     }
  149.     public function addCoupon(Coupon $coupon): self
  150.     {
  151.         if (!$this->coupons->contains($coupon)) {
  152.             $this->coupons[] = $coupon;
  153.             $coupon->setPromotion($this);
  154.         }
  155.         return $this;
  156.     }
  157.     public function removeCoupon(Coupon $coupon): self
  158.     {
  159.         if ($this->coupons->removeElement($coupon)) {
  160.             // set the owning side to null (unless already changed)
  161.             if ($coupon->getPromotion() === $this) {
  162.                 $coupon->setPromotion(null);
  163.             }
  164.         }
  165.         return $this;
  166.     }
  167.     /**
  168.      * @return Collection|PromotionRule[]
  169.      */
  170.     public function getPromotionRules(): Collection
  171.     {
  172.         return $this->promotionRules;
  173.     }
  174.     public function addPromotionRule(PromotionRule $promotionRule): self
  175.     {
  176.         if (!$this->promotionRules->contains($promotionRule)) {
  177.             $this->promotionRules[] = $promotionRule;
  178.             $promotionRule->setPromotion($this);
  179.         }
  180.         return $this;
  181.     }
  182.     public function removePromotionRule(PromotionRule $promotionRule): self
  183.     {
  184.         if ($this->promotionRules->removeElement($promotionRule)) {
  185.             // set the owning side to null (unless already changed)
  186.             if ($promotionRule->getPromotion() === $this) {
  187.                 $promotionRule->setPromotion(null);
  188.             }
  189.         }
  190.         return $this;
  191.     }
  192.     /**
  193.      * @return Collection|PromotionAction[]
  194.      */
  195.     public function getPromotionActions(): Collection
  196.     {
  197.         return $this->promotionActions;
  198.     }
  199.     public function addPromotionAction(PromotionAction $promotionAction): self
  200.     {
  201.         if (!$this->promotionActions->contains($promotionAction)) {
  202.             $this->promotionActions[] = $promotionAction;
  203.             $promotionAction->setPromotion($this);
  204.         }
  205.         return $this;
  206.     }
  207.     public function removePromotionAction(PromotionAction $promotionAction): self
  208.     {
  209.         if ($this->promotionActions->removeElement($promotionAction)) {
  210.             // set the owning side to null (unless already changed)
  211.             if ($promotionAction->getPromotion() === $this) {
  212.                 $promotionAction->setPromotion(null);
  213.             }
  214.         }
  215.         return $this;
  216.     }
  217.     /**
  218.      * @return Collection|Product[]
  219.      */
  220.     public function getProducts(): Collection
  221.     {
  222.         return $this->products;
  223.     }
  224.     public function addProduct(Product $product): self
  225.     {
  226.         if (!$this->products->contains($product)) {
  227.             $this->products[] = $product;
  228.             $product->setPromotion($this);
  229.         }
  230.         return $this;
  231.     }
  232.     public function removeProduct(Product $product): self
  233.     {
  234.         if ($this->products->removeElement($product)) {
  235.             // set the owning side to null (unless already changed)
  236.             if ($product->getPromotion() === $this) {
  237.                 $product->setPromotion(null);
  238.             }
  239.         }
  240.         return $this;
  241.     }
  242. }