src/Entity/Lesson.php line 26

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\LessonRepository;
  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. use ApiPlatform\Metadata\Get;
  10. use ApiPlatform\Metadata\GetCollection;
  11. use Symfony\Component\HttpFoundation\File\File;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  15. #[ORM\Entity(repositoryClassLessonRepository::class)]
  16. #[Vich\Uploadable]
  17. #[ApiResource(
  18.     operations: [
  19.         new Get(),
  20.         new GetCollection(),
  21.     ]
  22. )]
  23. class Lesson
  24. {
  25.     #[ORM\Id]
  26.     #[ORM\GeneratedValue]
  27.     #[ORM\Column]
  28.     #[Groups(['read:course:item''read:lecture:collection''read:lesson:item'])]
  29.     private ?int $id null;
  30.     #[ORM\ManyToOne(inversedBy'lessons')]
  31.     #[ORM\JoinColumn(nullablefalse)]
  32.     private ?Chapitre $chapitre null;
  33.     #[ORM\Column(length255)]
  34.     #[Assert\NotBlank(message"Ne peut être vide !")]
  35.     #[Assert\NotNull(message"Ne peut être nul !")]
  36.     #[Groups(['read:course:item''read:lecture:collection''read:lesson:item'])]
  37.     private ?string $title null;
  38.     #[ORM\Column(length255)]
  39.     #[Groups(['read:course:item''read:lesson:item'])]
  40.     private ?string $slug null;
  41.     #[ORM\Column(typeTypes::TEXT)]
  42.     #[Assert\NotBlank(message"Ne peut être vide !")]
  43.     #[Assert\NotNull(message"Ne peut être nul !")]
  44.     #[Groups(['read:lesson:item'])]
  45.     private ?string $content null;
  46.     #[ORM\Column(length255nullabletrue)]
  47.     #[Groups(['read:lesson:item'])]
  48.     private ?string $videoLink null;
  49.     #[ORM\OneToMany(mappedBy'lesson'targetEntityLecture::class, orphanRemovaltrue)]
  50.     private Collection $lectures;
  51.     #[ORM\Column(typeTypes::SMALLINTnullabletrue)]
  52.     #[Groups(['read:course:item''read:lecture:collection''read:lesson:item'])]
  53.     private ?int $numero null;
  54.     #[ORM\Column(length255nullabletrue)]
  55.     #[Groups(['read:lesson:item'])]
  56.     private ?string $poster null;
  57.     #[Vich\UploadableField(mapping"lesson_poster"fileNameProperty"poster")]
  58.     public ?File $posterFile null;
  59.     #[Vich\UploadableField(mapping"lesson_poster"fileNameProperty"videoLink")]
  60.     public ?File $videoFile null;
  61.     #[ORM\Column(nullabletrue)]
  62.     private ?\DateTimeImmutable $updatedAt null;
  63.     public function __construct()
  64.     {
  65.         $this->lectures = new ArrayCollection();
  66.     }
  67.     public function getId(): ?int
  68.     {
  69.         return $this->id;
  70.     }
  71.     public function getChapitre(): ?Chapitre
  72.     {
  73.         return $this->chapitre;
  74.     }
  75.     public function setChapitre(?Chapitre $chapitre): self
  76.     {
  77.         $this->chapitre $chapitre;
  78.         return $this;
  79.     }
  80.     public function getTitle(): ?string
  81.     {
  82.         return $this->title;
  83.     }
  84.     public function setTitle(string $title): self
  85.     {
  86.         $this->title $title;
  87.         return $this;
  88.     }
  89.     public function getSlug(): ?string
  90.     {
  91.         return $this->slug;
  92.     }
  93.     public function setSlug(string $slug): self
  94.     {
  95.         $this->slug $slug;
  96.         return $this;
  97.     }
  98.     public function getContent(): ?string
  99.     {
  100.         return $this->content;
  101.     }
  102.     public function setContent(string $content): self
  103.     {
  104.         $this->content $content;
  105.         return $this;
  106.     }
  107.     public function getVideoLink(): ?string
  108.     {
  109.         return $this->videoLink;
  110.     }
  111.     public function setVideoLink(?string $videoLink): self
  112.     {
  113.         $this->videoLink $videoLink;
  114.         return $this;
  115.     }
  116.     /**
  117.      * @return Collection<int, Lecture>
  118.      */
  119.     public function getLectures(): Collection
  120.     {
  121.         return $this->lectures;
  122.     }
  123.     public function addLecture(Lecture $lecture): self
  124.     {
  125.         if (!$this->lectures->contains($lecture)) {
  126.             $this->lectures->add($lecture);
  127.             $lecture->setLesson($this);
  128.         }
  129.         return $this;
  130.     }
  131.     public function removeLecture(Lecture $lecture): self
  132.     {
  133.         if ($this->lectures->removeElement($lecture)) {
  134.             // set the owning side to null (unless already changed)
  135.             if ($lecture->getLesson() === $this) {
  136.                 $lecture->setLesson(null);
  137.             }
  138.         }
  139.         return $this;
  140.     }
  141.     public function getNumero(): ?int
  142.     {
  143.         return $this->numero;
  144.     }
  145.     public function setNumero(?int $numero): self
  146.     {
  147.         $this->numero $numero;
  148.         return $this;
  149.     }
  150.     public function getPoster(): ?string
  151.     {
  152.         if ($this->poster == null) {
  153.             return 'uploads/media/course/' $this->getChapitre()->getCours()->getMedia()->getImageFile();
  154.         }
  155.         return 'uploads/media/courses/lessons/posters/' $this->poster;
  156.     }
  157.     public function setPoster(?string $poster): self
  158.     {
  159.         $this->poster $poster;
  160.         return $this;
  161.     }
  162.     public function getUpdatedAt(): ?\DateTimeImmutable
  163.     {
  164.         return $this->updatedAt;
  165.     }
  166.     public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
  167.     {
  168.         $this->updatedAt $updatedAt;
  169.         return $this;
  170.     }
  171. }