<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\QuizQuestionRepository")
*/
class QuizQuestion
{
//Keeping all of these to be consistent with the Form entity
//But limiting to TEXT_FIELD, RADIO_BUTTONS (multiple choice), and TRUE_FALSE for now
const TEXT_FIELD = 1;
const TEXT_AREA = 2;
const DROP_DOWN = 3;
const RADIO_BUTTONS = 4; //aka multiple choice
const CHECK_BOXES = 5;
const IMAGE = 6;
const FILE = 7;
const TRUE_FALSE = 8;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="bigint")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="text")
*/
private $body;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Quiz", inversedBy="quizQuestions")
* @ORM\JoinColumn(name="quiz_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $quiz;
/**
* @ORM\OneToMany(targetEntity="App\Entity\QuizQuestionOption", mappedBy="quizQuestion", orphanRemoval=true, cascade={"persist", "remove"}, fetch="EAGER")
* @ORM\OrderBy({"sort" = "ASC"})
*/
private $quizQuestionOptions;
/**
* @ORM\OneToMany(targetEntity="App\Entity\QuizAnswer", mappedBy="quizQuestion", orphanRemoval=true, cascade={"persist", "remove"}, fetch="EAGER")
*/
private $quizAnswers;
/**
* @ORM\Column(type="integer")
*/
private $sort;
/**
* @ORM\Column(type="integer")
*/
private $type;
public function __construct ()
{
$this->title = "";
$this->body = "";
$this->quizQuestionOptions = new ArrayCollection();
$this->quizAnswers = new ArrayCollection();
$this->sort = 0;
$this->type = 0;
}
public function getId()
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle (string $title = null): ?self
{
$this->title = $title ? $title : "";
return $this;
}
public function getBody(): ?string
{
return $this->body;
}
public function setBody (string $body = null): ?self
{
$this->body = $body ? $body : "";
return $this;
}
public function getQuiz(): ?Quiz
{
return $this->quiz;
}
public function setQuiz(?Quiz $quiz = null): self
{
$this->quiz = $quiz;
return $this;
}
/**
* @return Collection|QuizQuestionOption[]
*/
public function getQuizQuestionOptions(): Collection
{
return $this->quizQuestionOptions;
}
public function addQuizQuestionOption(QuizQuestionOption $quizQuestionOption): self
{
if (!$this->quizQuestionOptions->contains($quizQuestionOption)) {
$this->quizQuestionOptions[] = $quizQuestionOption;
$quizQuestionOption->setQuizQuestion($this);
}
return $this;
}
public function removeQuizQuestionOption(QuizQuestionOption $quizQuestionOption): self
{
if ($this->quizQuestionOptions->contains($quizQuestionOption)) {
$this->quizQuestionOptions->removeElement($quizQuestionOption);
// set the owning side to null (unless already changed)
if ($quizQuestionOption->getQuizQuestion() === $this) {
$quizQuestionOption->setQuizQuestion(null);
}
}
return $this;
}
/**
* @return Collection|QuizAnswer[]
*/
public function getQuizAnswers(): Collection
{
return $this->quizAnswers;
}
public function addQuizAnswer(QuizAnswer $quizAnswer): self
{
if (!$this->quizAnswers->contains($quizAnswer)) {
$this->quizAnswers[] = $quizAnswer;
$quizAnswer->setQuizQuestion($this);
}
return $this;
}
public function removeQuizAnswer(QuizAnswer $quizAnswer): self
{
if ($this->quizAnswers->contains($quizAnswer)) {
$this->quizAnswers->removeElement($quizAnswer);
// set the owning side to null (unless already changed)
if ($quizAnswer->getQuizQuestion() === $this) {
$quizAnswer->setQuizQuestion(null);
}
}
return $this;
}
public function countResponses() {
return count($this->quizQuestionOptions);
}
public function getSort(): int
{
return $this->sort;
}
public function setSort(int $sort): self
{
$this->sort = $sort;
return $this;
}
public function getType(): int
{
return $this->type;
}
public function setType(int $type): self
{
$this->type = $type;
return $this;
}
public function __toString ()
{
return $this->getTitle();
}
}