src/Entity/Chapitre.php line 33

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Get;
  5. use App\Controller\Api\Controller\Course\Chapter\ShowQuizzesController;
  6. use App\Repository\ChapitreRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. #[ORM\Entity(repositoryClassChapitreRepository::class)]
  14. #[ApiResource(
  15.     operations: [
  16.         new Get(),
  17.         new Get(
  18.             uriTemplate'/chapitre/{id}/quizzes',
  19.             controllerShowQuizzesController::class,
  20.             readfalse,
  21.             normalizationContext: [
  22.                 'groups' => ['read:quizzes:collection']
  23.             ],
  24.             openapiContext: [
  25.                 'security' => [['bearerAuth' => []]]
  26.             ]
  27.         ),
  28.     ]
  29. )]
  30. class Chapitre
  31. {
  32.     #[ORM\Id]
  33.     #[ORM\GeneratedValue]
  34.     #[ORM\Column]
  35.     #[Groups(['read:course:item''read:lecture:collection'])]
  36.     private ?int $id null;
  37.     #[ORM\ManyToOne(inversedBy'chapitres')]
  38.     #[ORM\JoinColumn(nullablefalse)]
  39.     private ?Cours $cours null;
  40.     #[ORM\Column(length255)]
  41.     #[Assert\NotBlank(message"Le titre du chapitre ne peut être vide !")]
  42.     #[Assert\Length(min10minMessage"Le titre du chapitre dois avoir au moins 10 caractères !")]
  43.     #[Groups(['read:course:item''read:lecture:collection'])]
  44.     private ?string $title null;
  45.     #[ORM\Column(length255)]
  46.     #[Groups(['read:course:item''read:lecture:collection'])]
  47.     private ?string $slug null;
  48.     #[ORM\Column(typeTypes::TEXT)]
  49.     #[Assert\NotBlank(message"La description est requise !")]
  50.     #[Groups(['read:course:item'])]
  51.     private ?string $description null;
  52.     #[ORM\OneToMany(mappedBy'chapitre'cascade: ['persist''remove'], targetEntityLesson::class, orphanRemovaltrue)]
  53.     #[Groups(['read:course:item''read:lesson:item'])]
  54.     private Collection $lessons;
  55.     #[ORM\OneToMany(mappedBy'chapitre'targetEntityQuiz::class, orphanRemovaltrue)]
  56.     #[Groups(['read:quizzes:collection'])]
  57.     private Collection $quizzes;
  58.     #[ORM\Column(typeTypes::SMALLINTnullabletrue)]
  59.     #[Groups(['read:course:item''read:lecture:collection'])]
  60.     private ?int $numero null;
  61.     #[ORM\OneToMany(mappedBy'chapitre'targetEntityLecture::class)]
  62.     private Collection $lectures;
  63.     #[ORM\OneToMany(mappedBy'chapitre'targetEntityQuizLost::class)]
  64.     private Collection $quizLosts;
  65.     public function __construct()
  66.     {
  67.         $this->lessons = new ArrayCollection();
  68.         $this->quizzes = new ArrayCollection();
  69.         $this->lectures = new ArrayCollection();
  70.         $this->quizLosts = new ArrayCollection();
  71.     }
  72.     public function getId(): ?int
  73.     {
  74.         return $this->id;
  75.     }
  76.     public function getCours(): ?Cours
  77.     {
  78.         return $this->cours;
  79.     }
  80.     public function setCours(?Cours $cours): self
  81.     {
  82.         $this->cours $cours;
  83.         return $this;
  84.     }
  85.     public function getTitle(): ?string
  86.     {
  87.         return $this->title;
  88.     }
  89.     public function setTitle(string $title): self
  90.     {
  91.         $this->title $title;
  92.         return $this;
  93.     }
  94.     public function getSlug(): ?string
  95.     {
  96.         return $this->slug;
  97.     }
  98.     public function setSlug(string $slug): self
  99.     {
  100.         $this->slug $slug;
  101.         return $this;
  102.     }
  103.     public function getDescription(): ?string
  104.     {
  105.         return $this->description;
  106.     }
  107.     public function setDescription(string $description): self
  108.     {
  109.         $this->description $description;
  110.         return $this;
  111.     }
  112.     /**
  113.      * @return Collection<int, Lesson>
  114.      */
  115.     public function getLessons(): Collection
  116.     {
  117.         return $this->lessons;
  118.     }
  119.     public function addLesson(Lesson $lesson): self
  120.     {
  121.         if (!$this->lessons->contains($lesson)) {
  122.             $this->lessons->add($lesson);
  123.             $lesson->setChapitre($this);
  124.         }
  125.         return $this;
  126.     }
  127.     public function removeLesson(Lesson $lesson): self
  128.     {
  129.         if ($this->lessons->removeElement($lesson)) {
  130.             // set the owning side to null (unless already changed)
  131.             if ($lesson->getChapitre() === $this) {
  132.                 $lesson->setChapitre(null);
  133.             }
  134.         }
  135.         return $this;
  136.     }
  137.     /**
  138.      * @return Collection<int, Quiz>
  139.      */
  140.     public function getQuizzes(): Collection
  141.     {
  142.         return $this->quizzes;
  143.     }
  144.     public function addQuiz(Quiz $quiz): self
  145.     {
  146.         if (!$this->quizzes->contains($quiz)) {
  147.             $this->quizzes->add($quiz);
  148.             $quiz->setChapitre($this);
  149.         }
  150.         return $this;
  151.     }
  152.     public function removeQuiz(Quiz $quiz): self
  153.     {
  154.         if ($this->quizzes->removeElement($quiz)) {
  155.             // set the owning side to null (unless already changed)
  156.             if ($quiz->getChapitre() === $this) {
  157.                 $quiz->setChapitre(null);
  158.             }
  159.         }
  160.         return $this;
  161.     }
  162.     public function getNumero(): ?int
  163.     {
  164.         return $this->numero;
  165.     }
  166.     public function setNumero(?int $numero): self
  167.     {
  168.         $this->numero $numero;
  169.         return $this;
  170.     }
  171.     /**
  172.      * @return Collection<int, Lecture>
  173.      */
  174.     public function getLectures(): Collection
  175.     {
  176.         return $this->lectures;
  177.     }
  178.     public function addLecture(Lecture $lecture): self
  179.     {
  180.         if (!$this->lectures->contains($lecture)) {
  181.             $this->lectures->add($lecture);
  182.             $lecture->setChapitre($this);
  183.         }
  184.         return $this;
  185.     }
  186.     public function removeLecture(Lecture $lecture): self
  187.     {
  188.         if ($this->lectures->removeElement($lecture)) {
  189.             // set the owning side to null (unless already changed)
  190.             if ($lecture->getChapitre() === $this) {
  191.                 $lecture->setChapitre(null);
  192.             }
  193.         }
  194.         return $this;
  195.     }
  196.     /**
  197.      * @return Collection<int, QuizLost>
  198.      */
  199.     public function getQuizLosts(): Collection
  200.     {
  201.         return $this->quizLosts;
  202.     }
  203.     public function addQuizLost(QuizLost $quizLost): self
  204.     {
  205.         if (!$this->quizLosts->contains($quizLost)) {
  206.             $this->quizLosts->add($quizLost);
  207.             $quizLost->setChapitre($this);
  208.         }
  209.         return $this;
  210.     }
  211.     public function removeQuizLost(QuizLost $quizLost): self
  212.     {
  213.         if ($this->quizLosts->removeElement($quizLost)) {
  214.             // set the owning side to null (unless already changed)
  215.             if ($quizLost->getChapitre() === $this) {
  216.                 $quizLost->setChapitre(null);
  217.             }
  218.         }
  219.         return $this;
  220.     }
  221. }