src/Entity/Question.php line 14

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\QuestionRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. #[ORM\Entity(repositoryClassQuestionRepository::class)]
  10. #[ApiResource]
  11. class Question
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\Column(typeTypes::TEXT)]
  18.     private ?string $text null;
  19.     #[ORM\ManyToOne(inversedBy'questions')]
  20.     private ?Quiz $quiz null;
  21.     #[ORM\OneToMany(mappedBy'question'targetEntityAnswere::class , cascade: ['persist'],orphanRemovaltrue)]
  22.     private Collection $answeres;
  23.     #[ORM\OneToMany(mappedBy'question'targetEntityGivenAnswere::class)]
  24.     private Collection $givenAnsweres;
  25.     public function __construct()
  26.     {
  27.         $this->answeres = new ArrayCollection();
  28.         $this->givenAnsweres = new ArrayCollection();
  29.     }
  30.     public function getId(): ?int
  31.     {
  32.         return $this->id;
  33.     }
  34.     public function __toString(): string
  35.     {
  36.         return $this->text;
  37.     }
  38.     public function getText(): ?string
  39.     {
  40.         return $this->text;
  41.     }
  42.     public function setText(string $text): self
  43.     {
  44.         $this->text $text;
  45.         return $this;
  46.     }
  47.     public function getQuiz(): ?Quiz
  48.     {
  49.         return $this->quiz;
  50.     }
  51.     public function setQuiz(?Quiz $quiz): self
  52.     {
  53.         $this->quiz $quiz;
  54.         return $this;
  55.     }
  56.     /**
  57.      * @return Collection<int, Answere>
  58.      */
  59.     public function getAnsweres(): Collection
  60.     {
  61.         return $this->answeres;
  62.     }
  63.     public function addAnswere(Answere $answere): self
  64.     {
  65.         if (!$this->answeres->contains($answere)) {
  66.             $this->answeres->add($answere);
  67.             $answere->setQuestion($this);
  68.         }
  69.         return $this;
  70.     }
  71.     public function removeAnswere(Answere $answere): self
  72.     {
  73.         if ($this->answeres->removeElement($answere)) {
  74.             // set the owning side to null (unless already changed)
  75.             if ($answere->getQuestion() === $this) {
  76.                 $answere->setQuestion(null);
  77.             }
  78.         }
  79.         return $this;
  80.     }
  81.     /**
  82.      * @return Collection<int, GivenAnswere>
  83.      */
  84.     public function getGivenAnsweres(): Collection
  85.     {
  86.         return $this->givenAnsweres;
  87.     }
  88.     public function addGivenAnswere(GivenAnswere $givenAnswere): self
  89.     {
  90.         if (!$this->givenAnsweres->contains($givenAnswere)) {
  91.             $this->givenAnsweres->add($givenAnswere);
  92.             $givenAnswere->setQuestion($this);
  93.         }
  94.         return $this;
  95.     }
  96.     public function removeGivenAnswere(GivenAnswere $givenAnswere): self
  97.     {
  98.         if ($this->givenAnsweres->removeElement($givenAnswere)) {
  99.             // set the owning side to null (unless already changed)
  100.             if ($givenAnswere->getQuestion() === $this) {
  101.                 $givenAnswere->setQuestion(null);
  102.             }
  103.         }
  104.         return $this;
  105.     }
  106. }