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. /**
  68. * Commande auquel est rataché le champ (si rataché à une commande, et n'est pas rataché a un produit ni un template) sert à l'édition des champs de la commande lorsque le produit ou le template et deleted
  69. *
  70. * @ORM\ManyToOne(targetEntity=CustomProductOrder::class, inversedBy="fields")
  71. */
  72. private ?CustomProductOrder $order = NULL;
  73. public function __clone()
  74. {
  75. if ($this->id) {
  76. $this->id = NULL;
  77. $this->template = NULL;
  78. }
  79. }
  80. public function getId(): ?int
  81. {
  82. return $this->id;
  83. }
  84. public function getLabel(): ?string
  85. {
  86. return $this->label;
  87. }
  88. public function setLabel(string $label): self
  89. {
  90. $this->label = $label;
  91. return $this;
  92. }
  93. public function getType(): ?string
  94. {
  95. return $this->type;
  96. }
  97. public function setType(string $type): self
  98. {
  99. $this->type = $type;
  100. return $this;
  101. }
  102. public function getPosition(): ?int
  103. {
  104. return $this->position;
  105. }
  106. public function setPosition(int $position): self
  107. {
  108. $this->position = $position;
  109. return $this;
  110. }
  111. public function isRequired(): ?bool
  112. {
  113. return $this->required;
  114. }
  115. public function setRequired(bool $required): self
  116. {
  117. $this->required = $required;
  118. return $this;
  119. }
  120. public function getProduct(): ?CustomProduct
  121. {
  122. return $this->product;
  123. }
  124. public function setProduct(?CustomProduct $product): self
  125. {
  126. $this->product = $product;
  127. return $this;
  128. }
  129. public function getTemplate(): ?CustomProductTemplate
  130. {
  131. return $this->template;
  132. }
  133. public function setTemplate(?CustomProductTemplate $template): self
  134. {
  135. $this->template = $template;
  136. return $this;
  137. }
  138. public function getOrder(): ?CustomProductOrder
  139. {
  140. return $this->order;
  141. }
  142. public function setOrder(?CustomProductOrder $order): self
  143. {
  144. $this->order = $order;
  145. return $this;
  146. }
  147. }