src/Entity/Lesson.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\LessonRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Entity\Traits\Timestampable;
  8. /**
  9.  * Leçon du programme national (créé par le superadmin).
  10.  *
  11.  * Rattaché à un SubjectReference (= matière + ClassOption).
  12.  * `position` définit l'ordre d'apparition dans le programme.
  13.  * `deadlineQuarter` indique la séquence avant la fin de laquelle le
  14.  * leçon doit être terminé (ex : "avant la fin de la Séquence 2").
  15.  *
  16.  * La date réelle de la deadline se calcule via deadlineQuarter->getEndDate()
  17.  * si ce champ existe sur Quarter, sinon on affiche juste le nom de la séquence.
  18.  */
  19. #[ORM\HasLifecycleCallbacks]
  20. #[ORM\Entity(repositoryClassLessonRepository::class)]
  21. class Lesson
  22. {
  23.     use Timestampable;
  24.     #[ORM\Id]
  25.     #[ORM\GeneratedValue]
  26.     #[ORM\Column]
  27.     private ?int $id null;
  28.     #[ORM\Column(length255)]
  29.     private ?string $title null;
  30.     #[ORM\Column(length255nullabletrue)]
  31.     private ?string $titleEn null;
  32.     #[ORM\Column(type'text'nullabletrue)]
  33.     private ?string $description null;
  34.     /**
  35.      * Ordre de la leçon dans le programme (1, 2, 3...).
  36.      */
  37.     #[ORM\Column]
  38.     private ?int $position null;
  39.     #[ORM\ManyToOne(inversedBy'lessons')]
  40.     #[ORM\JoinColumn(nullablefalse)]
  41.     private ?SubjectReference $subjectReference null;
  42.     /**
  43.      * Séquence avant la fin de laquelle cette leçon doit être terminée.
  44.      * Nullable : une leçon peut ne pas avoir de deadline imposée.
  45.      */
  46.     #[ORM\ManyToOne]
  47.     private ?Quarter $deadlineQuarter null;
  48.     /**
  49.      * Date calendaire optionnelle, en complément ou alternative à deadlineQuarter.
  50.      * Permet une deadline fixe (ex: 15/11/2025) si le superadmin préfère.
  51.      */
  52.     #[ORM\Column(type'date'nullabletrue)]
  53.     private ?\DateTimeInterface $deadlineDate null;
  54.     public const NATURE_THEORIQUE   'LT';
  55.     public const NATURE_DIGITALISEE 'LD';
  56.     public const NATURE_PRATIQUE    'LP';
  57.     /**
  58.      * Module/Thème parent (nullable — certaines matières n'ont pas de Module).
  59.      */
  60.     #[ORM\ManyToOne(inversedBy'lessons')]
  61.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  62.     private ?Module $module null;
  63.     /**
  64.      * Unité d'Apprentissage parente (nullable — certaines matières n'ont pas d'UA).
  65.      */
  66.     #[ORM\ManyToOne(inversedBy'lessons')]
  67.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  68.     private ?LearningUnit $learningUnit null;
  69.     /**
  70.      * Énoncé de compétence associé (nullable). Au niveau Leçon et non UA :
  71.      * certaines fiches de progression (ex: histoire-géo) n'ont ni Module ni
  72.      * UA mais la compétence y change quand même leçon par leçon.
  73.      */
  74.     #[ORM\Column(type'text'nullabletrue)]
  75.     private ?string $competenceStatement null;
  76.     /**
  77.      * Semaine du programme à laquelle cette leçon est prévue (nullable).
  78.      */
  79.     #[ORM\ManyToOne]
  80.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  81.     private ?ExamWeek $week null;
  82.     /**
  83.      * Nature par défaut définie par le national : Leçon Théorique (LT),
  84.      * Leçon Digitalisée (LD) ou Leçon Pratique (LP). Copiée comme valeur
  85.      * par défaut sur SubjectLesson::nature à la création, modifiable
  86.      * ensuite indépendamment par chaque école/prof.
  87.      */
  88.     #[ORM\Column(length2nullabletrue)]
  89.     private ?string $nature null;
  90.     /**
  91.      * Durée de référence en heures (ex: 2, 4).
  92.      */
  93.     #[ORM\Column(nullabletrue)]
  94.     private ?float $duration null;
  95.     #[ORM\OneToMany(mappedBy'lesson'targetEntityLessonProgress::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  96.     private Collection $progresses;
  97.     #[ORM\ManyToOne]
  98.     private ?User $author null;
  99.     public function __construct()
  100.     {
  101.         $this->progresses = new ArrayCollection();
  102.     }
  103.     public function __toString(): string
  104.     {
  105.         return $this->title;
  106.     }
  107.     public function getId(): ?int
  108.     {
  109.         return $this->id;
  110.     }
  111.     public function getTitle(): ?string
  112.     {
  113.         return $this->title;
  114.     }
  115.     public function setTitle(string $title): static
  116.     {
  117.         $this->title $title;
  118.         return $this;
  119.     }
  120.     public function getTitleEn(): ?string
  121.     {
  122.         return $this->titleEn;
  123.     }
  124.     public function setTitleEn(?string $titleEn): static
  125.     {
  126.         $this->titleEn $titleEn;
  127.         return $this;
  128.     }
  129.     public function getDescription(): ?string
  130.     {
  131.         return $this->description;
  132.     }
  133.     public function setDescription(?string $description): static
  134.     {
  135.         $this->description $description;
  136.         return $this;
  137.     }
  138.     public function getPosition(): ?int
  139.     {
  140.         return $this->position;
  141.     }
  142.     public function setPosition(int $position): static
  143.     {
  144.         $this->position $position;
  145.         return $this;
  146.     }
  147.     public function getSubjectReference(): ?SubjectReference
  148.     {
  149.         return $this->subjectReference;
  150.     }
  151.     public function setSubjectReference(?SubjectReference $subjectReference): static
  152.     {
  153.         $this->subjectReference $subjectReference;
  154.         return $this;
  155.     }
  156.     public function getDeadlineQuarter(): ?Quarter
  157.     {
  158.         return $this->deadlineQuarter;
  159.     }
  160.     public function setDeadlineQuarter(?Quarter $deadlineQuarter): static
  161.     {
  162.         $this->deadlineQuarter $deadlineQuarter;
  163.         return $this;
  164.     }
  165.     public function getDeadlineDate(): ?\DateTimeInterface
  166.     {
  167.         return $this->deadlineDate;
  168.     }
  169.     public function setDeadlineDate(?\DateTimeInterface $deadlineDate): static
  170.     {
  171.         $this->deadlineDate $deadlineDate;
  172.         return $this;
  173.     }
  174.     public function getModule(): ?Module
  175.     {
  176.         return $this->module;
  177.     }
  178.     public function setModule(?Module $module): static
  179.     {
  180.         $this->module $module;
  181.         return $this;
  182.     }
  183.     public function getLearningUnit(): ?LearningUnit
  184.     {
  185.         return $this->learningUnit;
  186.     }
  187.     public function setLearningUnit(?LearningUnit $learningUnit): static
  188.     {
  189.         $this->learningUnit $learningUnit;
  190.         return $this;
  191.     }
  192.     public function getCompetenceStatement(): ?string
  193.     {
  194.         return $this->competenceStatement;
  195.     }
  196.     public function setCompetenceStatement(?string $competenceStatement): static
  197.     {
  198.         $this->competenceStatement $competenceStatement;
  199.         return $this;
  200.     }
  201.     public function getWeek(): ?ExamWeek
  202.     {
  203.         return $this->week;
  204.     }
  205.     public function setWeek(?ExamWeek $week): static
  206.     {
  207.         $this->week $week;
  208.         return $this;
  209.     }
  210.     public function getNature(): ?string
  211.     {
  212.         return $this->nature;
  213.     }
  214.     public function setNature(?string $nature): static
  215.     {
  216.         $this->nature $nature;
  217.         return $this;
  218.     }
  219.     public function getDuration(): ?float
  220.     {
  221.         return $this->duration;
  222.     }
  223.     public function setDuration(?float $duration): static
  224.     {
  225.         $this->duration $duration;
  226.         return $this;
  227.     }
  228.     /**
  229.      * @return Collection<int, LessonProgress>
  230.      */
  231.     public function getProgresses(): Collection
  232.     {
  233.         return $this->progresses;
  234.     }
  235.     public function addProgress(LessonProgress $progress): static
  236.     {
  237.         if (!$this->progresses->contains($progress)) {
  238.             $this->progresses->add($progress);
  239.             $progress->setLesson($this);
  240.         }
  241.         return $this;
  242.     }
  243.     public function removeProgress(LessonProgress $progress): static
  244.     {
  245.         if ($this->progresses->removeElement($progress)) {
  246.             if ($progress->getLesson() === $this) {
  247.                 $progress->setLesson(null);
  248.             }
  249.         }
  250.         return $this;
  251.     }
  252.     public function getAuthor(): ?User
  253.     {
  254.         return $this->author;
  255.     }
  256.     public function setAuthor(?User $author): static
  257.     {
  258.         $this->author $author;
  259.         return $this;
  260.     }
  261. }