src/Entity/Quiz.php line 14

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\QuizRepository;
  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(repositoryClassQuizRepository::class)]
  10. #[ApiResource]
  11. class Quiz
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\Column(length255)]
  18.     private ?string $name null;
  19.     #[ORM\Column(typeTypes::TEXT)]
  20.     private ?string $description null;
  21.     #[ORM\Column(typeTypes::TEXT)]
  22.     private ?string $requirement null;
  23.     #[ORM\OneToMany(mappedBy'quiz'targetEntityQuestion::class, cascade: ['persist'],orphanRemovaltrue)]
  24.     private Collection $questions;
  25.     #[ORM\OneToMany(mappedBy'quiz'targetEntityLesson::class)]
  26.     private Collection $lessons;
  27.     #[ORM\OneToMany(mappedBy'quiz'targetEntityGivenAnswere::class),]
  28.     private Collection $givenAnsweres;
  29.     public function __construct()
  30.     {
  31.         $this->questions = new ArrayCollection();
  32.         $this->lessons = new ArrayCollection();
  33.         $this->givenAnsweres = new ArrayCollection();
  34.     }
  35.     public function getId(): ?int
  36.     {
  37.         return $this->id;
  38.     }
  39.     public function __toString(): string
  40.     {
  41.         return $this->name;
  42.     }
  43.     public function getName(): ?string
  44.     {
  45.         return $this->name;
  46.     }
  47.     public function setName(string $name): self
  48.     {
  49.         $this->name $name;
  50.         return $this;
  51.     }
  52.     public function getDescription(): ?string
  53.     {
  54.         return $this->description;
  55.     }
  56.     public function setDescription(string $description): self
  57.     {
  58.         $this->description $description;
  59.         return $this;
  60.     }
  61.     public function getRequirement(): ?string
  62.     {
  63.         return $this->requirement;
  64.     }
  65.     public function setRequirement(string $requirement): self
  66.     {
  67.         $this->requirement $requirement;
  68.         return $this;
  69.     }
  70.     /**
  71.      * @return Collection<int, Question>
  72.      */
  73.     public function getQuestions(): Collection
  74.     {
  75.         return $this->questions;
  76.     }
  77.     public function addQuestion(Question $question): self
  78.     {
  79.         if (!$this->questions->contains($question)) {
  80.             $this->questions->add($question);
  81.             $question->setQuiz($this);
  82.         }
  83.         return $this;
  84.     }
  85.     public function removeQuestion(Question $question): self
  86.     {
  87.         if ($this->questions->removeElement($question)) {
  88.             // set the owning side to null (unless already changed)
  89.             if ($question->getQuiz() === $this) {
  90.                 $question->setQuiz(null);
  91.             }
  92.         }
  93.         return $this;
  94.     }
  95.     /**
  96.      * @return Collection<int, Lesson>
  97.      */
  98.     public function getLessons(): Collection
  99.     {
  100.         return $this->lessons;
  101.     }
  102.     public function addLesson(Lesson $lesson): self
  103.     {
  104.         if (!$this->lessons->contains($lesson)) {
  105.             $this->lessons->add($lesson);
  106.             $lesson->setQuiz($this);
  107.         }
  108.         return $this;
  109.     }
  110.     public function removeLesson(Lesson $lesson): self
  111.     {
  112.         if ($this->lessons->removeElement($lesson)) {
  113.             // set the owning side to null (unless already changed)
  114.             if ($lesson->getQuiz() === $this) {
  115.                 $lesson->setQuiz(null);
  116.             }
  117.         }
  118.         return $this;
  119.     }
  120.     /**
  121.      * @return Collection<int, GivenAnswere>
  122.      */
  123.     public function getGivenAnsweres(): Collection
  124.     {
  125.         return $this->givenAnsweres;
  126.     }
  127.     public function addGivenAnswere(GivenAnswere $givenAnswere): self
  128.     {
  129.         if (!$this->givenAnsweres->contains($givenAnswere)) {
  130.             $this->givenAnsweres->add($givenAnswere);
  131.             $givenAnswere->setQuiz($this);
  132.         }
  133.         return $this;
  134.     }
  135.     public function removeGivenAnswere(GivenAnswere $givenAnswere): self
  136.     {
  137.         if ($this->givenAnsweres->removeElement($givenAnswere)) {
  138.             // set the owning side to null (unless already changed)
  139.             if ($givenAnswere->getQuiz() === $this) {
  140.                 $givenAnswere->setQuiz(null);
  141.             }
  142.         }
  143.         return $this;
  144.     }
  145. }