<?php
namespace App\Entity;
use App\Repository\CustomProductFieldRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Champ (formulaire) pour un produit personnalisé
*
* @ORM\Entity(repositoryClass=CustomProductFieldRepository::class)
*/
class CustomProductField
{
public const TYPE = ['string', 'text', 'boolean', 'date', 'file'];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private ?int $id = NULL;
/**
* Label pour le champ
*
* @ORM\Column(type="string", length=255)
*
* @Assert\Length(
* min = 2,
* max = 255,
* minMessage = "Le label doit comporter au moins {{ limit }} caractères",
* maxMessage = "Le label ne peut pas être plus long que {{ limit }} caractères"
* )
*/
private ?string $label = NULL;
/**
* Type de champs
*
* @ORM\Column(type="string", length=32)
*
* @Assert\Choice(choices=CustomProductField::TYPE, message="Sélectionnez un type valide")
*/
private ?string $type = NULL;
/**
* Position du champ dans le formulaire
*
* @ORM\Column(type="integer")
*
* @Assert\Positive
*/
private int $position = 99;
/**
* Si le champ est requis pour valider le formulaire
*
* @ORM\Column(type="boolean")
*/
private ?bool $required = NULL;
/**
* Produit auquel est rataché le champ (si rataché à un produit)
*
* @ORM\ManyToOne(targetEntity=CustomProduct::class, inversedBy="fields")
*/
private ?CustomProduct $product = NULL;
/**
* Template auquel est rataché le champ (si rataché à un template)
*
* @ORM\ManyToOne(targetEntity=CustomProductTemplate::class, inversedBy="fields")
*/
private ?CustomProductTemplate $template = NULL;
public function __clone()
{
if ($this->id) {
$this->id = NULL;
$this->template = NULL;
}
}
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
public function isRequired(): ?bool
{
return $this->required;
}
public function setRequired(bool $required): self
{
$this->required = $required;
return $this;
}
public function getProduct(): ?CustomProduct
{
return $this->product;
}
public function setProduct(?CustomProduct $product): self
{
$this->product = $product;
return $this;
}
public function getTemplate(): ?CustomProductTemplate
{
return $this->template;
}
public function setTemplate(?CustomProductTemplate $template): self
{
$this->template = $template;
return $this;
}
}