src/Entity/CompanyFormQuestion.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Greg0ire\Enum\Bridge\Symfony\Validator\Constraint\Enum as EnumAssert;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\CompanyFormQuestionRepository")
  10.  */
  11. class CompanyFormQuestion
  12. {
  13.     /**
  14.      * @ORM\Id()
  15.      * @ORM\GeneratedValue()
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @var string
  21.      *
  22.      * @ORM\Column(type="string", length=128, nullable=true)
  23.      * @Assert\Length(max="128")
  24.      */
  25.     private $label;
  26.     /**
  27.      * @var string
  28.      *
  29.      * @ORM\Column(type="string", length=64)
  30.      * @Assert\Length(max="64")
  31.      * @Assert\NotBlank()
  32.      * @EnumAssert(class="App\Enum\CompanyFormQuestionType")
  33.      */
  34.     private $type;
  35.     /**
  36.      * @var string
  37.      *
  38.      * @ORM\Column(type="string", length=128, nullable=true)
  39.      * @Assert\Length(max="128")
  40.      */
  41.     private $placeholder;
  42.     /**
  43.      * @var int
  44.      *
  45.      * @ORM\Column(type="integer")
  46.      * @Assert\NotBlank()
  47.      * @Assert\Type(type="integer")
  48.      */
  49.     private $position;
  50.     /**
  51.      * @var CompanyFormGroup
  52.      *
  53.      * @ORM\ManyToOne(targetEntity="App\Entity\CompanyFormGroup", inversedBy="formQuestions")
  54.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  55.      * @Assert\NotNull()
  56.      */
  57.     private $formGroup;
  58.     /**
  59.      * @var ArrayCollection
  60.      *
  61.      * @ORM\OneToMany(targetEntity="App\Entity\CompanyFormAnswer", mappedBy="formQuestion", cascade={"persist"})
  62.      */
  63.     private $formAnswers;
  64.     /**
  65.      * @var string
  66.      *
  67.      * @ORM\Column(type="string", length=128, nullable=true)
  68.      * @Assert\Length(max="128")
  69.      */
  70.     private $sliderLabelMin;
  71.     /**
  72.      * @var string
  73.      *
  74.      * @ORM\Column(type="string", length=128, nullable=true)
  75.      * @Assert\Length(max="128")
  76.      */
  77.     private $sliderLabelMax;
  78.     /**
  79.      * @var string
  80.      *
  81.      * @ORM\Column(type="integer", nullable=true)
  82.      * @Assert\Type(type="integer")
  83.      * @Assert\Range(min="2")
  84.      */
  85.     private $sliderNbGraduations;
  86.     /**
  87.      * CompanyFormQuestion constructor.
  88.      *
  89.      * @throws \Exception
  90.      */
  91.     public function __construct()
  92.     {
  93.         $this->formAnswers = new ArrayCollection();
  94.     }
  95.     public function __toString()
  96.     {
  97.         return $this->getFormGroup()->getFormPage()->getLabel().' > '.$this->getFormGroup()->getLabel().((null !== $this->getLabel()) ? ' > '.$this->getLabel() : '');
  98.     }
  99.     public function getId(): ?int
  100.     {
  101.         return $this->id;
  102.     }
  103.     public function getLabel(): ?string
  104.     {
  105.         return $this->label;
  106.     }
  107.     public function setLabel(?string $label): self
  108.     {
  109.         $this->label $label;
  110.         return $this;
  111.     }
  112.     public function getType(): ?string
  113.     {
  114.         return $this->type;
  115.     }
  116.     public function setType(string $type): self
  117.     {
  118.         $this->type $type;
  119.         return $this;
  120.     }
  121.     public function getPosition(): ?int
  122.     {
  123.         return $this->position;
  124.     }
  125.     public function setPosition(int $position): self
  126.     {
  127.         $this->position $position;
  128.         return $this;
  129.     }
  130.     public function getFormGroup(): ?CompanyFormGroup
  131.     {
  132.         return $this->formGroup;
  133.     }
  134.     public function setFormGroup(?CompanyFormGroup $formGroup): self
  135.     {
  136.         $this->formGroup $formGroup;
  137.         return $this;
  138.     }
  139.     /**
  140.      * @return Collection|CompanyFormAnswer[]
  141.      */
  142.     public function getFormAnswers(): Collection
  143.     {
  144.         return $this->formAnswers;
  145.     }
  146.     public function addFormAnswer(CompanyFormAnswer $formAnswer): self
  147.     {
  148.         if (!$this->formAnswers->contains($formAnswer)) {
  149.             $this->formAnswers[] = $formAnswer;
  150.             $formAnswer->setFormQuestion($this);
  151.         }
  152.         return $this;
  153.     }
  154.     public function removeFormAnswer(CompanyFormAnswer $formAnswer): self
  155.     {
  156.         if ($this->formAnswers->contains($formAnswer)) {
  157.             $this->formAnswers->removeElement($formAnswer);
  158.             // set the owning side to null (unless already changed)
  159.             if ($formAnswer->getFormQuestion() === $this) {
  160.                 $formAnswer->setFormQuestion(null);
  161.             }
  162.         }
  163.         return $this;
  164.     }
  165.     public function hasOtherFormAnswer(): bool
  166.     {
  167.         foreach ($this->getFormAnswers() as $formAnswer) {
  168.             /** @var CompanyFormAnswer $formAnswer */
  169.             if (true === $formAnswer->getOther()) {
  170.                 return true;
  171.             }
  172.         }
  173.         return false;
  174.     }
  175.     public function getSliderLabelMin(): ?string
  176.     {
  177.         return $this->sliderLabelMin;
  178.     }
  179.     public function setSliderLabelMin(?string $sliderLabelMin): self
  180.     {
  181.         $this->sliderLabelMin $sliderLabelMin;
  182.         return $this;
  183.     }
  184.     public function getSliderLabelMax(): ?string
  185.     {
  186.         return $this->sliderLabelMax;
  187.     }
  188.     public function setSliderLabelMax(?string $sliderLabelMax): self
  189.     {
  190.         $this->sliderLabelMax $sliderLabelMax;
  191.         return $this;
  192.     }
  193.     public function getSliderNbGraduations(): ?string
  194.     {
  195.         return $this->sliderNbGraduations;
  196.     }
  197.     public function setSliderNbGraduations(?string $sliderNbGraduations): self
  198.     {
  199.         $this->sliderNbGraduations $sliderNbGraduations;
  200.         return $this;
  201.     }
  202.     public function getPlaceholder(): ?string
  203.     {
  204.         return $this->placeholder;
  205.     }
  206.     public function setPlaceholder(?string $placeholder): self
  207.     {
  208.         $this->placeholder $placeholder;
  209.         return $this;
  210.     }
  211. }