Lorsqu'un super-admin crée un établissement via l'interface, le système doit automatiquement créer la base tenant, exécuter les migrations, créer le premier utilisateur admin et envoyer l'invitation — le tout de manière asynchrone pour ne pas bloquer la réponse HTTP. Ce mécanisme rend chaque établissement opérationnel dès sa création sans intervention manuelle sur l'infrastructure.
69 lines
1.9 KiB
PHP
69 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Scolarite\Application\Query\GetStudentProgression;
|
|
|
|
use App\Scolarite\Application\Port\TeacherStatisticsReader;
|
|
use App\Scolarite\Domain\Service\TeacherStatisticsCalculator;
|
|
|
|
use function array_map;
|
|
use function array_values;
|
|
|
|
use DateTimeImmutable;
|
|
|
|
use function sprintf;
|
|
|
|
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
|
|
|
#[AsMessageHandler(bus: 'query.bus')]
|
|
final readonly class GetStudentProgressionHandler
|
|
{
|
|
public function __construct(
|
|
private TeacherStatisticsReader $reader,
|
|
private TeacherStatisticsCalculator $calculator,
|
|
) {
|
|
}
|
|
|
|
public function __invoke(GetStudentProgressionQuery $query): StudentProgressionDto
|
|
{
|
|
$now = new DateTimeImmutable();
|
|
$month = (int) $now->format('n');
|
|
$yearStart = $month >= 9 ? (int) $now->format('Y') : (int) $now->format('Y') - 1;
|
|
$academicYearStart = sprintf('%d-09-01', $yearStart);
|
|
$academicYearEnd = sprintf('%d-08-31', $yearStart + 1);
|
|
|
|
$history = $this->reader->studentGradeHistory(
|
|
$query->studentId,
|
|
$query->subjectId,
|
|
$query->classId,
|
|
$query->teacherId,
|
|
$query->tenantId,
|
|
$academicYearStart,
|
|
$academicYearEnd,
|
|
);
|
|
|
|
$grades = array_map(
|
|
static fn (array $row) => new GradePointDto(
|
|
date: $row['date'],
|
|
value: $row['value'],
|
|
evaluationTitle: $row['evaluationTitle'],
|
|
),
|
|
$history,
|
|
);
|
|
|
|
$points = array_values(array_map(
|
|
static fn (int $i, GradePointDto $g) => [$i + 1, $g->value],
|
|
array_keys($grades),
|
|
$grades,
|
|
));
|
|
|
|
$trendLine = $this->calculator->calculateTrendLine($points);
|
|
|
|
return new StudentProgressionDto(
|
|
grades: $grades,
|
|
trendLine: $trendLine,
|
|
);
|
|
}
|
|
}
|