src/Entity/Channel/PositioningTest/Attempt/Answer.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Channel\PositioningTest\Attempt;
  3. use App\Entity\Channel\PositioningTest\Question;
  4. use App\Entity\Channel\PositioningTest\QuestionAnswer;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use DrosalysWeb\ObjectExtensions\Blame\Model\BlameInterface;
  9. use DrosalysWeb\ObjectExtensions\Blame\Model\BlameTrait;
  10. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampInterface;
  11. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampTrait;
  12. #[
  13. ORM\Entity(),
  14. ORM\Table(name: 'channel_positioning_test_attempt_answers'),
  15. ]
  16. class Answer implements TimestampInterface, BlameInterface
  17. {
  18. use TimestampTrait;
  19. use BlameTrait;
  20. #[ORM\Id]
  21. #[ORM\GeneratedValue]
  22. #[ORM\Column(type: 'integer')]
  23. private ?int $id = null;
  24. #[ORM\Column(type: 'boolean')]
  25. private bool $valid = false;
  26. #[ORM\ManyToOne(targetEntity: AttemptBlock::class, inversedBy: 'answers')]
  27. #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
  28. private ?AttemptBlock $attemptBlock = null;
  29. #[ORM\ManyToOne(targetEntity: Question::class)]
  30. #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
  31. private ?Question $question = null;
  32. #[ORM\ManyToMany(targetEntity: QuestionAnswer::class)]
  33. #[ORM\JoinTable('channel_positioning_test_attempt_answer_selected_answers')]
  34. private ?Collection $selectedAnswers = null;
  35. public function __construct()
  36. {
  37. $this->selectedAnswers = new ArrayCollection();
  38. }
  39. public function getId(): ?int
  40. {
  41. return $this->id;
  42. }
  43. public function isValid(): bool
  44. {
  45. return $this->valid;
  46. }
  47. public function setValid(bool $valid): static
  48. {
  49. $this->valid = $valid;
  50. return $this;
  51. }
  52. public function getAttemptBlock(): ?AttemptBlock
  53. {
  54. return $this->attemptBlock;
  55. }
  56. public function setAttemptBlock(?AttemptBlock $attemptBlock): static
  57. {
  58. $this->attemptBlock = $attemptBlock;
  59. return $this;
  60. }
  61. public function getQuestion(): ?Question
  62. {
  63. return $this->question;
  64. }
  65. public function setQuestion(?Question $question): static
  66. {
  67. $this->question = $question;
  68. return $this;
  69. }
  70. public function getSelectedAnswers(): ?Collection
  71. {
  72. return $this->selectedAnswers;
  73. }
  74. public function addSelectedAnswer(QuestionAnswer $answer): self
  75. {
  76. if (!$this->selectedAnswers->contains($answer)) {
  77. $this->selectedAnswers[] = $answer;
  78. }
  79. return $this;
  80. }
  81. public function removeSelectedAnswer(QuestionAnswer $answer): self
  82. {
  83. if ($this->selectedAnswers->contains($answer)) {
  84. $this->selectedAnswers->removeElement($answer);
  85. }
  86. return $this;
  87. }
  88. }