<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Greg0ire\Enum\Bridge\Symfony\Validator\Constraint\Enum as EnumAssert;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\CompanyFormQuestionRepository")
*/
class CompanyFormQuestion
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var string
*
* @ORM\Column(type="string", length=128, nullable=true)
* @Assert\Length(max="128")
*/
private $label;
/**
* @var string
*
* @ORM\Column(type="string", length=64)
* @Assert\Length(max="64")
* @Assert\NotBlank()
* @EnumAssert(class="App\Enum\CompanyFormQuestionType")
*/
private $type;
/**
* @var string
*
* @ORM\Column(type="string", length=128, nullable=true)
* @Assert\Length(max="128")
*/
private $placeholder;
/**
* @var int
*
* @ORM\Column(type="integer")
* @Assert\NotBlank()
* @Assert\Type(type="integer")
*/
private $position;
/**
* @var CompanyFormGroup
*
* @ORM\ManyToOne(targetEntity="App\Entity\CompanyFormGroup", inversedBy="formQuestions")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Assert\NotNull()
*/
private $formGroup;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="App\Entity\CompanyFormAnswer", mappedBy="formQuestion", cascade={"persist"})
*/
private $formAnswers;
/**
* @var string
*
* @ORM\Column(type="string", length=128, nullable=true)
* @Assert\Length(max="128")
*/
private $sliderLabelMin;
/**
* @var string
*
* @ORM\Column(type="string", length=128, nullable=true)
* @Assert\Length(max="128")
*/
private $sliderLabelMax;
/**
* @var string
*
* @ORM\Column(type="integer", nullable=true)
* @Assert\Type(type="integer")
* @Assert\Range(min="2")
*/
private $sliderNbGraduations;
/**
* CompanyFormQuestion constructor.
*
* @throws \Exception
*/
public function __construct()
{
$this->formAnswers = new ArrayCollection();
}
public function __toString()
{
return $this->getFormGroup()->getFormPage()->getLabel().' > '.$this->getFormGroup()->getLabel().((null !== $this->getLabel()) ? ' > '.$this->getLabel() : '');
}
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 getFormGroup(): ?CompanyFormGroup
{
return $this->formGroup;
}
public function setFormGroup(?CompanyFormGroup $formGroup): self
{
$this->formGroup = $formGroup;
return $this;
}
/**
* @return Collection|CompanyFormAnswer[]
*/
public function getFormAnswers(): Collection
{
return $this->formAnswers;
}
public function addFormAnswer(CompanyFormAnswer $formAnswer): self
{
if (!$this->formAnswers->contains($formAnswer)) {
$this->formAnswers[] = $formAnswer;
$formAnswer->setFormQuestion($this);
}
return $this;
}
public function removeFormAnswer(CompanyFormAnswer $formAnswer): self
{
if ($this->formAnswers->contains($formAnswer)) {
$this->formAnswers->removeElement($formAnswer);
// set the owning side to null (unless already changed)
if ($formAnswer->getFormQuestion() === $this) {
$formAnswer->setFormQuestion(null);
}
}
return $this;
}
public function hasOtherFormAnswer(): bool
{
foreach ($this->getFormAnswers() as $formAnswer) {
/** @var CompanyFormAnswer $formAnswer */
if (true === $formAnswer->getOther()) {
return true;
}
}
return false;
}
public function getSliderLabelMin(): ?string
{
return $this->sliderLabelMin;
}
public function setSliderLabelMin(?string $sliderLabelMin): self
{
$this->sliderLabelMin = $sliderLabelMin;
return $this;
}
public function getSliderLabelMax(): ?string
{
return $this->sliderLabelMax;
}
public function setSliderLabelMax(?string $sliderLabelMax): self
{
$this->sliderLabelMax = $sliderLabelMax;
return $this;
}
public function getSliderNbGraduations(): ?string
{
return $this->sliderNbGraduations;
}
public function setSliderNbGraduations(?string $sliderNbGraduations): self
{
$this->sliderNbGraduations = $sliderNbGraduations;
return $this;
}
public function getPlaceholder(): ?string
{
return $this->placeholder;
}
public function setPlaceholder(?string $placeholder): self
{
$this->placeholder = $placeholder;
return $this;
}
}