src/Entity/CardType.php line 15

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CardTypeRepository;
  4. use App\Trait\ArrayableTrait;
  5. use App\Trait\DateTrait;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. #[ORM\Entity(repositoryClass: CardTypeRepository::class)]
  12. class CardType
  13. {
  14.     use ArrayableTrait;
  15.     use DateTrait{DateTrait::__construct as private constructDate;}
  16.     const CLIENT = 'card.type.client';
  17.     const EMPLOYEE = 'card.type.employee';
  18.     const MEMBER = 'card.type.member';
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column]
  22.     private ?int $id = null;
  23.     #[ORM\Column(length: 255)]
  24.     private ?string $name = null;
  25.     #[ORM\OneToMany(mappedBy: 'cardType', targetEntity: Card::class, orphanRemoval: true)]
  26.     private Collection $cards;
  27.     #[ORM\ManyToOne(inversedBy: 'cardTypes')]
  28.     #[ORM\JoinColumn(nullable: false)]
  29.     private ?Establishment $establishment = null;
  30.     #[ORM\Column(nullable: false)]
  31.     private ?array $textPlaces = [];
  32.     #[ORM\Column(length: 255)]
  33.     #[Assert\Choice(callback: [self::class, 'getList'])]
  34.     private ?string $type = null;
  35.     #[ORM\ManyToOne(cascade: ['persist'])]
  36.     private ?Attachment $file = null;
  37.     #[ORM\ManyToOne(cascade: ['persist'])]
  38.     private ?Attachment $fileBack = null;
  39.     #[ORM\Column]
  40.     private ?bool $withBack = false;
  41.     #[ORM\Column]
  42.     private ?array $identificators = [];
  43.     #[ORM\Column]
  44.     private ?bool $withWallet = false;
  45.     #[ORM\ManyToMany(targetEntity: Currency::class)]
  46.     private Collection $currencySupport;
  47.     #[ORM\ManyToOne]
  48.     private ?ArticleDepartment $article = null;
  49.     #[ORM\ManyToOne(cascade: ["persist"])]
  50.     #[ORM\JoinColumn(nullable: true)]
  51.     #[Groups(['article:list'])]
  52.     private ?Attachment $qrAttachment = null;
  53.     #[ORM\Column(nullable: true)]
  54.     private ?int $sizeWidth = null;
  55.     #[ORM\Column(nullable: true)]
  56.     private ?int $sizeHeight = null;
  57.     public static function getList()
  58.     {
  59.         return [
  60.             self::CLIENT,
  61.             self::EMPLOYEE,
  62.             self::MEMBER,
  63.         ];
  64.     }
  65.     public function __construct()
  66.     {
  67.         $this->constructDate();
  68.         $this->cards = new ArrayCollection();
  69.         $this->currencySupport = new ArrayCollection();
  70.     }
  71.     public function __toString(): string
  72.     {
  73.         return $this->name;
  74.     }
  75.     public function getId(): ?int
  76.     {
  77.         return $this->id;
  78.     }
  79.     public function getName(): ?string
  80.     {
  81.         return $this->name;
  82.     }
  83.     public function setName(string $name): static
  84.     {
  85.         $this->name = $name;
  86.         return $this;
  87.     }
  88.     /**
  89.      * @return Collection<int, Card>
  90.      */
  91.     public function getCards(): Collection
  92.     {
  93.         return $this->cards;
  94.     }
  95.     public function addCard(Card $card): static
  96.     {
  97.         if (!$this->cards->contains($card)) {
  98.             $this->cards->add($card);
  99.             $card->setCardType($this);
  100.         }
  101.         return $this;
  102.     }
  103.     public function removeCard(Card $card): static
  104.     {
  105.         if ($this->cards->removeElement($card)) {
  106.             // set the owning side to null (unless already changed)
  107.             if ($card->getCardType() === $this) {
  108.                 $card->setCardType(null);
  109.             }
  110.         }
  111.         return $this;
  112.     }
  113.     public function getEstablishment(): ?Establishment
  114.     {
  115.         return $this->establishment;
  116.     }
  117.     public function setEstablishment(?Establishment $establishment): static
  118.     {
  119.         $this->establishment = $establishment;
  120.         return $this;
  121.     }
  122.     public function getTextPlaces(): array
  123.     {
  124.         return $this->textPlaces;
  125.     }
  126.     public function setTextPlaces(array $textPlaces): static
  127.     {
  128.         $this->textPlaces = $textPlaces;
  129.         return $this;
  130.     }
  131.     public function getType(): ?string
  132.     {
  133.         return $this->type;
  134.     }
  135.     public function setType(string $type): static
  136.     {
  137.         $this->type = $type;
  138.         return $this;
  139.     }
  140.     public function getFile(): ?Attachment
  141.     {
  142.         return $this->file;
  143.     }
  144.     public function setFile(?Attachment $file): static
  145.     {
  146.         $this->file = $file;
  147.         return $this;
  148.     }
  149.     public function getFileBack(): ?Attachment
  150.     {
  151.         return $this->fileBack;
  152.     }
  153.     public function setFileBack(?Attachment $fileBack): static
  154.     {
  155.         $this->fileBack = $fileBack;
  156.         return $this;
  157.     }
  158.     public function isWithBack(): ?bool
  159.     {
  160.         return $this->withBack;
  161.     }
  162.     public function setWithBack(bool $withBack): static
  163.     {
  164.         $this->withBack = $withBack;
  165.         return $this;
  166.     }
  167.     public function getIdentificators(): ?array
  168.     {
  169.         return $this->identificators;
  170.     }
  171.     public function setIdentificators(?array $identificators): static
  172.     {
  173.         $this->identificators = $identificators;
  174.         return $this;
  175.     }
  176.     public function isWithWallet(): ?bool
  177.     {
  178.         return $this->withWallet;
  179.     }
  180.     public function setWithWallet(bool $withWallet): static
  181.     {
  182.         $this->withWallet = $withWallet;
  183.         return $this;
  184.     }
  185.     /**
  186.      * @return Collection<int, Currency>
  187.      */
  188.     public function getCurrencySupport(): Collection
  189.     {
  190.         return $this->currencySupport;
  191.     }
  192.     public function addCurrencySupport(Currency $currencySupport): static
  193.     {
  194.         if (!$this->currencySupport->contains($currencySupport)) {
  195.             $this->currencySupport->add($currencySupport);
  196.         }
  197.         return $this;
  198.     }
  199.     public function removeCurrencySupport(Currency $currencySupport): static
  200.     {
  201.         $this->currencySupport->removeElement($currencySupport);
  202.         return $this;
  203.     }
  204.     public function getArticle(): ?ArticleDepartment
  205.     {
  206.         return $this->article;
  207.     }
  208.     public function setArticle(?ArticleDepartment $article): static
  209.     {
  210.         $this->article = $article;
  211.         return $this;
  212.     }
  213.     public function getQrAttachment(): ?Attachment
  214.     {
  215.         return $this->qrAttachment;
  216.     }
  217.     public function setQrAttachment(?Attachment $attachment): self
  218.     {
  219.         $this->qrAttachment = $attachment;
  220.         return $this;
  221.     }
  222.     public function getSizeWidth(): ?int
  223.     {
  224.         return $this->sizeWidth;
  225.     }
  226.     public function setSizeWidth(?int $sizeWidth): static
  227.     {
  228.         $this->sizeWidth = $sizeWidth;
  229.         return $this;
  230.     }
  231.     public function getSizeHeight(): ?int
  232.     {
  233.         return $this->sizeHeight;
  234.     }
  235.     public function setSizeHeight(?int $sizeHeight): static
  236.     {
  237.         $this->sizeHeight = $sizeHeight;
  238.         return $this;
  239.     }
  240. }