src/Entity/QuizAnswer.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\QuizAnswerRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity(repositoryClass=QuizAnswerRepository::class)
  9. */
  10. class QuizAnswer
  11. {
  12. /**
  13. * @ORM\Id
  14. * @ORM\GeneratedValue
  15. * @ORM\Column(type="integer")
  16. */
  17. private $id;
  18. /**
  19. * @ORM\Column(type="string", length=255)
  20. */
  21. private ?string $text;
  22. /**
  23. * @ORM\Column(type="boolean", options={"default":false})
  24. */
  25. private bool $isRight = FALSE;
  26. /**
  27. * @ORM\Column(type="integer", nullable=true)
  28. */
  29. private ?int $orderIndex;
  30. /**
  31. * @ORM\ManyToOne(targetEntity=QuizQuestion::class, inversedBy="quizAnswers")
  32. */
  33. private ?QuizQuestion $quizQuestion;
  34. /**
  35. * @ORM\OneToMany(targetEntity=QuizUserAnswer::class, mappedBy="quizAnswer", cascade={"persist", "remove"})
  36. */
  37. private $quizUserAnswers;
  38. public function __construct()
  39. {
  40. $this->quizUserAnswers = new ArrayCollection();
  41. }
  42. public function getId(): ?int
  43. {
  44. return $this->id;
  45. }
  46. public function getText(): ?string
  47. {
  48. return $this->text;
  49. }
  50. public function setText( string $text ): QuizAnswer
  51. {
  52. $this->text = $text;
  53. return $this;
  54. }
  55. public function getIsRight(): ?bool
  56. {
  57. return $this->isRight;
  58. }
  59. public function setIsRight( bool $isRight ): QuizAnswer
  60. {
  61. $this->isRight = $isRight;
  62. return $this;
  63. }
  64. public function getOrderIndex(): ?int
  65. {
  66. return $this->orderIndex;
  67. }
  68. public function setOrderIndex( ?int $orderIndex ): QuizAnswer
  69. {
  70. $this->orderIndex = $orderIndex;
  71. return $this;
  72. }
  73. public function getQuizQuestion(): ?QuizQuestion
  74. {
  75. return $this->quizQuestion;
  76. }
  77. public function setQuizQuestion( ?QuizQuestion $quizQuestion ): QuizAnswer
  78. {
  79. $this->quizQuestion = $quizQuestion;
  80. // $quizQuestion->addQuizAnswer( $this );
  81. return $this;
  82. }
  83. public function getQuizUserAnswers(): Collection
  84. {
  85. return $this->quizUserAnswers;
  86. }
  87. public function addQuizUserAnswer( QuizUserAnswer $quizUserAnswer ): QuizAnswer
  88. {
  89. if ( !$this->quizUserAnswers->contains( $quizUserAnswer ) ) {
  90. $this->quizUserAnswers[] = $quizUserAnswer;
  91. $quizUserAnswer->setQuizAnswer( $this );
  92. }
  93. return $this;
  94. }
  95. public function removeQuizUserAnswer( QuizUserAnswer $quizUserAnswer ): QuizAnswer
  96. {
  97. if ( $this->quizUserAnswers->removeElement( $quizUserAnswer ) ) {
  98. // set the owning side to null (unless already changed)
  99. if ( $quizUserAnswer->getQuizAnswer() === $this ) {
  100. $quizUserAnswer->setQuizAnswer( NULL );
  101. }
  102. }
  103. return $this;
  104. }
  105. }