src/Entity/DiscountCode.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\DiscountCodeRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Symfony\Component\Validator\Mapping\ClassMetadata;
  10. #[ORM\Entity(repositoryClassDiscountCodeRepository::class)]
  11. class DiscountCode
  12. {
  13.     public static function loadValidatorMetadata(ClassMetadata $metadata)
  14.     {
  15.         $metadata->addConstraint(new UniqueEntity([
  16.             'fields' => 'code',
  17.             'message' => 'Already use',
  18.         ]));
  19.     }
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue]
  22.     #[ORM\Column(type'integer')]
  23.     private $id;
  24.     #[ORM\Column(type'string'length255)]
  25.     private $code;
  26.     #[ORM\Column(type'float'nullabletrue)]
  27.     #[Assert\Type(type'float'message'Veillez saisir un nombre valide')]
  28.     #[Assert\Expression('this.checkRange()'message'Veillez saisir un nombre valide')]
  29.     private $discount;
  30.     #[ORM\Column(type'string'length255)]
  31.     private $type;
  32.     #[ORM\Column(type'date')]
  33.     private $createdAt;
  34.     #[ORM\Column(type'string'length255)]
  35.     private $status;
  36.     #[ORM\Column(type'date'nullabletrue)]
  37.     private $validity;
  38.     #[ORM\Column(type'integer'nullabletrue)]
  39.     private $numberOfUses;
  40.     #[ORM\OneToMany(targetEntitySubscription::class, mappedBy'discount')]
  41.     private $subscriptions;
  42.     #[ORM\Column(length255nullabletrue)]
  43.     private ?string $recipientEmail null;
  44.     #[ORM\Column(length255nullabletrue)]
  45.     private ?string $recipientType null;
  46.     #[ORM\Column(length255nullabletrue)]
  47.     private ?string $language null;
  48.     public function __construct()
  49.     {
  50.         $this->subscriptions = new ArrayCollection();
  51.     }
  52.     public function checkRange(){
  53.         if($this->discount 100 || $this->discount 0){
  54.             return false;
  55.         }
  56.         return true;
  57.     }
  58.     public function getId(): ?int
  59.     {
  60.         return $this->id;
  61.     }
  62.     public function getCode(): ?string
  63.     {
  64.         return $this->code;
  65.     }
  66.     public function setCode(string $code): self
  67.     {
  68.         $this->code $code;
  69.         return $this;
  70.     }
  71.     public function getDiscount(): ?float
  72.     {
  73.         return $this->discount;
  74.     }
  75.     public function setDiscount(?float $discount): self
  76.     {
  77.         $this->discount $discount;
  78.         return $this;
  79.     }
  80.     public function getType(): ?string
  81.     {
  82.         return $this->type;
  83.     }
  84.     public function setType(string $type): self
  85.     {
  86.         $this->type $type;
  87.         return $this;
  88.     }
  89.     public function getCreatedAt(): ?\DateTimeInterface
  90.     {
  91.         return $this->createdAt;
  92.     }
  93.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  94.     {
  95.         $this->createdAt $createdAt;
  96.         return $this;
  97.     }
  98.     public function getStatus(): ?string
  99.     {
  100.         return $this->status;
  101.     }
  102.     public function setStatus(string $status): self
  103.     {
  104.         $this->status $status;
  105.         return $this;
  106.     }
  107.     public function getValidity(): ?\DateTimeInterface
  108.     {
  109.         return $this->validity;
  110.     }
  111.     public function setValidity(?\DateTimeInterface $validity): self
  112.     {
  113.         $this->validity $validity;
  114.         return $this;
  115.     }
  116.     public function getNumberOfUses(): ?int
  117.     {
  118.         return $this->numberOfUses;
  119.     }
  120.     public function setNumberOfUses(?int $numberOfUses): self
  121.     {
  122.         $this->numberOfUses $numberOfUses;
  123.         return $this;
  124.     }
  125.     /**
  126.      * @return Collection|Subscription[]
  127.      */
  128.     public function getSubscriptions(): Collection
  129.     {
  130.         return $this->subscriptions;
  131.     }
  132.     public function addSubscription(Subscription $subscription): self
  133.     {
  134.         if (!$this->subscriptions->contains($subscription)) {
  135.             $this->subscriptions[] = $subscription;
  136.             $subscription->setDiscount($this);
  137.         }
  138.         return $this;
  139.     }
  140.     public function removeSubscription(Subscription $subscription): self
  141.     {
  142.         if ($this->subscriptions->removeElement($subscription)) {
  143.             // set the owning side to null (unless already changed)
  144.             if ($subscription->getDiscount() === $this) {
  145.                 $subscription->setDiscount(null);
  146.             }
  147.         }
  148.         return $this;
  149.     }
  150.     public function getRecipientEmail(): ?string
  151.     {
  152.         return $this->recipientEmail;
  153.     }
  154.     public function setRecipientEmail(?string $recipientEmail): static
  155.     {
  156.         $this->recipientEmail $recipientEmail;
  157.         return $this;
  158.     }
  159.     public function getRecipientType(): ?string
  160.     {
  161.         return $this->recipientType;
  162.     }
  163.     public function setRecipientType(?string $recipientType): static
  164.     {
  165.         $this->recipientType $recipientType;
  166.         return $this;
  167.     }
  168.     public function getLanguage(): ?string
  169.     {
  170.         return $this->language;
  171.     }
  172.     public function setLanguage(?string $language): static
  173.     {
  174.         $this->language $language;
  175.         return $this;
  176.     }
  177. }