src/Entity/QuizQuestion.php line 12

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. /**
  7.  * @ORM\Entity(repositoryClass="App\Repository\QuizQuestionRepository")
  8.  */
  9. class QuizQuestion
  10. {
  11.     //Keeping all of these to be consistent with the Form entity
  12.     //But limiting to TEXT_FIELD, RADIO_BUTTONS (multiple choice), and TRUE_FALSE for now
  13.     const TEXT_FIELD 1;
  14.     const TEXT_AREA 2;
  15.     const DROP_DOWN 3;
  16.     const RADIO_BUTTONS 4//aka multiple choice
  17.     const CHECK_BOXES 5;
  18.     const IMAGE 6;
  19.     const FILE 7;
  20.     const TRUE_FALSE 8;
  21.     
  22.     /**
  23.      * @ORM\Id()
  24.      * @ORM\GeneratedValue()
  25.      * @ORM\Column(type="bigint")
  26.      */
  27.     private $id;
  28.     
  29.     /**
  30.      * @ORM\Column(type="string", length=255)
  31.      */
  32.     private $title;
  33.     /**
  34.      * @ORM\Column(type="text")
  35.      */
  36.     private $body;
  37.     
  38.     /**
  39.      * @ORM\ManyToOne(targetEntity="App\Entity\Quiz", inversedBy="quizQuestions")
  40.      * @ORM\JoinColumn(name="quiz_id", referencedColumnName="id", onDelete="SET NULL")
  41.      */
  42.     private $quiz;
  43.     
  44.     /**
  45.      * @ORM\OneToMany(targetEntity="App\Entity\QuizQuestionOption", mappedBy="quizQuestion", orphanRemoval=true, cascade={"persist", "remove"}, fetch="EAGER")
  46.      * @ORM\OrderBy({"sort" = "ASC"})
  47.      */
  48.     private $quizQuestionOptions;
  49.     /**
  50.      * @ORM\OneToMany(targetEntity="App\Entity\QuizAnswer", mappedBy="quizQuestion", orphanRemoval=true, cascade={"persist", "remove"}, fetch="EAGER")
  51.      */
  52.     private $quizAnswers;
  53.     /**
  54.      * @ORM\Column(type="integer")
  55.      */
  56.     private $sort;
  57.     /**
  58.      * @ORM\Column(type="integer")
  59.      */
  60.     private $type;
  61.     
  62.     
  63.     public function __construct ()
  64.     {
  65.         $this->title "";
  66.         $this->body "";
  67.         $this->quizQuestionOptions = new ArrayCollection();
  68.         $this->quizAnswers = new ArrayCollection();
  69.         $this->sort 0;
  70.         $this->type 0;
  71.     }
  72.     public function getId()
  73.     {
  74.         return $this->id;
  75.     }
  76.     
  77.     public function getTitle(): ?string
  78.     {
  79.         return $this->title;
  80.     }
  81.     
  82.     public function setTitle (string $title null): ?self
  83.     {
  84.         $this->title $title $title "";
  85.         return $this;
  86.     }
  87.     
  88.     public function getBody(): ?string
  89.     {
  90.         return $this->body;
  91.     }
  92.     
  93.     public function setBody (string $body null): ?self
  94.     {
  95.         $this->body $body $body "";
  96.         return $this;
  97.     }
  98.     
  99.     public function getQuiz(): ?Quiz
  100.     {
  101.         return $this->quiz;
  102.     }
  103.     
  104.     public function setQuiz(?Quiz $quiz null): self
  105.     {
  106.         $this->quiz $quiz;
  107.         return $this;
  108.     }
  109.     
  110.     
  111.     /**
  112.      * @return Collection|QuizQuestionOption[]
  113.      */
  114.     public function getQuizQuestionOptions(): Collection
  115.     {
  116.         return $this->quizQuestionOptions;
  117.     }
  118.     
  119.     public function addQuizQuestionOption(QuizQuestionOption $quizQuestionOption): self
  120.     {
  121.         if (!$this->quizQuestionOptions->contains($quizQuestionOption)) {
  122.             $this->quizQuestionOptions[] = $quizQuestionOption;
  123.             $quizQuestionOption->setQuizQuestion($this);
  124.         }
  125.         
  126.         return $this;
  127.     }
  128.     
  129.     public function removeQuizQuestionOption(QuizQuestionOption $quizQuestionOption): self
  130.     {
  131.         if ($this->quizQuestionOptions->contains($quizQuestionOption)) {
  132.             $this->quizQuestionOptions->removeElement($quizQuestionOption);
  133.             // set the owning side to null (unless already changed)
  134.             if ($quizQuestionOption->getQuizQuestion() === $this) {
  135.                 $quizQuestionOption->setQuizQuestion(null);
  136.             }
  137.         }
  138.         
  139.         return $this;
  140.     }
  141.     
  142.     /**
  143.      * @return Collection|QuizAnswer[]
  144.      */
  145.     public function getQuizAnswers(): Collection
  146.     {
  147.         return $this->quizAnswers;
  148.     }
  149.     
  150.     public function addQuizAnswer(QuizAnswer $quizAnswer): self
  151.     {
  152.         if (!$this->quizAnswers->contains($quizAnswer)) {
  153.             $this->quizAnswers[] = $quizAnswer;
  154.             $quizAnswer->setQuizQuestion($this);
  155.         }
  156.         
  157.         return $this;
  158.     }
  159.     
  160.     public function removeQuizAnswer(QuizAnswer $quizAnswer): self
  161.     {
  162.         if ($this->quizAnswers->contains($quizAnswer)) {
  163.             $this->quizAnswers->removeElement($quizAnswer);
  164.             // set the owning side to null (unless already changed)
  165.             if ($quizAnswer->getQuizQuestion() === $this) {
  166.                 $quizAnswer->setQuizQuestion(null);
  167.             }
  168.         }
  169.         
  170.         return $this;
  171.     }
  172.     public function countResponses() {
  173.         return count($this->quizQuestionOptions);
  174.     }
  175.     public function getSort(): int
  176.     {
  177.         return $this->sort;
  178.     }
  179.     
  180.     public function setSort(int $sort): self
  181.     {
  182.         $this->sort $sort;
  183.         return $this;
  184.     }
  185.     public function getType(): int
  186.     {
  187.         return $this->type;
  188.     }
  189.     
  190.     public function setType(int $type): self
  191.     {
  192.         $this->type $type;
  193.         return $this;
  194.     }
  195.     
  196.     
  197.     public function __toString ()
  198.     {
  199.         return $this->getTitle();
  200.     }
  201.     
  202. }