src/Entity/Quiz.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\QuizRepository;
  4. use DateTimeInterface;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use JMS\Serializer\Annotation as Serializer;
  9. use JMS\Serializer\Annotation\Expose;
  10. use JMS\Serializer\Annotation\Groups;
  11. /**
  12. * @ORM\Entity(repositoryClass=QuizRepository::class)
  13. *
  14. * @Serializer\ExclusionPolicy("ALL")
  15. */
  16. class Quiz
  17. {
  18. const STATUS_CLOSED = 0; // Quiz is not viewable by user
  19. const STATUS_OPENED = 1; // Quiz is answerable ( = writable)
  20. const STATUS_FINISHED = 2; // Quiz is viewable ( = read only)
  21. const STATUS = [
  22. 'fermé' => Quiz::STATUS_CLOSED,
  23. 'ouvert' => Quiz::STATUS_OPENED,
  24. 'terminé' => Quiz::STATUS_FINISHED,
  25. ];
  26. const RANDOM = [
  27. 'non' => FALSE,
  28. 'oui' => TRUE,
  29. ];
  30. /**
  31. * @ORM\Id
  32. * @ORM\GeneratedValue
  33. * @ORM\Column(type="integer")
  34. *
  35. * @Expose()
  36. * @Groups({ "quiz" })
  37. */
  38. private $id;
  39. /**
  40. * @ORM\Column(type="string", length=255)
  41. *
  42. * @Expose()
  43. * @Groups({ "quiz" })
  44. */
  45. private ?string $name;
  46. /**
  47. * @ORM\Column(type="text", nullable=true)
  48. *
  49. * @Expose()
  50. * @Groups({ "quiz" })
  51. */
  52. private ?string $description;
  53. /**
  54. * @ORM\Column(type="boolean", nullable=true)
  55. *
  56. * @Expose()
  57. * @Groups({ "quiz" })
  58. */
  59. private ?bool $isRandom;
  60. /**
  61. * @ORM\Column(type="integer", options={"default":0})
  62. *
  63. * @Expose()
  64. * @Groups({ "quiz" })
  65. */
  66. private int $status = 0;
  67. /**
  68. * @ORM\Column(type="datetime", nullable=true)
  69. *
  70. * @Expose()
  71. * @Groups({ "quiz" })
  72. */
  73. private ?DateTimeInterface $dateStart;
  74. /**
  75. * @ORM\Column(type="datetime", nullable=true)
  76. *
  77. * @Expose()
  78. * @Groups({ "quiz" })
  79. */
  80. private ?DateTimeInterface $dateEnd;
  81. /**
  82. * @ORM\OneToMany(targetEntity=QuizQuestion::class, mappedBy="quiz", cascade={"remove", "persist"})
  83. * @ORM\OrderBy({"orderIndex" = "ASC"})
  84. */
  85. private $quizQuestions;
  86. public function __construct()
  87. {
  88. $this->quizQuestions = new ArrayCollection();
  89. }
  90. /**
  91. * @Serializer\VirtualProperty()
  92. * @Serializer\SerializedName("questions_nbr")
  93. *
  94. * @Expose
  95. * @Groups({ "quiz" })
  96. */
  97. public function getQuestionNumber(): int
  98. {
  99. return count($this->getQuizQuestions());
  100. }
  101. public function getId(): ?int
  102. {
  103. return $this->id;
  104. }
  105. public function getName(): ?string
  106. {
  107. return $this->name;
  108. }
  109. public function setName( string $name ): Quiz
  110. {
  111. $this->name = $name;
  112. return $this;
  113. }
  114. public function getDescription(): ?string
  115. {
  116. return $this->description;
  117. }
  118. public function setDescription( ?string $description ): Quiz
  119. {
  120. $this->description = $description;
  121. return $this;
  122. }
  123. public function getIsRandom(): ?bool
  124. {
  125. return $this->isRandom;
  126. }
  127. public function setIsRandom( ?bool $isRandom ): Quiz
  128. {
  129. $this->isRandom = $isRandom;
  130. return $this;
  131. }
  132. public function getStatus(): ?int
  133. {
  134. return $this->status;
  135. }
  136. public function setStatus( int $status ): Quiz
  137. {
  138. $this->status = $status;
  139. return $this;
  140. }
  141. public function getDateStart(): ?DateTimeInterface
  142. {
  143. return $this->dateStart;
  144. }
  145. public function setDateStart( ?DateTimeInterface $dateStart ): Quiz
  146. {
  147. $this->dateStart = $dateStart;
  148. return $this;
  149. }
  150. public function getDateEnd(): ?DateTimeInterface
  151. {
  152. return $this->dateEnd;
  153. }
  154. public function setDateEnd( ?DateTimeInterface $dateEnd ): Quiz
  155. {
  156. $this->dateEnd = $dateEnd;
  157. return $this;
  158. }
  159. public function getQuizQuestions(): Collection
  160. {
  161. return $this->quizQuestions;
  162. }
  163. public function addQuizQuestion( QuizQuestion $quizQuestion ): Quiz
  164. {
  165. if ( !$this->quizQuestions->contains( $quizQuestion ) ) {
  166. $this->quizQuestions[] = $quizQuestion;
  167. $quizQuestion->setQuiz( $this );
  168. }
  169. return $this;
  170. }
  171. public function removeQuizQuestion( QuizQuestion $quizQuestion ): Quiz
  172. {
  173. if ( $this->quizQuestions->removeElement( $quizQuestion ) ) {
  174. // set the owning side to null (unless already changed)
  175. if ( $quizQuestion->getQuiz() === $this ) {
  176. $quizQuestion->setQuiz( NULL );
  177. }
  178. }
  179. return $this;
  180. }
  181. }