src/Entity/Promotion/PromotionCode.php line 44
<?php/** This file is part of the Pellipop project.** (c) Mobizel** For the full copyright and license information, please view the LICENSE* file that was distributed with this source code.*/declare(strict_types=1);namespace App\Entity\Promotion;use App\Entity\Customer\Customer;use App\Entity\IdentifiableTrait;use App\Entity\Payment\Payment;use App\Entity\Product\CreditPack;use App\Entity\Promotion\UniquePromotionCode\UniquePromotion;use App\PromotionCodeTypes;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Sylius\Component\Resource\Annotation\SyliusCrudRoutes;use Sylius\Component\Resource\Model\ResourceInterface;use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;use Symfony\Component\Validator\Constraints as Assert;#[ORM\Entity]#[UniqueEntity('code')]#[ORM\Table(name: 'app_promotion_code')]#[SyliusCrudRoutes(alias: 'app.promotion_code', path: '/admin/promotion-codes', section: 'backend', templates: 'backend/crud', grid: 'app_backend_promotion_code', except: ['show'], vars: ['all' => ['subheader' => 'app.ui.manage_your_promotion_codes','templates' => ['form' => 'backend/promotion_code/_form.html.twig',],],'index' => ['icon' => 'percent',],])]class PromotionCode implements ResourceInterface{use IdentifiableTrait;#[ORM\OneToMany(mappedBy: 'promotionCode', targetEntity: Payment::class)]private Collection $payments;#[ORM\ManyToOne(targetEntity: UniquePromotion::class, inversedBy: 'promotionCodes', cascade: ['persist'])]#[ORM\JoinColumn(nullable: true)]private ?UniquePromotion $uniquePromotion;#[ORM\Column(type: 'string')]#[Assert\NotBlank, Assert\Length(min: 3, max: 150)]private ?string $name = null;#[ORM\Column(type: 'string')]#[Assert\NotBlank, Assert\Length(min: 3, max: 50), Assert\Regex('/^[\w-]*$/')]private ?string $code = null;#[Assert\NotBlank]#[ORM\Column(type: 'datetime')]private ?\DateTimeInterface $startAt = null;#[Assert\NotBlank]#[ORM\Column(type: 'datetime')]private ?\DateTimeInterface $endAt = null;#[ORM\Column(type: 'integer')]private int $used = 0;#[ORM\Column(type: 'datetime', nullable: true)]private ?\DateTimeInterface $usedAt = null;#[ORM\Column(type: 'string', nullable: true)]private ?string $userEmail = null;#[ORM\Column(type: 'datetime')]private \DateTimeInterface $createdAt;#[ORM\Column(type: 'json')]private array $rules;#[ORM\ManyToMany(targetEntity: Customer::class)]private Collection $customers;private array $creditPacks = [];public function __construct(){$this->payments = new ArrayCollection();$this->rules = [];$this->createdAt = new \DateTimeImmutable();$this->customers = new ArrayCollection();}public function getName(): ?string{return $this->name;}public function setName(string $name): self{$this->name = $name;return $this;}public function getCode(): ?string{return $this->code;}public function setCode(string $code): self{$this->code = $code;return $this;}public function getStartAt(): ?\DateTimeInterface{return $this->startAt;}public function setStartAt(?\DateTimeInterface $startAt): self{$this->startAt = $startAt;return $this;}public function getEndAt(): ?\DateTimeInterface{return $this->endAt;}public function setEndAt(?\DateTimeInterface $endAt): self{$this->endAt = $endAt;return $this;}public function getUsed(): int{return $this->used;}public function setUsed(int $used): self{$this->used = $used;return $this;}public function getCreatedAt(): \DateTimeInterface{return $this->createdAt;}public function setCreatedAt(\DateTimeInterface $createdAt): self{$this->createdAt = $createdAt;return $this;}public function getRules(){return $this->rules;}public function setRules(array $rules): self{$this->rules = $rules;return $this;}public function hasRule(string $rule): bool{return array_key_exists($rule, $this->rules);}public function getRuleType(): ?string{return (!empty($this->rules)) ? strval(array_key_first($this->rules)) : null;}public function getCreditsOffered(): int{if (true === $this->hasRule(PromotionCodeTypes::TYPE_CREDITS_OFFERED)) {return $this->rules[PromotionCodeTypes::TYPE_CREDITS_OFFERED];}return 0;}public function getCreditPacks(): array{return $this->creditPacks;}public function addCreditPack(CreditPack $creditPack): self{if (!in_array($creditPack, $this->creditPacks, true)) {$this->creditPacks [] = $creditPack;}return $this;}/*** @return Collection<int, Customer>*/public function getCustomers(): Collection{return $this->customers;}public function addCustomer(Customer $customer): self{if (!$this->customers->contains($customer)) {$this->customers->add($customer);}return $this;}public function removeCustomer(Customer $customer): self{$this->customers->removeElement($customer);return $this;}public function getUniquePromotion(): ?UniquePromotion{return $this->uniquePromotion;}public function setUniquePromotion(?UniquePromotion $uniquePromotion): void{$this->uniquePromotion = $uniquePromotion;}public function getUsedAt(): ?\DateTimeInterface{return $this->usedAt;}public function setUsedAt(?\DateTimeInterface $usedAt): void{$this->usedAt = $usedAt;}public function getUserEmail(): ?string{return $this->userEmail;}public function setUserEmail(?string $userEmail): void{$this->userEmail = $userEmail;}}