src/Entity/CustomProductField.php line 15

Open in your IDE?
  1. <?php
  2.     namespace App\Entity;
  3.     use App\Repository\CustomProductFieldRepository;
  4.     use Doctrine\ORM\Mapping as ORM;
  5.     use Symfony\Component\Validator\Constraints as Assert;
  6.     /**
  7.      * Champ (formulaire) pour un produit personnalisé
  8.      *
  9.      * @ORM\Entity(repositoryClass=CustomProductFieldRepository::class)
  10.      */
  11.     class CustomProductField
  12.     {
  13.         public const TYPE = ['string''text''boolean''date''file'];
  14.         /**
  15.          * @ORM\Id
  16.          * @ORM\GeneratedValue
  17.          * @ORM\Column(type="integer")
  18.          */
  19.         private ?int $id NULL;
  20.         /**
  21.          * Label pour le champ
  22.          *
  23.          * @ORM\Column(type="string", length=255)
  24.          *
  25.          * @Assert\Length(
  26.          *      min = 2,
  27.          *      max = 255,
  28.          *      minMessage = "Le label doit comporter au moins {{ limit }} caractères",
  29.          *      maxMessage = "Le label ne peut pas être plus long que {{ limit }} caractères"
  30.          * )
  31.          */
  32.         private ?string $label NULL;
  33.         /**
  34.          * Type de champs
  35.          *
  36.          * @ORM\Column(type="string", length=32)
  37.          *
  38.          * @Assert\Choice(choices=CustomProductField::TYPE, message="Sélectionnez un type valide")
  39.          */
  40.         private ?string $type NULL;
  41.         /**
  42.          * Position du champ dans le formulaire
  43.          *
  44.          * @ORM\Column(type="integer")
  45.          *
  46.          * @Assert\Positive
  47.          */
  48.         private int $position 99;
  49.         /**
  50.          * Si le champ est requis pour valider le formulaire
  51.          *
  52.          * @ORM\Column(type="boolean")
  53.          */
  54.         private ?bool $required NULL;
  55.         /**
  56.          * Produit auquel est rataché le champ (si rataché à un produit)
  57.          *
  58.          * @ORM\ManyToOne(targetEntity=CustomProduct::class, inversedBy="fields")
  59.          */
  60.         private ?CustomProduct $product NULL;
  61.         /**
  62.          * Template auquel est rataché le champ (si rataché à un template)
  63.          *
  64.          * @ORM\ManyToOne(targetEntity=CustomProductTemplate::class, inversedBy="fields")
  65.          */
  66.         private ?CustomProductTemplate $template NULL;
  67.         public function __clone()
  68.         {
  69.             if ($this->id) {
  70.                 $this->id       NULL;
  71.                 $this->template NULL;
  72.             }
  73.         }
  74.         public function getId(): ?int
  75.         {
  76.             return $this->id;
  77.         }
  78.         public function getLabel(): ?string
  79.         {
  80.             return $this->label;
  81.         }
  82.         public function setLabel(string $label): self
  83.         {
  84.             $this->label $label;
  85.             return $this;
  86.         }
  87.         public function getType(): ?string
  88.         {
  89.             return $this->type;
  90.         }
  91.         public function setType(string $type): self
  92.         {
  93.             $this->type $type;
  94.             return $this;
  95.         }
  96.         public function getPosition(): ?int
  97.         {
  98.             return $this->position;
  99.         }
  100.         public function setPosition(int $position): self
  101.         {
  102.             $this->position $position;
  103.             return $this;
  104.         }
  105.         public function isRequired(): ?bool
  106.         {
  107.             return $this->required;
  108.         }
  109.         public function setRequired(bool $required): self
  110.         {
  111.             $this->required $required;
  112.             return $this;
  113.         }
  114.         public function getProduct(): ?CustomProduct
  115.         {
  116.             return $this->product;
  117.         }
  118.         public function setProduct(?CustomProduct $product): self
  119.         {
  120.             $this->product $product;
  121.             return $this;
  122.         }
  123.         public function getTemplate(): ?CustomProductTemplate
  124.         {
  125.             return $this->template;
  126.         }
  127.         public function setTemplate(?CustomProductTemplate $template): self
  128.         {
  129.             $this->template $template;
  130.             return $this;
  131.         }
  132.     }