src/Entity/QuizQuestion.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\QuizQuestionRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassQuizQuestionRepository::class)]
  9. class QuizQuestion
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\ManyToOne(inversedBy'questions')]
  16.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  17.     private ?Quiz $quiz null;
  18.     #[ORM\Column(typeTypes::TEXT)]
  19.     private ?string $enonce null;
  20.     // 'qcu' = choix unique, 'qcm' = choix multiples,
  21.     // 'texte' = réponse libre, 'vrai_faux'
  22.     #[ORM\Column(length20)]
  23.     private string $typeQuestion 'qcu';
  24.     #[ORM\Column(nullabletrue)]
  25.     private ?int $points 1;
  26.     #[ORM\Column]
  27.     private int $position 0;
  28.     // Image optionnelle pour la question
  29.     #[ORM\Column(length255nullabletrue)]
  30.     private ?string $image null;
  31.     // Explication affichée après réponse
  32.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  33.     private ?string $explication null;
  34.     #[ORM\Column]
  35.     private bool $obligatoire true;
  36.     #[ORM\OneToMany(mappedBy'question'targetEntityQuizOption::class , cascade: ['persist''remove'], orphanRemovaltrue)]
  37.     private Collection $options;
  38.     #[ORM\OneToMany(mappedBy'question'targetEntityQuizReponseDetail::class)]
  39.     private Collection $details;
  40.     public function __construct()
  41.     {
  42.         $this->options = new ArrayCollection();
  43.         $this->details = new ArrayCollection();
  44.     }
  45.     public function getId(): ?int
  46.     {
  47.         return $this->id;
  48.     }
  49.     public function getQuiz(): ?Quiz
  50.     {
  51.         return $this->quiz;
  52.     }
  53.     public function setQuiz(?Quiz $quiz): self
  54.     {
  55.         $this->quiz $quiz;
  56.         return $this;
  57.     }
  58.     public function getEnonce(): ?string { return $this->enonce; }
  59.     public function setEnonce(string $e): self $this->enonce $e; return $this; }
  60.     public function getTypeQuestion(): string { return $this->typeQuestion; }
  61.     public function setTypeQuestion(string $t): self $this->typeQuestion $t; return $this; }
  62.     public function getPoints(): ?int { return $this->points; }
  63.     public function setPoints(?int $p): self $this->points $p; return $this; }
  64.     public function getPosition(): int { return $this->position; }
  65.     public function setPosition(int $p): self $this->position $p; return $this; }
  66.     public function getImage(): ?string { return $this->image; }
  67.     public function setImage(?string $i): self $this->image $i; return $this; }
  68.     public function getExplication(): ?string { return $this->explication; }
  69.     public function setExplication(?string $e): self $this->explication $e; return $this; }
  70.     public function isObligatoire(): bool { return $this->obligatoire; }
  71.     public function setObligatoire(bool $o): self $this->obligatoire $o; return $this; }
  72.     /**
  73.      * @return Collection<int, QuizOption>
  74.      */
  75.     public function getOptions(): Collection
  76.     {
  77.         return $this->options;
  78.     }
  79.     public function addOption(QuizOption $option): self
  80.     {
  81.         if (!$this->options->contains($option)) {
  82.             $this->options->add($option);
  83.             $option->setQuestion($this);
  84.         }
  85.         return $this;
  86.     }
  87.     public function removeOption(QuizOption $option): self
  88.     {
  89.         if ($this->options->removeElement($option)) {
  90.             // set the owning side to null (unless already changed)
  91.             if ($option->getQuestion() === $this) {
  92.                 $option->setQuestion(null);
  93.             }
  94.         }
  95.         return $this;
  96.     }
  97.     /**
  98.      * @return Collection<int, QuizReponseDetail>
  99.      */
  100.     public function getDetails(): Collection
  101.     {
  102.         return $this->details;
  103.     }
  104.     public function addDetail(QuizReponseDetail $detail): self
  105.     {
  106.         if (!$this->details->contains($detail)) {
  107.             $this->details->add($detail);
  108.             $detail->setQuestion($this);
  109.         }
  110.         return $this;
  111.     }
  112.     public function removeDetail(QuizReponseDetail $detail): self
  113.     {
  114.         if ($this->details->removeElement($detail)) {
  115.             // set the owning side to null (unless already changed)
  116.             if ($detail->getQuestion() === $this) {
  117.                 $detail->setQuestion(null);
  118.             }
  119.         }
  120.         return $this;
  121.     }
  122.     // Retourne les bonnes réponses
  123.     public function getBonnesReponses(): Collection {
  124.         return $this->options->filter(fn($o) => $o->isCorrect());
  125.     }
  126. }