src/AdminBundle/Entity/Question.php line 80

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6. * Question
  7. */
  8. #[ORM\Table(name: 'questions')]
  9. #[ORM\Entity(repositoryClass: \AdminBundle\Repository\QuestionRepository::class)]
  10. class Question
  11. {
  12. /**
  13. * @var int
  14. */
  15. #[ORM\Column(name: 'id', type: 'integer')]
  16. #[ORM\Id]
  17. #[ORM\GeneratedValue(strategy: 'AUTO')]
  18. private $id;
  19. /**
  20. * @var Booking
  21. */
  22. #[ORM\JoinColumn(name: 'questionnaire_id', referencedColumnName: 'id')]
  23. #[ORM\ManyToOne(targetEntity: \AdminBundle\Entity\Questionnaire::class, inversedBy: 'questions', cascade: ['persist', 'remove'])]
  24. private $questionnaire;
  25. /**
  26. * @var string
  27. */
  28. #[ORM\Column(name: 'name', type: 'string', length: 255)]
  29. private $name;
  30. #[ORM\OneToMany(targetEntity: \AdminBundle\Entity\Answer::class, mappedBy: 'question', cascade: ['all'], orphanRemoval: true)]
  31. private $answers;
  32. /**
  33. * @return int
  34. */
  35. public function getId()
  36. {
  37. return $this->id;
  38. }
  39. /**
  40. * @return string
  41. */
  42. public function getName()
  43. {
  44. return $this->name;
  45. }
  46. /**
  47. * @param string $name
  48. *
  49. * @return Question
  50. */
  51. public function setName($name)
  52. {
  53. $this->name = $name;
  54. return $this;
  55. }
  56. /**
  57. * @return Questionnaire
  58. */
  59. public function getQuestionnaire()
  60. {
  61. return $this->questionnaire;
  62. }
  63. /**
  64. * @param Questionnaire $questionnaire
  65. *
  66. * @return Question
  67. */
  68. public function setQuestionnaire(Questionnaire $questionnaire = null)
  69. {
  70. $this->questionnaire = $questionnaire;
  71. return $this;
  72. }
  73. /**
  74. * @param Answer $answer
  75. *
  76. * @return Question
  77. */
  78. public function addAnswer(Answer $answer)
  79. {
  80. $answer->setQuestion($this);
  81. $this->answers->add($answer);
  82. return $this;
  83. }
  84. /**
  85. * @param Answer $answer
  86. *
  87. * @return Question
  88. */
  89. public function removeAnswer(Answer $answer)
  90. {
  91. if (!$this->answers->contains($answer)) {
  92. return;
  93. }
  94. $this->answers->removeElement($answer);
  95. $answer->setQuestion(null);
  96. return $this;
  97. }
  98. /**
  99. * @return ArrayCollection
  100. */
  101. public function getAnswers()
  102. {
  103. return $this->answers;
  104. }
  105. }