src/Entity/PollQuestion.php line 13

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Repository\PollQuestionRepository;
  8. #[ORM\Entity(repositoryClassPollQuestionRepository::class)]
  9. #[ORM\Table(name'poll_questions')]
  10. class PollQuestion
  11. {
  12.     public const TYPE_NUMBER 'number';
  13.     public const TYPE_TEXT 'text';
  14.     public const TYPE_OPTION 'option';
  15.     public const TYPES = [
  16.         self::TYPE_NUMBER,
  17.         self::TYPE_TEXT,
  18.         self::TYPE_OPTION,
  19.     ];
  20.     public const DEFAULT_EVALUATION_PROMPT_TEMPLATE "From the following {{OPTIONS}}, return the number of the option that is closest to the answer given by the user if the question was: {{QUESTION}}.  If the user's answer is not close to any of the options -1 should be your response";
  21.     #[ORM\Id]
  22.     #[ORM\GeneratedValue]
  23.     #[ORM\Column(type'integer')]
  24.     private ?int $id null;
  25.     #[ORM\Column(type'string'length255)]
  26.     private ?string $question null;
  27.     #[ORM\Column(type'string'length20)]
  28.     private ?string $type null;
  29.     #[ORM\Column(type'text'nullabletrue)]
  30.     private ?string $evaluationPromptTemplate null;
  31.     #[ORM\ManyToOne(targetEntity'Poll'inversedBy'questions')]
  32.     private ?Poll $poll null;
  33.     #[ORM\OneToMany(mappedBy'question'targetEntity'QuestionOption'cascade: ['persist''remove'], orphanRemovaltrue)]
  34.     private Collection $options;
  35.     public function __construct()
  36.     {
  37.         $this->options = new ArrayCollection();
  38.     }
  39.     public function __toString(): string
  40.     {
  41.         return $this->question;
  42.     }
  43.     public function getId(): ?int
  44.     {
  45.         return $this->id;
  46.     }
  47.     public function getQuestion(): ?string
  48.     {
  49.         return $this->question;
  50.     }
  51.     public function setQuestion(?string $question): self
  52.     {
  53.         $this->question $question;
  54.         return $this;
  55.     }
  56.     public function getType(): ?string
  57.     {
  58.         return $this->type;
  59.     }
  60.     public function setType(?string $type): self
  61.     {
  62.         if (!\in_array($type, [self::TYPE_NUMBERself::TYPE_TEXTself::TYPE_OPTION], true)) {
  63.             throw new \InvalidArgumentException('Invalid type.');
  64.         }
  65.         $this->type $type;
  66.         return $this;
  67.     }
  68.     public function getPoll(): ?Poll
  69.     {
  70.         return $this->poll;
  71.     }
  72.     public function setPoll(?Poll $poll): self
  73.     {
  74.         $this->poll $poll;
  75.         return $this;
  76.     }
  77.     public function getOptions(): Collection
  78.     {
  79.         return $this->options;
  80.     }
  81.     public function setOptions(Collection $options): self
  82.     {
  83.         $this->options $options;
  84.         return $this;
  85.     }
  86.     public function addOption(QuestionOption $option): self
  87.     {
  88.         $this->options->add($option);
  89.         return $this;
  90.     }
  91.     public function removeOption(QuestionOption $option): self
  92.     {
  93.         $this->options->removeElement($option);
  94.         return $this;
  95.     }
  96.     public function getEvaluationPromptTemplate(): ?string
  97.     {
  98.         return $this->evaluationPromptTemplate;
  99.     }
  100.     public function setEvaluationPromptTemplate(?string $evaluationPromptTemplate): self
  101.     {
  102.         $this->evaluationPromptTemplate $evaluationPromptTemplate;
  103.         return $this;
  104.     }
  105. }