feat: Permettre la création et modification de l'emploi du temps des classes
L'administration a besoin de construire et maintenir les emplois du temps hebdomadaires pour chaque classe, en s'assurant que les enseignants ne sont pas en conflit (même créneau, classes différentes) et que les affectations enseignant-matière-classe sont respectées. Cette implémentation couvre le CRUD complet des créneaux (ScheduleSlot), la détection de conflits (classe, enseignant, salle) avec possibilité de forcer, la validation des affectations côté serveur (AC2), l'intégration calendrier pour les jours bloqués, une vue mobile-first avec onglets jour par jour, et le drag-and-drop pour réorganiser les créneaux sur desktop.
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Query\GetBlockedDates;
|
||||
|
||||
final readonly class BlockedDateDto
|
||||
{
|
||||
public function __construct(
|
||||
public string $date,
|
||||
public string $reason,
|
||||
public string $type,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Query\GetBlockedDates;
|
||||
|
||||
use App\Administration\Domain\Model\SchoolCalendar\SchoolCalendarRepository;
|
||||
use App\Administration\Domain\Model\SchoolClass\AcademicYearId;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use DateInterval;
|
||||
use DateTimeImmutable;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
/**
|
||||
* Retourne les dates bloquées (jours fériés, vacances, journées pédagogiques, weekends)
|
||||
* pour une plage de dates donnée.
|
||||
*
|
||||
* Utilisé par le frontend pour griser les jours non modifiables dans la grille EDT.
|
||||
*/
|
||||
#[AsMessageHandler(bus: 'query.bus')]
|
||||
final readonly class GetBlockedDatesHandler
|
||||
{
|
||||
public function __construct(
|
||||
private SchoolCalendarRepository $calendarRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
/** @return array<BlockedDateDto> */
|
||||
public function __invoke(GetBlockedDatesQuery $query): array
|
||||
{
|
||||
$tenantId = TenantId::fromString($query->tenantId);
|
||||
$academicYearId = AcademicYearId::fromString($query->academicYearId);
|
||||
|
||||
$calendar = $this->calendarRepository->findByTenantAndYear($tenantId, $academicYearId);
|
||||
|
||||
$startDate = new DateTimeImmutable($query->startDate);
|
||||
$endDate = new DateTimeImmutable($query->endDate);
|
||||
$oneDay = new DateInterval('P1D');
|
||||
|
||||
$blockedDates = [];
|
||||
$current = $startDate;
|
||||
|
||||
while ($current <= $endDate) {
|
||||
$dayOfWeek = (int) $current->format('N');
|
||||
$dateStr = $current->format('Y-m-d');
|
||||
|
||||
if ($dayOfWeek >= 6) {
|
||||
$blockedDates[] = new BlockedDateDto(
|
||||
date: $dateStr,
|
||||
reason: $dayOfWeek === 6 ? 'Samedi' : 'Dimanche',
|
||||
type: 'weekend',
|
||||
);
|
||||
} elseif ($calendar !== null) {
|
||||
$entry = $calendar->trouverEntreePourDate($current);
|
||||
|
||||
if ($entry !== null) {
|
||||
$blockedDates[] = new BlockedDateDto(
|
||||
date: $dateStr,
|
||||
reason: $entry->label,
|
||||
type: $entry->type->value,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$current = $current->add($oneDay);
|
||||
}
|
||||
|
||||
return $blockedDates;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Query\GetBlockedDates;
|
||||
|
||||
final readonly class GetBlockedDatesQuery
|
||||
{
|
||||
public function __construct(
|
||||
public string $tenantId,
|
||||
public string $academicYearId,
|
||||
public string $startDate,
|
||||
public string $endDate,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Query\GetScheduleSlots;
|
||||
|
||||
use App\Administration\Domain\Model\SchoolClass\ClassId;
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Domain\Model\Schedule\ScheduleSlot;
|
||||
use App\Scolarite\Domain\Repository\ScheduleSlotRepository;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
|
||||
use function array_filter;
|
||||
use function array_map;
|
||||
use function array_values;
|
||||
|
||||
use Ramsey\Uuid\Exception\InvalidUuidStringException;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
#[AsMessageHandler(bus: 'query.bus')]
|
||||
final readonly class GetScheduleSlotsHandler
|
||||
{
|
||||
public function __construct(
|
||||
private ScheduleSlotRepository $repository,
|
||||
) {
|
||||
}
|
||||
|
||||
/** @return array<ScheduleSlotDto> */
|
||||
public function __invoke(GetScheduleSlotsQuery $query): array
|
||||
{
|
||||
try {
|
||||
$tenantId = TenantId::fromString($query->tenantId);
|
||||
|
||||
if ($query->classId !== null) {
|
||||
$slots = $this->repository->findByClass(ClassId::fromString($query->classId), $tenantId);
|
||||
|
||||
if ($query->teacherId !== null) {
|
||||
$teacherId = UserId::fromString($query->teacherId);
|
||||
$slots = array_values(array_filter(
|
||||
$slots,
|
||||
static fn (ScheduleSlot $slot) => $slot->teacherId->equals($teacherId),
|
||||
));
|
||||
}
|
||||
} elseif ($query->teacherId !== null) {
|
||||
$slots = $this->repository->findByTeacher(UserId::fromString($query->teacherId), $tenantId);
|
||||
} else {
|
||||
$slots = [];
|
||||
}
|
||||
} catch (InvalidUuidStringException) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_map(ScheduleSlotDto::fromDomain(...), $slots);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Query\GetScheduleSlots;
|
||||
|
||||
final readonly class GetScheduleSlotsQuery
|
||||
{
|
||||
public function __construct(
|
||||
public string $tenantId,
|
||||
public ?string $classId = null,
|
||||
public ?string $teacherId = null,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Query\GetScheduleSlots;
|
||||
|
||||
use App\Scolarite\Domain\Model\Schedule\ScheduleSlot;
|
||||
use DateTimeImmutable;
|
||||
|
||||
final readonly class ScheduleSlotDto
|
||||
{
|
||||
public function __construct(
|
||||
public string $id,
|
||||
public string $classId,
|
||||
public string $subjectId,
|
||||
public string $teacherId,
|
||||
public int $dayOfWeek,
|
||||
public string $startTime,
|
||||
public string $endTime,
|
||||
public ?string $room,
|
||||
public bool $isRecurring,
|
||||
public DateTimeImmutable $createdAt,
|
||||
public DateTimeImmutable $updatedAt,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function fromDomain(ScheduleSlot $slot): self
|
||||
{
|
||||
return new self(
|
||||
id: (string) $slot->id,
|
||||
classId: (string) $slot->classId,
|
||||
subjectId: (string) $slot->subjectId,
|
||||
teacherId: (string) $slot->teacherId,
|
||||
dayOfWeek: $slot->dayOfWeek->value,
|
||||
startTime: $slot->timeSlot->startTime,
|
||||
endTime: $slot->timeSlot->endTime,
|
||||
room: $slot->room,
|
||||
isRecurring: $slot->isRecurring,
|
||||
createdAt: $slot->createdAt,
|
||||
updatedAt: $slot->updatedAt,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user