src/Entity/Survey/Question.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Survey;
  3. use App\Entity\PrimaryIdTrait;
  4. use App\Repository\Survey\QuestionRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Timestampable\Traits\TimestampableEntity;
  9. use Symfony\Component\Cache\Adapter\FilesystemAdapter;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. #[ORM\Entity(repositoryClassQuestionRepository::class)]
  12. class Question
  13. {
  14.     public const TEXT 0;
  15.     public const TEXTAREA 1;
  16.     public const RADIOBUTTON 2;
  17.     public const CHECKBOX 3;
  18.     public const SELECT 4;
  19.     public const CHECKBOXONE 5;
  20.     public const TYPE = [
  21.         self::TEXT => 'question.type.text',
  22.         self::TEXTAREA => 'question.type.textarea',
  23.         self::RADIOBUTTON => 'question.type.radiobutton',
  24.         self::CHECKBOX => 'question.type.checkbox',
  25.         self::SELECT => 'question.type.select',
  26.         self::CHECKBOXONE => 'question.type.checkboxone'
  27.     ];
  28.     public const REQUIRING_ANSWER = [
  29.         self::TEXT => 0,
  30.         self::TEXTAREA => 0,
  31.         self::RADIOBUTTON => 1,
  32.         self::CHECKBOX => 1,
  33.         self::SELECT => 1,
  34.         self::CHECKBOXONE => 0
  35.     ];
  36.     public const NO 0;
  37.     public const YES 1;
  38.     public const REQUIRED = [
  39.         self::NO => 'question.required.no',
  40.         self::YES => 'question.required.yes'
  41.     ];
  42.     use PrimaryIdTrait;
  43.     use TimestampableEntity;
  44.     #[ORM\Column(type'string')]
  45.     #[Groups(['survey''childrenQuestions'])]
  46.     private string $wording;
  47.     #[ORM\Column(type'integer')]
  48.     #[Groups(['survey''childrenQuestions'])]
  49.     private int $type;
  50.     #[ORM\Column(type'boolean')]
  51.     #[Groups(['survey''childrenQuestions'])]
  52.     private bool $required;
  53.     #[ORM\OneToMany(targetEntity'App\Entity\Survey\SurveyQuestion'mappedBy'question'cascade: ['remove'])]
  54.     public $surveyQuestion;
  55.     #[ORM\OneToMany(targetEntity'App\Entity\Survey\QuestionAnswer'mappedBy'question'cascade: ['persist''remove'], orphanRemovaltrue)]
  56.     #[ORM\OrderBy(['sort' => 'ASC'])]
  57.     #[Groups(['survey''childrenQuestions'])]
  58.     public $questionAnswer;
  59.     #[ORM\OneToMany(targetEntity'App\Entity\Survey\SurveyResultData'mappedBy'question'cascade: ['remove'])]
  60.     public $surveyResultData;
  61.     #[ORM\OneToMany(targetEntity'App\Entity\Survey\AnswerQuestion'mappedBy'question'cascade: ['remove'])]
  62.     public $answerQuestion;
  63.     public function __construct()
  64.     {
  65.         $this->surveyQuestion = new ArrayCollection();
  66.         $this->questionAnswer = new ArrayCollection();
  67.         $this->surveyResultData = new ArrayCollection();
  68.         $this->answerQuestion = new ArrayCollection();
  69.     }
  70.     public function getWording(): string
  71.     {
  72.         return $this->wording;
  73.     }
  74.     public function setWording(string $wording): void
  75.     {
  76.         $this->wording $wording;
  77.     }
  78.     public function getType(): int
  79.     {
  80.         return $this->type;
  81.     }
  82.     public function setType(int $type): void
  83.     {
  84.         $this->type $type;
  85.     }
  86.     public function getRequired(): bool
  87.     {
  88.         return $this->required;
  89.     }
  90.     public function setRequired(bool $required): void
  91.     {
  92.         $this->required $required;
  93.     }
  94.     /**
  95.      * @return Collection|SurveyQuestion[]
  96.      */
  97.     public function getSurveyQuestion(): Collection
  98.     {
  99.         return $this->surveyQuestion;
  100.     }
  101.     /**
  102.      * @return Collection|QuestionAnswer[]
  103.      */
  104.     public function getQuestionAnswer(): Collection
  105.     {
  106.         return $this->questionAnswer;
  107.     }
  108.     public function addQuestionAnswer(QuestionAnswer $questionAnswer): void
  109.     {
  110.         $questionAnswer->setQuestion($this);
  111.         $this->questionAnswer->add($questionAnswer);
  112.     }
  113.     public function removeQuestionAnswer(QuestionAnswer $questionAnswer): void
  114.     {
  115.         if ($this->questionAnswer->contains($questionAnswer)) {
  116.             $this->questionAnswer->removeElement($questionAnswer);
  117.         }
  118.     }
  119.     /**
  120.      * @return Collection|SurveyResultData[]
  121.      */
  122.     public function getSurveyResultData(): Collection
  123.     {
  124.         return $this->surveyResultData;
  125.     }
  126.     /**
  127.      * @return Collection|AnswerQuestion[]
  128.      */
  129.     public function getAnswerQuestion(): Collection
  130.     {
  131.         return $this->answerQuestion;
  132.     }
  133. }