src/Entity/LessonLog.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\LessonLogRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use App\Entity\Traits\Timestampable;
  9. /**
  10.  * Une entrée du "cahier de texte numérique".
  11.  *
  12.  * Le prof saisit, après chaque séance, ce qu'il a effectivement vu en
  13.  * cours — même si le chapitre n'est pas terminé, et même s'il n'y a PAS
  14.  * de chapitre concerné (révisions générales, correction d'épreuve...).
  15.  * Permet au censeur / préfet des études de suivre l'avancement réel jour
  16.  * par jour.
  17.  *
  18.  * - chapterProgress est NULLABLE : si null, 'motif' doit être rempli
  19.  *   (cf. LessonLogController/ProgressController qui imposent cette règle).
  20.  * - subject est TOUJOURS rempli (avec ou sans chapitre), pour pouvoir
  21.  *   lister tout le cahier de texte d'une matière indépendamment du
  22.  *   programme national.
  23.  * - agendaElement + timeRanges permettent de savoir précisément quelle(s)
  24.  *   tranche(s) horaire(s) du cours ont déjà été documentées, pour empêcher
  25.  *   les doublons (cf. règle métier : on ne remplit pas deux fois la même
  26.  *   tranche horaire).
  27.  * - startAt/endAt sont calculés depuis agendaElement/timeRanges au moment
  28.  *   de la création, jamais saisis directement par l'utilisateur.
  29.  */
  30. #[ORM\HasLifecycleCallbacks]
  31. #[ORM\Entity(repositoryClassLessonLogRepository::class)]
  32. class LessonLog
  33. {
  34.     use Timestampable;
  35.     #[ORM\Id]
  36.     #[ORM\GeneratedValue]
  37.     #[ORM\Column]
  38.     private ?int $id null;
  39.     /**
  40.      * Chapitre du programme national concerné. NULL si la séance ne
  41.      * correspond à aucun chapitre (révisions, correction d'épreuve...) —
  42.      * dans ce cas, 'motif' doit être rempli à la place.
  43.      */
  44.     #[ORM\ManyToOne(inversedBy'lessonLogs')]
  45.     private ?ChapterProgress $chapterProgress null;
  46.     /**
  47.      * La matière réelle concernée. Toujours rempli, même sans chapitre,
  48.      * pour permettre une liste chronologique du cahier de texte par
  49.      * matière indépendamment du programme national.
  50.      */
  51.     #[ORM\ManyToOne(inversedBy'lessonLogs')]
  52.     #[ORM\JoinColumn(nullablefalse)]
  53.     private ?Subject $subject null;
  54.     /**
  55.      * Motif de la séance quand aucun chapitre n'est concerné
  56.      * (ex: "Révisions générales avant le contrôle", "Correction de
  57.      * l'épreuve du contrôle commun"). NULL si chapterProgress est rempli.
  58.      */
  59.     #[ORM\Column(length255nullabletrue)]
  60.     private ?string $motif null;
  61.     /**
  62.      * Date à laquelle le cours a été dispensé.
  63.      */
  64.     #[ORM\Column(type'date')]
  65.     private ?\DateTimeInterface $date null;
  66.     /**
  67.      * Heure de début réelle de la séance documentée (copiée depuis
  68.      * l'AgendaElement ou la TimeRange choisie — jamais saisie).
  69.      */
  70.     #[ORM\Column(typeTypes::TIME_MUTABLEnullabletrue)]
  71.     private ?\DateTimeInterface $startAt null;
  72.     /**
  73.      * Heure de fin réelle de la séance documentée (idem startAt).
  74.      */
  75.     #[ORM\Column(typeTypes::TIME_MUTABLEnullabletrue)]
  76.     private ?\DateTimeInterface $endAt null;
  77.     /**
  78.      * Texte libre : ce qui a été vu/fait pendant la séance.
  79.      */
  80.     #[ORM\Column(type'text')]
  81.     private ?string $content null;
  82.     /**
  83.      * Durée de la séance en heures (ex: 1, 1.5, 2), calculée à partir du
  84.      * nombre de tranches horaires couvertes et de AgendaTimeConvertion.
  85.      */
  86.     #[ORM\Column(nullabletrue)]
  87.     private ?float $duration null;
  88.     #[ORM\ManyToOne]
  89.     #[ORM\JoinColumn(nullablefalse)]
  90.     private ?User $createdBy null;
  91.     /**
  92.      * Le cours (AgendaElement) pendant lequel la séance a eu lieu.
  93.      * Nécessaire pour la vérification anti-doublon par tranche horaire.
  94.      */
  95.     #[ORM\ManyToOne(inversedBy'lessonLogs')]
  96.     #[ORM\JoinColumn(nullablefalse)]
  97.     private ?AgendaElement $agendaElement null;
  98.     /**
  99.      * Tranche(s) horaire(s) couvertes par cette entrée. Vide si "tout le
  100.      * cours" a été choisi sans tranches définies sur l'AgendaElement
  101.      * (cas rare, fallback sur agendaElement seul pour l'anti-doublon).
  102.      *
  103.      * Côté INVERSE de la relation (comme Absence::timeRanges) :
  104.      * TimeRange::lessonLogs est le côté propriétaire (owning side) avec
  105.      * 'inversedBy' => 'timeRanges' ; ici on déclare 'mappedBy' => 'lessonLogs'.
  106.      *
  107.      * @var Collection<int, TimeRange>
  108.      */
  109.     #[ORM\ManyToMany(targetEntityTimeRange::class, mappedBy'lessonLogs')]
  110.     private Collection $timeRanges;
  111.     public function __construct()
  112.     {
  113.         $this->timeRanges = new ArrayCollection();
  114.     }
  115.     public function getId(): ?int
  116.     {
  117.         return $this->id;
  118.     }
  119.     public function getChapterProgress(): ?ChapterProgress
  120.     {
  121.         return $this->chapterProgress;
  122.     }
  123.     public function setChapterProgress(?ChapterProgress $chapterProgress): static
  124.     {
  125.         $this->chapterProgress $chapterProgress;
  126.         return $this;
  127.     }
  128.     public function getSubject(): ?Subject
  129.     {
  130.         return $this->subject;
  131.     }
  132.     public function setSubject(?Subject $subject): static
  133.     {
  134.         $this->subject $subject;
  135.         return $this;
  136.     }
  137.     public function getMotif(): ?string
  138.     {
  139.         return $this->motif;
  140.     }
  141.     public function setMotif(?string $motif): static
  142.     {
  143.         $this->motif $motif;
  144.         return $this;
  145.     }
  146.     /**
  147.      * Libellé à afficher : le titre du chapitre s'il existe, sinon le motif.
  148.      */
  149.     public function getDisplayLabel(): string
  150.     {
  151.         if ($this->chapterProgress !== null) {
  152.             return $this->chapterProgress->getChapterTitle();
  153.         }
  154.         return $this->motif ?? 'Séance sans chapitre';
  155.     }
  156.     public function getDate(): ?\DateTimeInterface
  157.     {
  158.         return $this->date;
  159.     }
  160.     public function setDate(\DateTimeInterface $date): static
  161.     {
  162.         $this->date $date;
  163.         return $this;
  164.     }
  165.     public function getStartAt(): ?\DateTimeInterface
  166.     {
  167.         return $this->startAt;
  168.     }
  169.     public function setStartAt(?\DateTimeInterface $startAt): static
  170.     {
  171.         $this->startAt $startAt;
  172.         return $this;
  173.     }
  174.     public function getEndAt(): ?\DateTimeInterface
  175.     {
  176.         return $this->endAt;
  177.     }
  178.     public function setEndAt(?\DateTimeInterface $endAt): static
  179.     {
  180.         $this->endAt $endAt;
  181.         return $this;
  182.     }
  183.     public function getContent(): ?string
  184.     {
  185.         return $this->content;
  186.     }
  187.     public function setContent(string $content): static
  188.     {
  189.         $this->content $content;
  190.         return $this;
  191.     }
  192.     public function getDuration(): ?float
  193.     {
  194.         return $this->duration;
  195.     }
  196.     public function setDuration(?float $duration): static
  197.     {
  198.         $this->duration $duration;
  199.         return $this;
  200.     }
  201.     public function getCreatedBy(): ?User
  202.     {
  203.         return $this->createdBy;
  204.     }
  205.     public function setCreatedBy(?User $createdBy): static
  206.     {
  207.         $this->createdBy $createdBy;
  208.         return $this;
  209.     }
  210.     public function getAgendaElement(): ?AgendaElement
  211.     {
  212.         return $this->agendaElement;
  213.     }
  214.     public function setAgendaElement(?AgendaElement $agendaElement): static
  215.     {
  216.         $this->agendaElement $agendaElement;
  217.         return $this;
  218.     }
  219.     /**
  220.      * @return Collection<int, TimeRange>
  221.      */
  222.     public function getTimeRanges(): Collection
  223.     {
  224.         return $this->timeRanges;
  225.     }
  226.     public function addTimeRange(TimeRange $timeRange): static
  227.     {
  228.         if (!$this->timeRanges->contains($timeRange)) {
  229.             $this->timeRanges->add($timeRange);
  230.             $timeRange->addLessonLog($this);
  231.         }
  232.         return $this;
  233.     }
  234.     public function removeTimeRange(TimeRange $timeRange): static
  235.     {
  236.         if ($this->timeRanges->removeElement($timeRange)) {
  237.             $timeRange->removeLessonLog($this);
  238.         }
  239.         return $this;
  240.     }
  241. }