src/Entity/Promotion/UniquePromotionCode/UniquePromotion.php line 56
<?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\UniquePromotionCode;use App\Controller\DownloadUniquePromotionCode;use App\Entity\IdentifiableTrait;use App\Entity\Promotion\PromotionCode;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\Annotation\SyliusRoute;use Sylius\Component\Resource\Model\ResourceInterface;use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;use Symfony\Component\Validator\Constraints as Assert;#[ORM\Entity]#[UniqueEntity('name')]#[ORM\Table(name: 'app_unique_promotion')]#[SyliusCrudRoutes(alias: 'app.unique_promotion',path: '/admin/unique-promotion',section: 'backend',templates: 'backend/unique_promotion',grid: 'app_backend_unique_promotion',only: ['index', 'show', 'create'],vars: ['all' => ['subheader' => 'app.ui.manage_unique_promotions','templates' => ['form' => 'backend/unique_promotion/_form.html.twig',],],'index' => ['icon' => 'percent',],],)]#[SyliusRoute(name: 'app_backend_unique_promotion_download',path: '/admin/unique-promotion/{id}/download',methods: ['GET'],controller: DownloadUniquePromotionCode::class,)]class UniquePromotion implements ResourceInterface{use IdentifiableTrait;#[ORM\Column(type: 'string', nullable: true)]#[Assert\Length(min: 3, max: 10), Assert\Regex('/^[\w-]*$/')]private ?string $prefix = null;#[ORM\Column(type: 'string')]#[Assert\NotBlank, Assert\Length(min: 3, max: 50)]private ?string $name = null;#[ORM\Column(type: 'integer')]#[Assert\NotBlank]private ?int $credits = null;#[ORM\Column(type: 'integer')]#[Assert\NotBlank]private ?int $number = null;#[ORM\OneToMany(mappedBy: 'uniquePromotion', targetEntity: PromotionCode::class, cascade: ['persist'])]private ?Collection $promotionCodes;public function __construct(){$this->promotionCodes = new ArrayCollection();}public function getPrefix(): ?string{return $this->prefix;}public function setPrefix(?string $prefix): void{$this->prefix = $prefix;}public function getCredits(): ?int{return $this->credits;}public function setCredits(?int $credits): void{$this->credits = $credits;}public function getNumber(): ?int{return $this->number;}public function setNumber(?int $number): void{$this->number = $number;}public function getName(): ?string{return $this->name;}public function setName(?string $name): void{$this->name = $name;}public function getPromotionCodes(): ?Collection{return $this->promotionCodes;}public function addPromotionCode(PromotionCode $promotionCode): self{if (!$this->promotionCodes->contains($promotionCode)) {$this->promotionCodes[] = $promotionCode;$promotionCode->setUniquePromotion($this);}return $this;}public function removePromotionCode(PromotionCode $promotionCode): self{if ($this->promotionCodes->removeElement($promotionCode)) {// set the owning side to null (unless already changed)if ($promotionCode->getUniquePromotion() === $this) {$promotionCode->setUniquePromotion(null);}}return $this;}}