<?php
namespace App\Entity;
use App\Repository\SubjectModuleRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Traits\Timestampable;
/**
* Thème (Module) LOCAL d'une matière dans un établissement.
*
* Pendant de Module (programme national) pour la partie du cahier de texte
* "hors programme national" : l'admin/éditeur d'une école peut créer ses
* propres thèmes pour regrouper ses SubjectLesson, exactement comme le
* superadmin le fait pour Lesson via Module — mais scopé au Subject réel
* (matière + classe + année + école), comme SubjectLesson, et non au
* SubjectReference (matière + ClassOption) qui est partagé entre écoles.
*
* Une SubjectLesson peut alternativement être rattachée directement à un
* Module national (voir SubjectLesson::$module) sans passer par un
* SubjectModule local — les deux mécanismes cohabitent.
*/
#[ORM\HasLifecycleCallbacks]
#[ORM\Entity(repositoryClass: SubjectModuleRepository::class)]
class SubjectModule
{
use Timestampable;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $title = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $titleEn = null;
/**
* Ordre d'affichage parmi les thèmes locaux de la matière (1, 2, 3...).
*/
#[ORM\Column]
private ?int $position = null;
#[ORM\ManyToOne(inversedBy: 'subjectModules')]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private ?Subject $subject = null;
#[ORM\OneToMany(mappedBy: 'subjectModule', targetEntity: SubjectLearningUnit::class)]
#[ORM\OrderBy(['position' => 'ASC'])]
private Collection $subjectLearningUnits;
#[ORM\OneToMany(mappedBy: 'subjectModule', targetEntity: SubjectLesson::class)]
private Collection $subjectLessons;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?User $author = null;
public function __construct()
{
$this->subjectLearningUnits = new ArrayCollection();
$this->subjectLessons = new ArrayCollection();
}
public function __toString(): string
{
return $this->title ?? '';
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
public function getTitleEn(): ?string
{
return $this->titleEn;
}
public function setTitleEn(?string $titleEn): static
{
$this->titleEn = $titleEn;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(int $position): static
{
$this->position = $position;
return $this;
}
public function getSubject(): ?Subject
{
return $this->subject;
}
public function setSubject(?Subject $subject): static
{
$this->subject = $subject;
return $this;
}
/** @return Collection<int, SubjectLearningUnit> */
public function getSubjectLearningUnits(): Collection
{
return $this->subjectLearningUnits;
}
/** @return Collection<int, SubjectLesson> */
public function getSubjectLessons(): Collection
{
return $this->subjectLessons;
}
public function getAuthor(): ?User
{
return $this->author;
}
public function setAuthor(?User $author): static
{
$this->author = $author;
return $this;
}
}