src/Entity/Lesson.php line 26
<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\LessonRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
#[ORM\Entity(repositoryClass: LessonRepository::class)]
#[Vich\Uploadable]
#[ApiResource(
operations: [
new Get(),
new GetCollection(),
]
)]
class Lesson
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['read:course:item', 'read:lecture:collection', 'read:lesson:item'])]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'lessons')]
#[ORM\JoinColumn(nullable: false)]
private ?Chapitre $chapitre = null;
#[ORM\Column(length: 255)]
#[Assert\NotBlank(message: "Ne peut être vide !")]
#[Assert\NotNull(message: "Ne peut être nul !")]
#[Groups(['read:course:item', 'read:lecture:collection', 'read:lesson:item'])]
private ?string $title = null;
#[ORM\Column(length: 255)]
#[Groups(['read:course:item', 'read:lesson:item'])]
private ?string $slug = null;
#[ORM\Column(type: Types::TEXT)]
#[Assert\NotBlank(message: "Ne peut être vide !")]
#[Assert\NotNull(message: "Ne peut être nul !")]
#[Groups(['read:lesson:item'])]
private ?string $content = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read:lesson:item'])]
private ?string $videoLink = null;
#[ORM\OneToMany(mappedBy: 'lesson', targetEntity: Lecture::class, orphanRemoval: true)]
private Collection $lectures;
#[ORM\Column(type: Types::SMALLINT, nullable: true)]
#[Groups(['read:course:item', 'read:lecture:collection', 'read:lesson:item'])]
private ?int $numero = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read:lesson:item'])]
private ?string $poster = null;
#[Vich\UploadableField(mapping: "lesson_poster", fileNameProperty: "poster")]
public ?File $posterFile = null;
#[Vich\UploadableField(mapping: "lesson_poster", fileNameProperty: "videoLink")]
public ?File $videoFile = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $updatedAt = null;
public function __construct()
{
$this->lectures = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getChapitre(): ?Chapitre
{
return $this->chapitre;
}
public function setChapitre(?Chapitre $chapitre): self
{
$this->chapitre = $chapitre;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function getVideoLink(): ?string
{
return $this->videoLink;
}
public function setVideoLink(?string $videoLink): self
{
$this->videoLink = $videoLink;
return $this;
}
/**
* @return Collection<int, Lecture>
*/
public function getLectures(): Collection
{
return $this->lectures;
}
public function addLecture(Lecture $lecture): self
{
if (!$this->lectures->contains($lecture)) {
$this->lectures->add($lecture);
$lecture->setLesson($this);
}
return $this;
}
public function removeLecture(Lecture $lecture): self
{
if ($this->lectures->removeElement($lecture)) {
// set the owning side to null (unless already changed)
if ($lecture->getLesson() === $this) {
$lecture->setLesson(null);
}
}
return $this;
}
public function getNumero(): ?int
{
return $this->numero;
}
public function setNumero(?int $numero): self
{
$this->numero = $numero;
return $this;
}
public function getPoster(): ?string
{
if ($this->poster == null) {
return 'uploads/media/course/' . $this->getChapitre()->getCours()->getMedia()->getImageFile();
}
return 'uploads/media/courses/lessons/posters/' . $this->poster;
}
public function setPoster(?string $poster): self
{
$this->poster = $poster;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
}