src/Entity/Promocode.php line 17

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use App\Repository\PromocodeRepository;
  5. use App\Traits\UuidEntityTrait;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=PromocodeRepository::class)
  9.  * @ORM\Table(indexes={
  10.  *     @ORM\Index(name="promocode_value", columns={"value"})
  11.  * })
  12.  */
  13. class Promocode
  14. {
  15.     use UuidEntityTrait;
  16.     /**
  17.      * @ORM\Column(type="string", length=255, unique=true)
  18.      */
  19.     private string $owner;
  20.     /**
  21.      * @ORM\Column(type="string", length=255, unique=true)
  22.      */
  23.     private ?string $value null;
  24.     /**
  25.      * @ORM\Column(type="integer")
  26.      */
  27.     private int $uses 0;
  28.     /**
  29.      * @ORM\Column(type="json", options={"default": "{}"})
  30.      */
  31.     private array $used = [];
  32.     public function __construct(string $email)
  33.     {
  34.         $this->owner $email;
  35.     }
  36.     public function getOwner(): string
  37.     {
  38.         return $this->owner;
  39.     }
  40.     public function setOwner(string $owner): self
  41.     {
  42.         $this->owner $owner;
  43.         return $this;
  44.     }
  45.     public function getValue(): ?string
  46.     {
  47.         return $this->value;
  48.     }
  49.     public function setValue(string $value): self
  50.     {
  51.         $this->value $value;
  52.         return $this;
  53.     }
  54.     public function getUses(): int
  55.     {
  56.         return $this->uses;
  57.     }
  58.     public function setUses(int $uses): self
  59.     {
  60.         $this->uses $uses;
  61.         return $this;
  62.     }
  63.     public function getUsed(): array
  64.     {
  65.         return $this->used;
  66.     }
  67.     public function addUsed(string $used): self
  68.     {
  69.         if (!\in_array($used$this->used)) {
  70.             $this->used[] = $used;
  71.         }
  72.         return $this;
  73.     }
  74.     public function removeUsed(string $used): self
  75.     {
  76.         if (($key \array_search($used$this->used)) !== false) {
  77.             unset($this->used[$key]);
  78.         }
  79.         return $this;
  80.     }
  81. }