<?php
namespace App\Entity;
use App\Entity\Enum\SectionMetaType;
use App\Entity\Traits\Sortable;
use App\Repository\SectionMetaRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
use Symfony\Component\Validator\Constraints\LessThanOrEqual;
#[ORM\Entity(repositoryClass: SectionMetaRepository::class)]
class SectionMeta
{
//TODO: amélioration - rajouter un champ isSaved pour savoir si c'est une donnée temporaire
use Sortable;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 30, enumType: SectionMetaType::class)]
private $type;
#[ORM\Column(type: 'string', length: 100, nullable: true)]
private $slug;
#[ORM\Column(type: 'string', length: 100)]
private $name;
#[ORM\Column(type: 'json', nullable: true)]
private $choices = [];
#[ORM\Column(type: 'boolean')]
private $isRequired;
#[ORM\Column(type: 'boolean')]
private $isMinor;
#[ORM\Column(type: 'boolean')]
private $isAdult;
#[ORM\Column(type: 'text', nullable: true)]
private $comment;
#[ORM\Column(type: 'string', length: 150, nullable: true)]
private $help;
#[ORM\Column(type: 'smallint', nullable: true)]
#[GreaterThanOrEqual(propertyPath: 'lengthMin', message: "Le maximum doit être supérieur au minimum")]
private $lengthMax;
#[ORM\Column(type: 'smallint', nullable: true)]
#[LessThanOrEqual(propertyPath: 'lengthMax', message: "Le minimum doit être inférieur au maximum")]
private $lengthMin;
#[ORM\Column(type: 'boolean')]
private $isDisplayedRegistration;
#[ORM\Column(type: 'boolean')]
private $isDisplayedBackoffice;
#[ORM\ManyToOne(targetEntity: Section::class, inversedBy: 'sectionMetas')]
#[ORM\JoinColumn(nullable: false)]
private $section;
#[ORM\OneToMany(mappedBy: 'sectionMeta', targetEntity: SectionPersonMeta::class)]
private $sectionPersonMetas;
public function __construct()
{
$this->sectionPersonMetas = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getType(): ?Enum\SectionMetaType
{
return $this->type;
}
public function setType(Enum\SectionMetaType $type): self
{
$this->type = $type;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getChoices(): ?array
{
return $this->choices;
}
public function setChoices(?array $choices): self
{
$this->choices = $choices;
return $this;
}
public function getIsRequired(): ?bool
{
return $this->isRequired;
}
public function setIsRequired(bool $isRequired): self
{
$this->isRequired = $isRequired;
return $this;
}
public function getIsMinor(): ?bool
{
return $this->isMinor;
}
public function setIsMinor(bool $isMinor): self
{
$this->isMinor = $isMinor;
return $this;
}
public function getIsAdult(): ?bool
{
return $this->isAdult;
}
public function setIsAdult(bool $isAdult): self
{
$this->isAdult = $isAdult;
return $this;
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): self
{
$this->comment = $comment;
return $this;
}
public function getHelp(): ?string
{
return $this->help;
}
public function setHelp(?string $help): self
{
$this->help = $help;
return $this;
}
public function getLengthMax(): ?int
{
return $this->lengthMax;
}
public function setLengthMax(?int $lengthMax): self
{
$this->lengthMax = $lengthMax;
return $this;
}
public function getLengthMin(): ?int
{
return $this->lengthMin;
}
public function setLengthMin(?int $lengthMin): self
{
$this->lengthMin = $lengthMin;
return $this;
}
public function getIsDisplayedRegistration(): ?bool
{
return $this->isDisplayedRegistration;
}
public function setIsDisplayedRegistration(bool $isDisplayedRegistration): self
{
$this->isDisplayedRegistration = $isDisplayedRegistration;
return $this;
}
public function getIsDisplayedBackoffice(): ?bool
{
return $this->isDisplayedBackoffice;
}
public function setIsDisplayedBackoffice(bool $isDisplayedBackoffice): self
{
$this->isDisplayedBackoffice = $isDisplayedBackoffice;
return $this;
}
public function getSection(): ?Section
{
return $this->section;
}
public function setSection(?Section $section): self
{
$this->section = $section;
return $this;
}
/**
* @return Collection<int, SectionPersonMeta>
*/
public function getSectionPersonMetas(): Collection
{
return $this->sectionPersonMetas;
}
public function addSectionPersonMeta(SectionPersonMeta $sectionPersonMeta): self
{
if (!$this->sectionPersonMetas->contains($sectionPersonMeta)) {
$this->sectionPersonMetas[] = $sectionPersonMeta;
$sectionPersonMeta->setSectionMeta($this);
}
return $this;
}
public function removeSectionPersonMeta(SectionPersonMeta $sectionPersonMeta): self
{
if ($this->sectionPersonMetas->removeElement($sectionPersonMeta)) {
// set the owning side to null (unless already changed)
if ($sectionPersonMeta->getSectionMeta() === $this) {
$sectionPersonMeta->setSectionMeta(null);
}
}
return $this;
}
}