feat: Calculer automatiquement les moyennes après chaque saisie de notes
Les enseignants ont besoin de moyennes à jour immédiatement après la publication ou modification des notes, sans attendre un batch nocturne. Le système recalcule via Domain Events synchrones : statistiques d'évaluation (min/max/moyenne/médiane), moyennes matières pondérées (normalisation /20), et moyenne générale par élève. Les résultats sont stockés dans des tables dénormalisées avec cache Redis (TTL 5 min). Trois endpoints API exposent les données avec contrôle d'accès par rôle. Une commande console permet le backfill des données historiques au déploiement.
This commit is contained in:
@@ -39,6 +39,11 @@ framework:
|
||||
adapter: cache.adapter.filesystem
|
||||
default_lifetime: 604800 # 7 jours
|
||||
|
||||
# Pool dédié aux moyennes élèves et statistiques (5 min TTL)
|
||||
student_averages.cache:
|
||||
adapter: cache.adapter.filesystem
|
||||
default_lifetime: 300 # 5 minutes
|
||||
|
||||
# Pool dédié au cache des requêtes paginées (1h TTL, tag-aware)
|
||||
paginated_queries.cache:
|
||||
adapter: cache.adapter.filesystem
|
||||
@@ -79,6 +84,10 @@ when@test:
|
||||
adapter: cache.adapter.redis
|
||||
provider: '%env(REDIS_URL)%'
|
||||
default_lifetime: 604800
|
||||
student_averages.cache:
|
||||
adapter: cache.adapter.redis
|
||||
provider: '%env(REDIS_URL)%'
|
||||
default_lifetime: 300
|
||||
paginated_queries.cache:
|
||||
adapter: cache.adapter.redis_tag_aware
|
||||
provider: '%env(REDIS_URL)%'
|
||||
@@ -120,6 +129,10 @@ when@prod:
|
||||
adapter: cache.adapter.redis
|
||||
provider: '%env(REDIS_URL)%'
|
||||
default_lifetime: 604800 # 7 jours
|
||||
student_averages.cache:
|
||||
adapter: cache.adapter.redis
|
||||
provider: '%env(REDIS_URL)%'
|
||||
default_lifetime: 300 # 5 minutes
|
||||
paginated_queries.cache:
|
||||
adapter: cache.adapter.redis_tag_aware
|
||||
provider: '%env(REDIS_URL)%'
|
||||
|
||||
@@ -265,9 +265,60 @@ services:
|
||||
App\Scolarite\Domain\Repository\GradeRepository:
|
||||
alias: App\Scolarite\Infrastructure\Persistence\Doctrine\DoctrineGradeRepository
|
||||
|
||||
App\Scolarite\Domain\Repository\AppreciationTemplateRepository:
|
||||
alias: App\Scolarite\Infrastructure\Persistence\Doctrine\DoctrineAppreciationTemplateRepository
|
||||
|
||||
App\Scolarite\Application\Port\EvaluationGradesChecker:
|
||||
alias: App\Scolarite\Infrastructure\Service\NoGradesEvaluationGradesChecker
|
||||
|
||||
# Competency repositories (Story 6.5 - Mode compétences)
|
||||
App\Scolarite\Domain\Repository\CompetencyFrameworkRepository:
|
||||
alias: App\Scolarite\Infrastructure\Persistence\Doctrine\DoctrineCompetencyFrameworkRepository
|
||||
|
||||
App\Scolarite\Domain\Repository\CompetencyRepository:
|
||||
alias: App\Scolarite\Infrastructure\Persistence\Doctrine\DoctrineCompetencyRepository
|
||||
|
||||
App\Scolarite\Domain\Repository\CompetencyEvaluationRepository:
|
||||
alias: App\Scolarite\Infrastructure\Persistence\Doctrine\DoctrineCompetencyEvaluationRepository
|
||||
|
||||
App\Scolarite\Domain\Repository\StudentCompetencyResultRepository:
|
||||
alias: App\Scolarite\Infrastructure\Persistence\Doctrine\DoctrineStudentCompetencyResultRepository
|
||||
|
||||
App\Scolarite\Domain\Repository\CustomCompetencyLevelRepository:
|
||||
alias: App\Scolarite\Infrastructure\Persistence\Doctrine\DoctrineCustomCompetencyLevelRepository
|
||||
|
||||
# Averages (Story 6.3 - Calcul automatique des moyennes)
|
||||
App\Scolarite\Domain\Service\AverageCalculator:
|
||||
autowire: true
|
||||
|
||||
App\Scolarite\Application\Service\RecalculerMoyennesService:
|
||||
autowire: true
|
||||
|
||||
App\Scolarite\Application\Port\PeriodFinder:
|
||||
alias: App\Scolarite\Infrastructure\Service\DoctrinePeriodFinder
|
||||
|
||||
App\Scolarite\Infrastructure\Persistence\Doctrine\DoctrineEvaluationStatisticsRepository:
|
||||
autowire: true
|
||||
|
||||
App\Scolarite\Infrastructure\Cache\CachingEvaluationStatisticsRepository:
|
||||
arguments:
|
||||
$inner: '@App\Scolarite\Infrastructure\Persistence\Doctrine\DoctrineEvaluationStatisticsRepository'
|
||||
$cache: '@student_averages.cache'
|
||||
|
||||
App\Scolarite\Domain\Repository\EvaluationStatisticsRepository:
|
||||
alias: App\Scolarite\Infrastructure\Cache\CachingEvaluationStatisticsRepository
|
||||
|
||||
App\Scolarite\Infrastructure\Persistence\Doctrine\DoctrineStudentAverageRepository:
|
||||
autowire: true
|
||||
|
||||
App\Scolarite\Infrastructure\Cache\CachingStudentAverageRepository:
|
||||
arguments:
|
||||
$inner: '@App\Scolarite\Infrastructure\Persistence\Doctrine\DoctrineStudentAverageRepository'
|
||||
$cache: '@student_averages.cache'
|
||||
|
||||
App\Scolarite\Domain\Repository\StudentAverageRepository:
|
||||
alias: App\Scolarite\Infrastructure\Cache\CachingStudentAverageRepository
|
||||
|
||||
# Super Admin Repositories (Story 2.10 - Multi-établissements)
|
||||
App\SuperAdmin\Domain\Repository\SuperAdminRepository:
|
||||
alias: App\SuperAdmin\Infrastructure\Persistence\Doctrine\DoctrineSuperAdminRepository
|
||||
|
||||
84
backend/migrations/Version20260329082334.php
Normal file
84
backend/migrations/Version20260329082334.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260329082334 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Création des tables dénormalisées pour les moyennes élèves et statistiques évaluations';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE student_averages (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
tenant_id UUID NOT NULL,
|
||||
student_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
subject_id UUID NOT NULL REFERENCES subjects(id) ON DELETE CASCADE,
|
||||
period_id UUID NOT NULL REFERENCES academic_periods(id) ON DELETE CASCADE,
|
||||
average DECIMAL(4,2),
|
||||
grade_count INT NOT NULL DEFAULT 0,
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (student_id, subject_id, period_id)
|
||||
)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE INDEX idx_student_averages_tenant ON student_averages(tenant_id)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE INDEX idx_student_averages_student ON student_averages(student_id)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE INDEX idx_student_averages_subject ON student_averages(subject_id)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE student_general_averages (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
tenant_id UUID NOT NULL,
|
||||
student_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
period_id UUID NOT NULL REFERENCES academic_periods(id) ON DELETE CASCADE,
|
||||
average DECIMAL(4,2),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (student_id, period_id)
|
||||
)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE INDEX idx_student_general_averages_tenant ON student_general_averages(tenant_id)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE INDEX idx_student_general_averages_student ON student_general_averages(student_id)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE evaluation_statistics (
|
||||
evaluation_id UUID PRIMARY KEY REFERENCES evaluations(id) ON DELETE CASCADE,
|
||||
average DECIMAL(5,2),
|
||||
min_grade DECIMAL(5,2),
|
||||
max_grade DECIMAL(5,2),
|
||||
median_grade DECIMAL(5,2),
|
||||
graded_count INT NOT NULL DEFAULT 0,
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
)
|
||||
SQL);
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP TABLE IF EXISTS evaluation_statistics');
|
||||
$this->addSql('DROP TABLE IF EXISTS student_general_averages');
|
||||
$this->addSql('DROP TABLE IF EXISTS student_averages');
|
||||
}
|
||||
}
|
||||
56
backend/migrations/Version20260331154510.php
Normal file
56
backend/migrations/Version20260331154510.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260331154510 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Ajout des appréciations sur les notes et table des modèles d\'appréciations enseignant';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE grades ADD COLUMN appreciation TEXT
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE grades ADD COLUMN appreciation_updated_at TIMESTAMPTZ
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE appreciation_templates (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
tenant_id UUID NOT NULL,
|
||||
teacher_id UUID NOT NULL REFERENCES users(id),
|
||||
title VARCHAR(100) NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
category VARCHAR(50),
|
||||
usage_count INT NOT NULL DEFAULT 0,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE INDEX idx_templates_teacher ON appreciation_templates(teacher_id)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE INDEX idx_templates_tenant ON appreciation_templates(tenant_id)
|
||||
SQL);
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP TABLE IF EXISTS appreciation_templates');
|
||||
$this->addSql('ALTER TABLE grades DROP COLUMN IF EXISTS appreciation_updated_at');
|
||||
$this->addSql('ALTER TABLE grades DROP COLUMN IF EXISTS appreciation');
|
||||
}
|
||||
}
|
||||
108
backend/migrations/Version20260402055321.php
Normal file
108
backend/migrations/Version20260402055321.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260402055321 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Tables pour le mode compétences : référentiels, compétences, niveaux personnalisables, évaluations par compétences et résultats élèves';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE competency_frameworks (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
tenant_id UUID NOT NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
is_default BOOLEAN NOT NULL DEFAULT false,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE INDEX idx_competency_frameworks_tenant ON competency_frameworks(tenant_id)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE competencies (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
framework_id UUID NOT NULL REFERENCES competency_frameworks(id) ON DELETE CASCADE,
|
||||
code VARCHAR(50) NOT NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
description TEXT,
|
||||
parent_id UUID REFERENCES competencies(id) ON DELETE SET NULL,
|
||||
sort_order INT NOT NULL DEFAULT 0
|
||||
)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE INDEX idx_competencies_framework ON competencies(framework_id)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE competency_levels (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
tenant_id UUID NOT NULL,
|
||||
code VARCHAR(20) NOT NULL,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
color VARCHAR(7),
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
UNIQUE (tenant_id, code)
|
||||
)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE INDEX idx_competency_levels_tenant ON competency_levels(tenant_id)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE competency_evaluations (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
evaluation_id UUID NOT NULL REFERENCES evaluations(id) ON DELETE CASCADE,
|
||||
competency_id UUID NOT NULL REFERENCES competencies(id) ON DELETE CASCADE,
|
||||
UNIQUE (evaluation_id, competency_id)
|
||||
)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE INDEX idx_competency_evaluations_evaluation ON competency_evaluations(evaluation_id)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE student_competency_results (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
tenant_id UUID NOT NULL,
|
||||
competency_evaluation_id UUID NOT NULL REFERENCES competency_evaluations(id) ON DELETE CASCADE,
|
||||
student_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
level_code VARCHAR(20) NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (competency_evaluation_id, student_id)
|
||||
)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE INDEX idx_competency_results_student ON student_competency_results(student_id)
|
||||
SQL);
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE INDEX idx_competency_results_tenant ON student_competency_results(tenant_id)
|
||||
SQL);
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP TABLE IF EXISTS student_competency_results');
|
||||
$this->addSql('DROP TABLE IF EXISTS competency_evaluations');
|
||||
$this->addSql('DROP TABLE IF EXISTS competency_levels');
|
||||
$this->addSql('DROP TABLE IF EXISTS competencies');
|
||||
$this->addSql('DROP TABLE IF EXISTS competency_frameworks');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Command\CreateAppreciationTemplate;
|
||||
|
||||
final readonly class CreateAppreciationTemplateCommand
|
||||
{
|
||||
public function __construct(
|
||||
public string $tenantId,
|
||||
public string $teacherId,
|
||||
public string $title,
|
||||
public string $content,
|
||||
public ?string $category,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Command\CreateAppreciationTemplate;
|
||||
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Domain\Exception\CategorieAppreciationInvalideException;
|
||||
use App\Scolarite\Domain\Model\Grade\AppreciationCategory;
|
||||
use App\Scolarite\Domain\Model\Grade\AppreciationTemplate;
|
||||
use App\Scolarite\Domain\Repository\AppreciationTemplateRepository;
|
||||
use App\Shared\Domain\Clock;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
#[AsMessageHandler(bus: 'command.bus')]
|
||||
final readonly class CreateAppreciationTemplateHandler
|
||||
{
|
||||
public function __construct(
|
||||
private AppreciationTemplateRepository $templateRepository,
|
||||
private Clock $clock,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(CreateAppreciationTemplateCommand $command): AppreciationTemplate
|
||||
{
|
||||
$category = null;
|
||||
if ($command->category !== null) {
|
||||
$category = AppreciationCategory::tryFrom($command->category);
|
||||
if ($category === null) {
|
||||
throw CategorieAppreciationInvalideException::pourValeur($command->category);
|
||||
}
|
||||
}
|
||||
|
||||
$template = AppreciationTemplate::creer(
|
||||
tenantId: TenantId::fromString($command->tenantId),
|
||||
teacherId: UserId::fromString($command->teacherId),
|
||||
title: $command->title,
|
||||
content: $command->content,
|
||||
category: $category,
|
||||
now: $this->clock->now(),
|
||||
);
|
||||
|
||||
$this->templateRepository->save($template);
|
||||
|
||||
return $template;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Command\DeleteAppreciationTemplate;
|
||||
|
||||
final readonly class DeleteAppreciationTemplateCommand
|
||||
{
|
||||
public function __construct(
|
||||
public string $tenantId,
|
||||
public string $teacherId,
|
||||
public string $templateId,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Command\DeleteAppreciationTemplate;
|
||||
|
||||
use App\Scolarite\Domain\Exception\AppreciationTemplateNonTrouveeException;
|
||||
use App\Scolarite\Domain\Exception\NonProprietaireDuModeleException;
|
||||
use App\Scolarite\Domain\Model\Grade\AppreciationTemplateId;
|
||||
use App\Scolarite\Domain\Repository\AppreciationTemplateRepository;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
#[AsMessageHandler(bus: 'command.bus')]
|
||||
final readonly class DeleteAppreciationTemplateHandler
|
||||
{
|
||||
public function __construct(
|
||||
private AppreciationTemplateRepository $templateRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(DeleteAppreciationTemplateCommand $command): void
|
||||
{
|
||||
$tenantId = TenantId::fromString($command->tenantId);
|
||||
$templateId = AppreciationTemplateId::fromString($command->templateId);
|
||||
|
||||
$template = $this->templateRepository->findById($templateId, $tenantId);
|
||||
|
||||
if ($template === null) {
|
||||
throw AppreciationTemplateNonTrouveeException::withId($templateId);
|
||||
}
|
||||
|
||||
if ((string) $template->teacherId !== $command->teacherId) {
|
||||
throw NonProprietaireDuModeleException::withId($templateId);
|
||||
}
|
||||
|
||||
$this->templateRepository->delete($templateId, $tenantId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Command\LinkCompetenciesToEvaluation;
|
||||
|
||||
final readonly class LinkCompetenciesToEvaluationCommand
|
||||
{
|
||||
/**
|
||||
* @param array<string> $competencyIds
|
||||
*/
|
||||
public function __construct(
|
||||
public string $tenantId,
|
||||
public string $evaluationId,
|
||||
public string $teacherId,
|
||||
public array $competencyIds,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Command\LinkCompetenciesToEvaluation;
|
||||
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Domain\Exception\NonProprietaireDeLEvaluationException;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyEvaluation;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyId;
|
||||
use App\Scolarite\Domain\Model\Evaluation\EvaluationId;
|
||||
use App\Scolarite\Domain\Repository\CompetencyEvaluationRepository;
|
||||
use App\Scolarite\Domain\Repository\CompetencyRepository;
|
||||
use App\Scolarite\Domain\Repository\EvaluationRepository;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use DomainException;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
#[AsMessageHandler(bus: 'command.bus')]
|
||||
final readonly class LinkCompetenciesToEvaluationHandler
|
||||
{
|
||||
public function __construct(
|
||||
private EvaluationRepository $evaluationRepository,
|
||||
private CompetencyRepository $competencyRepository,
|
||||
private CompetencyEvaluationRepository $competencyEvaluationRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
/** @return array<CompetencyEvaluation> */
|
||||
public function __invoke(LinkCompetenciesToEvaluationCommand $command): array
|
||||
{
|
||||
$tenantId = TenantId::fromString($command->tenantId);
|
||||
$evaluationId = EvaluationId::fromString($command->evaluationId);
|
||||
$teacherId = UserId::fromString($command->teacherId);
|
||||
|
||||
$evaluation = $this->evaluationRepository->get($evaluationId, $tenantId);
|
||||
|
||||
if ((string) $evaluation->teacherId !== (string) $teacherId) {
|
||||
throw NonProprietaireDeLEvaluationException::withId($evaluationId);
|
||||
}
|
||||
|
||||
$existingCes = $this->competencyEvaluationRepository->findByEvaluation($evaluationId);
|
||||
$existingByCompetency = [];
|
||||
foreach ($existingCes as $existing) {
|
||||
$existingByCompetency[(string) $existing->competencyId] = $existing;
|
||||
}
|
||||
|
||||
$linked = [];
|
||||
|
||||
foreach ($command->competencyIds as $competencyIdStr) {
|
||||
$competencyId = CompetencyId::fromString($competencyIdStr);
|
||||
|
||||
// Skip already linked competencies
|
||||
if (isset($existingByCompetency[$competencyIdStr])) {
|
||||
$linked[] = $existingByCompetency[$competencyIdStr];
|
||||
continue;
|
||||
}
|
||||
|
||||
$competency = $this->competencyRepository->findById($competencyId, $tenantId);
|
||||
if ($competency === null) {
|
||||
throw new DomainException('Compétence non trouvée : ' . $competencyIdStr);
|
||||
}
|
||||
|
||||
$ce = CompetencyEvaluation::creer(
|
||||
evaluationId: $evaluationId,
|
||||
competencyId: $competencyId,
|
||||
);
|
||||
|
||||
$this->competencyEvaluationRepository->save($ce);
|
||||
$linked[] = $ce;
|
||||
}
|
||||
|
||||
return $linked;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Command\SaveAppreciation;
|
||||
|
||||
final readonly class SaveAppreciationCommand
|
||||
{
|
||||
public function __construct(
|
||||
public string $tenantId,
|
||||
public string $gradeId,
|
||||
public string $teacherId,
|
||||
public ?string $appreciation,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Command\SaveAppreciation;
|
||||
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Domain\Exception\NonProprietaireDeLEvaluationException;
|
||||
use App\Scolarite\Domain\Model\Grade\Grade;
|
||||
use App\Scolarite\Domain\Model\Grade\GradeId;
|
||||
use App\Scolarite\Domain\Repository\EvaluationRepository;
|
||||
use App\Scolarite\Domain\Repository\GradeRepository;
|
||||
use App\Shared\Domain\Clock;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
#[AsMessageHandler(bus: 'command.bus')]
|
||||
final readonly class SaveAppreciationHandler
|
||||
{
|
||||
public function __construct(
|
||||
private EvaluationRepository $evaluationRepository,
|
||||
private GradeRepository $gradeRepository,
|
||||
private Clock $clock,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(SaveAppreciationCommand $command): Grade
|
||||
{
|
||||
$tenantId = TenantId::fromString($command->tenantId);
|
||||
$gradeId = GradeId::fromString($command->gradeId);
|
||||
$teacherId = UserId::fromString($command->teacherId);
|
||||
|
||||
$grade = $this->gradeRepository->get($gradeId, $tenantId);
|
||||
|
||||
$evaluation = $this->evaluationRepository->get($grade->evaluationId, $tenantId);
|
||||
|
||||
if ((string) $evaluation->teacherId !== (string) $teacherId) {
|
||||
throw NonProprietaireDeLEvaluationException::withId($grade->evaluationId);
|
||||
}
|
||||
|
||||
$grade->saisirAppreciation($command->appreciation, $this->clock->now());
|
||||
$this->gradeRepository->saveAppreciation($grade);
|
||||
|
||||
return $grade;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Command\SaveCompetencyResults;
|
||||
|
||||
final readonly class SaveCompetencyResultsCommand
|
||||
{
|
||||
/**
|
||||
* @param array<array{studentId: string, competencyEvaluationId: string, levelCode: ?string}> $results
|
||||
*/
|
||||
public function __construct(
|
||||
public string $tenantId,
|
||||
public string $evaluationId,
|
||||
public string $teacherId,
|
||||
public array $results,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Command\SaveCompetencyResults;
|
||||
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Application\Port\ClassStudentsReader;
|
||||
use App\Scolarite\Domain\Exception\NonProprietaireDeLEvaluationException;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyEvaluationId;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyLevel;
|
||||
use App\Scolarite\Domain\Model\Competency\StudentCompetencyResult;
|
||||
use App\Scolarite\Domain\Model\Evaluation\EvaluationId;
|
||||
use App\Scolarite\Domain\Repository\CompetencyEvaluationRepository;
|
||||
use App\Scolarite\Domain\Repository\CustomCompetencyLevelRepository;
|
||||
use App\Scolarite\Domain\Repository\EvaluationRepository;
|
||||
use App\Scolarite\Domain\Repository\StudentCompetencyResultRepository;
|
||||
use App\Shared\Domain\Clock;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
|
||||
use function array_column;
|
||||
use function array_map;
|
||||
|
||||
use DomainException;
|
||||
|
||||
use function in_array;
|
||||
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
#[AsMessageHandler(bus: 'command.bus')]
|
||||
final readonly class SaveCompetencyResultsHandler
|
||||
{
|
||||
public function __construct(
|
||||
private EvaluationRepository $evaluationRepository,
|
||||
private CompetencyEvaluationRepository $competencyEvaluationRepository,
|
||||
private StudentCompetencyResultRepository $resultRepository,
|
||||
private CustomCompetencyLevelRepository $customLevelRepository,
|
||||
private ClassStudentsReader $classStudentsReader,
|
||||
private Clock $clock,
|
||||
) {
|
||||
}
|
||||
|
||||
/** @return array<StudentCompetencyResult> */
|
||||
public function __invoke(SaveCompetencyResultsCommand $command): array
|
||||
{
|
||||
$tenantId = TenantId::fromString($command->tenantId);
|
||||
$evaluationId = EvaluationId::fromString($command->evaluationId);
|
||||
$teacherId = UserId::fromString($command->teacherId);
|
||||
$now = $this->clock->now();
|
||||
|
||||
$evaluation = $this->evaluationRepository->get($evaluationId, $tenantId);
|
||||
|
||||
if ((string) $evaluation->teacherId !== (string) $teacherId) {
|
||||
throw NonProprietaireDeLEvaluationException::withId($evaluationId);
|
||||
}
|
||||
|
||||
// Build set of valid student IDs in the class
|
||||
$classStudents = $this->classStudentsReader->studentsInClass((string) $evaluation->classId, $tenantId);
|
||||
$validStudentIds = array_column($classStudents, 'id');
|
||||
|
||||
// Build set of valid competencyEvaluationIds for this evaluation
|
||||
$validCeIds = $this->competencyEvaluationRepository->findByEvaluation($evaluationId);
|
||||
$validCeIdSet = array_map(static fn ($ce) => (string) $ce->id, $validCeIds);
|
||||
|
||||
// Build set of valid level codes (custom or standard)
|
||||
$customLevels = $this->customLevelRepository->findByTenant($tenantId);
|
||||
$validLevelCodes = $customLevels !== []
|
||||
? array_column(array_map(static fn ($l) => ['code' => $l->code], $customLevels), 'code')
|
||||
: array_map(static fn ($l) => $l->value, CompetencyLevel::cases());
|
||||
|
||||
$savedResults = [];
|
||||
|
||||
foreach ($command->results as $resultInput) {
|
||||
$studentId = UserId::fromString($resultInput['studentId']);
|
||||
$ceId = CompetencyEvaluationId::fromString($resultInput['competencyEvaluationId']);
|
||||
/** @var ?string $levelCode */
|
||||
$levelCode = $resultInput['levelCode'] ?? null;
|
||||
|
||||
if (!in_array($resultInput['studentId'], $validStudentIds, true)) {
|
||||
throw new DomainException('L\'élève ne fait pas partie de la classe de cette évaluation.');
|
||||
}
|
||||
|
||||
if (!in_array((string) $ceId, $validCeIdSet, true)) {
|
||||
throw new DomainException('La compétence évaluée ne fait pas partie de cette évaluation.');
|
||||
}
|
||||
|
||||
$existing = $this->resultRepository->findByCompetencyEvaluationAndStudent(
|
||||
$ceId,
|
||||
$studentId,
|
||||
$tenantId,
|
||||
);
|
||||
|
||||
// Toggle OFF: delete existing result
|
||||
if ($levelCode === null) {
|
||||
if ($existing !== null) {
|
||||
$this->resultRepository->delete($existing);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!in_array($levelCode, $validLevelCodes, true)) {
|
||||
throw new DomainException('Code de niveau invalide : ' . $levelCode);
|
||||
}
|
||||
|
||||
if ($existing !== null) {
|
||||
$existing->modifier(
|
||||
levelCode: $levelCode,
|
||||
now: $now,
|
||||
);
|
||||
$this->resultRepository->save($existing);
|
||||
$savedResults[] = $existing;
|
||||
} else {
|
||||
$result = StudentCompetencyResult::saisir(
|
||||
tenantId: $tenantId,
|
||||
competencyEvaluationId: $ceId,
|
||||
studentId: $studentId,
|
||||
levelCode: $levelCode,
|
||||
now: $now,
|
||||
);
|
||||
$this->resultRepository->save($result);
|
||||
$savedResults[] = $result;
|
||||
}
|
||||
}
|
||||
|
||||
return $savedResults;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Command\UpdateAppreciationTemplate;
|
||||
|
||||
final readonly class UpdateAppreciationTemplateCommand
|
||||
{
|
||||
public function __construct(
|
||||
public string $tenantId,
|
||||
public string $teacherId,
|
||||
public string $templateId,
|
||||
public string $title,
|
||||
public string $content,
|
||||
public ?string $category,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Command\UpdateAppreciationTemplate;
|
||||
|
||||
use App\Scolarite\Domain\Exception\AppreciationTemplateNonTrouveeException;
|
||||
use App\Scolarite\Domain\Exception\CategorieAppreciationInvalideException;
|
||||
use App\Scolarite\Domain\Exception\NonProprietaireDuModeleException;
|
||||
use App\Scolarite\Domain\Model\Grade\AppreciationCategory;
|
||||
use App\Scolarite\Domain\Model\Grade\AppreciationTemplate;
|
||||
use App\Scolarite\Domain\Model\Grade\AppreciationTemplateId;
|
||||
use App\Scolarite\Domain\Repository\AppreciationTemplateRepository;
|
||||
use App\Shared\Domain\Clock;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
#[AsMessageHandler(bus: 'command.bus')]
|
||||
final readonly class UpdateAppreciationTemplateHandler
|
||||
{
|
||||
public function __construct(
|
||||
private AppreciationTemplateRepository $templateRepository,
|
||||
private Clock $clock,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(UpdateAppreciationTemplateCommand $command): AppreciationTemplate
|
||||
{
|
||||
$tenantId = TenantId::fromString($command->tenantId);
|
||||
$templateId = AppreciationTemplateId::fromString($command->templateId);
|
||||
|
||||
$template = $this->templateRepository->findById($templateId, $tenantId);
|
||||
|
||||
if ($template === null) {
|
||||
throw AppreciationTemplateNonTrouveeException::withId($templateId);
|
||||
}
|
||||
|
||||
if ((string) $template->teacherId !== $command->teacherId) {
|
||||
throw NonProprietaireDuModeleException::withId($templateId);
|
||||
}
|
||||
|
||||
$category = null;
|
||||
if ($command->category !== null) {
|
||||
$category = AppreciationCategory::tryFrom($command->category);
|
||||
if ($category === null) {
|
||||
throw CategorieAppreciationInvalideException::pourValeur($command->category);
|
||||
}
|
||||
}
|
||||
|
||||
$template->modifier(
|
||||
title: $command->title,
|
||||
content: $command->content,
|
||||
category: $category,
|
||||
now: $this->clock->now(),
|
||||
);
|
||||
|
||||
$this->templateRepository->save($template);
|
||||
|
||||
return $template;
|
||||
}
|
||||
}
|
||||
13
backend/src/Scolarite/Application/Port/PeriodFinder.php
Normal file
13
backend/src/Scolarite/Application/Port/PeriodFinder.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Port;
|
||||
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use DateTimeImmutable;
|
||||
|
||||
interface PeriodFinder
|
||||
{
|
||||
public function findForDate(DateTimeImmutable $date, TenantId $tenantId): ?PeriodInfo;
|
||||
}
|
||||
17
backend/src/Scolarite/Application/Port/PeriodInfo.php
Normal file
17
backend/src/Scolarite/Application/Port/PeriodInfo.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Port;
|
||||
|
||||
use DateTimeImmutable;
|
||||
|
||||
final readonly class PeriodInfo
|
||||
{
|
||||
public function __construct(
|
||||
public string $periodId,
|
||||
public DateTimeImmutable $startDate,
|
||||
public DateTimeImmutable $endDate,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Application\Service;
|
||||
|
||||
use App\Administration\Domain\Model\SchoolClass\ClassId;
|
||||
use App\Administration\Domain\Model\Subject\SubjectId;
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Application\Port\PeriodFinder;
|
||||
use App\Scolarite\Application\Port\PeriodInfo;
|
||||
use App\Scolarite\Domain\Model\Evaluation\Evaluation;
|
||||
use App\Scolarite\Domain\Model\Evaluation\EvaluationId;
|
||||
use App\Scolarite\Domain\Model\Grade\Grade;
|
||||
use App\Scolarite\Domain\Model\Grade\GradeStatus;
|
||||
use App\Scolarite\Domain\Repository\EvaluationRepository;
|
||||
use App\Scolarite\Domain\Repository\EvaluationStatisticsRepository;
|
||||
use App\Scolarite\Domain\Repository\GradeRepository;
|
||||
use App\Scolarite\Domain\Repository\StudentAverageRepository;
|
||||
use App\Scolarite\Domain\Service\AverageCalculator;
|
||||
use App\Scolarite\Domain\Service\GradeEntry;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
|
||||
use function array_map;
|
||||
use function count;
|
||||
|
||||
final readonly class RecalculerMoyennesService
|
||||
{
|
||||
public function __construct(
|
||||
private EvaluationRepository $evaluationRepository,
|
||||
private GradeRepository $gradeRepository,
|
||||
private EvaluationStatisticsRepository $evaluationStatisticsRepository,
|
||||
private StudentAverageRepository $studentAverageRepository,
|
||||
private PeriodFinder $periodFinder,
|
||||
private AverageCalculator $calculator,
|
||||
) {
|
||||
}
|
||||
|
||||
public function recalculerStatistiquesEvaluation(EvaluationId $evaluationId, TenantId $tenantId): void
|
||||
{
|
||||
$grades = $this->gradeRepository->findByEvaluation($evaluationId, $tenantId);
|
||||
|
||||
$gradedValues = [];
|
||||
|
||||
foreach ($grades as $g) {
|
||||
if ($g->status === GradeStatus::GRADED && $g->value !== null) {
|
||||
$gradedValues[] = $g->value->value;
|
||||
}
|
||||
}
|
||||
|
||||
$stats = $this->calculator->calculateClassStatistics($gradedValues);
|
||||
$this->evaluationStatisticsRepository->save($evaluationId, $stats);
|
||||
}
|
||||
|
||||
public function recalculerMoyenneEleve(
|
||||
UserId $studentId,
|
||||
SubjectId $subjectId,
|
||||
ClassId $classId,
|
||||
PeriodInfo $period,
|
||||
TenantId $tenantId,
|
||||
): void {
|
||||
$evaluations = $this->evaluationRepository->findWithPublishedGradesBySubjectAndClassInDateRange(
|
||||
$subjectId,
|
||||
$classId,
|
||||
$period->startDate,
|
||||
$period->endDate,
|
||||
$tenantId,
|
||||
);
|
||||
|
||||
$evalIds = array_map(static fn (Evaluation $e) => $e->id, $evaluations);
|
||||
$allGradesByEval = $this->gradeRepository->findByEvaluations($evalIds, $tenantId);
|
||||
|
||||
$entries = [];
|
||||
|
||||
foreach ($evaluations as $eval) {
|
||||
/** @var list<Grade> $evalGrades */
|
||||
$evalGrades = $allGradesByEval[(string) $eval->id] ?? [];
|
||||
|
||||
foreach ($evalGrades as $grade) {
|
||||
if ($grade->studentId->equals($studentId)
|
||||
&& $grade->status === GradeStatus::GRADED
|
||||
&& $grade->value !== null
|
||||
) {
|
||||
$entries[] = new GradeEntry(
|
||||
value: $grade->value->value,
|
||||
gradeScale: $eval->gradeScale,
|
||||
coefficient: $eval->coefficient,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$subjectAverage = $this->calculator->calculateSubjectAverage($entries);
|
||||
|
||||
if ($subjectAverage !== null) {
|
||||
$this->studentAverageRepository->saveSubjectAverage(
|
||||
$tenantId,
|
||||
$studentId,
|
||||
$subjectId,
|
||||
$period->periodId,
|
||||
$subjectAverage,
|
||||
count($entries),
|
||||
);
|
||||
} else {
|
||||
$this->studentAverageRepository->deleteSubjectAverage(
|
||||
$studentId,
|
||||
$subjectId,
|
||||
$period->periodId,
|
||||
$tenantId,
|
||||
);
|
||||
}
|
||||
|
||||
// Moyenne générale
|
||||
$allSubjectAverages = $this->studentAverageRepository->findSubjectAveragesForStudent(
|
||||
$studentId,
|
||||
$period->periodId,
|
||||
$tenantId,
|
||||
);
|
||||
|
||||
$generalAverage = $this->calculator->calculateGeneralAverage($allSubjectAverages);
|
||||
|
||||
if ($generalAverage !== null) {
|
||||
$this->studentAverageRepository->saveGeneralAverage(
|
||||
$tenantId,
|
||||
$studentId,
|
||||
$period->periodId,
|
||||
$generalAverage,
|
||||
);
|
||||
} else {
|
||||
$this->studentAverageRepository->deleteGeneralAverage(
|
||||
$studentId,
|
||||
$period->periodId,
|
||||
$tenantId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function recalculerTousElevesPourEvaluation(EvaluationId $evaluationId, TenantId $tenantId): void
|
||||
{
|
||||
$evaluation = $this->evaluationRepository->findById($evaluationId, $tenantId);
|
||||
|
||||
if ($evaluation === null || !$evaluation->notesPubliees()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$period = $this->periodFinder->findForDate($evaluation->evaluationDate, $tenantId);
|
||||
|
||||
if ($period === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$grades = $this->gradeRepository->findByEvaluation($evaluationId, $tenantId);
|
||||
$studentIds = [];
|
||||
|
||||
foreach ($grades as $g) {
|
||||
$studentIds[(string) $g->studentId] = $g->studentId;
|
||||
}
|
||||
|
||||
foreach ($studentIds as $studentId) {
|
||||
$this->recalculerMoyenneEleve(
|
||||
$studentId,
|
||||
$evaluation->subjectId,
|
||||
$evaluation->classId,
|
||||
$period,
|
||||
$tenantId,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Event;
|
||||
|
||||
use App\Scolarite\Domain\Model\Competency\StudentCompetencyResultId;
|
||||
use App\Shared\Domain\DomainEvent;
|
||||
use DateTimeImmutable;
|
||||
use Override;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
|
||||
final readonly class ResultatCompetenceModifie implements DomainEvent
|
||||
{
|
||||
public function __construct(
|
||||
public StudentCompetencyResultId $resultId,
|
||||
public string $competencyEvaluationId,
|
||||
public string $studentId,
|
||||
public string $oldLevelCode,
|
||||
public string $newLevelCode,
|
||||
private DateTimeImmutable $occurredOn,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function occurredOn(): DateTimeImmutable
|
||||
{
|
||||
return $this->occurredOn;
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function aggregateId(): UuidInterface
|
||||
{
|
||||
return $this->resultId->value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Event;
|
||||
|
||||
use App\Scolarite\Domain\Model\Competency\StudentCompetencyResultId;
|
||||
use App\Shared\Domain\DomainEvent;
|
||||
use DateTimeImmutable;
|
||||
use Override;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
|
||||
final readonly class ResultatCompetenceSaisi implements DomainEvent
|
||||
{
|
||||
public function __construct(
|
||||
public StudentCompetencyResultId $resultId,
|
||||
public string $competencyEvaluationId,
|
||||
public string $studentId,
|
||||
public string $levelCode,
|
||||
private DateTimeImmutable $occurredOn,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function occurredOn(): DateTimeImmutable
|
||||
{
|
||||
return $this->occurredOn;
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function aggregateId(): UuidInterface
|
||||
{
|
||||
return $this->resultId->value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Exception;
|
||||
|
||||
use App\Scolarite\Domain\Model\Grade\AppreciationTemplateId;
|
||||
use DomainException;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
final class AppreciationTemplateNonTrouveeException extends DomainException
|
||||
{
|
||||
public static function withId(AppreciationTemplateId $id): self
|
||||
{
|
||||
return new self(sprintf(
|
||||
'Le modèle d\'appréciation avec l\'ID "%s" n\'a pas été trouvé.',
|
||||
$id,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Exception;
|
||||
|
||||
use DomainException;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
final class AppreciationTropLongueException extends DomainException
|
||||
{
|
||||
public static function depasseLimite(int $length, int $maxLength): self
|
||||
{
|
||||
return new self(sprintf(
|
||||
'L\'appréciation dépasse la limite de %d caractères (%d donnés).',
|
||||
$maxLength,
|
||||
$length,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Exception;
|
||||
|
||||
use DomainException;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
final class CategorieAppreciationInvalideException extends DomainException
|
||||
{
|
||||
public static function pourValeur(string $value): self
|
||||
{
|
||||
return new self(sprintf(
|
||||
'La catégorie d\'appréciation "%s" n\'est pas valide. Valeurs acceptées : positive, neutral, improvement.',
|
||||
$value,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -18,4 +18,13 @@ final class GradeNotFoundException extends DomainException
|
||||
$id,
|
||||
));
|
||||
}
|
||||
|
||||
public static function forStudent(string $studentId, string $evaluationId): self
|
||||
{
|
||||
return new self(sprintf(
|
||||
'Aucune note trouvée pour l\'élève "%s" dans l\'évaluation "%s".',
|
||||
$studentId,
|
||||
$evaluationId,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Exception;
|
||||
|
||||
use App\Scolarite\Domain\Model\Grade\AppreciationTemplateId;
|
||||
use DomainException;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
final class NonProprietaireDuModeleException extends DomainException
|
||||
{
|
||||
public static function withId(AppreciationTemplateId $id): self
|
||||
{
|
||||
return new self(sprintf(
|
||||
'Vous n\'êtes pas le propriétaire du modèle d\'appréciation "%s".',
|
||||
$id,
|
||||
));
|
||||
}
|
||||
}
|
||||
61
backend/src/Scolarite/Domain/Model/Competency/Competency.php
Normal file
61
backend/src/Scolarite/Domain/Model/Competency/Competency.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Model\Competency;
|
||||
|
||||
final class Competency
|
||||
{
|
||||
private function __construct(
|
||||
public private(set) CompetencyId $id,
|
||||
public private(set) CompetencyFrameworkId $frameworkId,
|
||||
public private(set) string $code,
|
||||
public private(set) string $name,
|
||||
public private(set) ?string $description,
|
||||
public private(set) ?CompetencyId $parentId,
|
||||
public private(set) int $sortOrder,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function creer(
|
||||
CompetencyFrameworkId $frameworkId,
|
||||
string $code,
|
||||
string $name,
|
||||
?string $description,
|
||||
?CompetencyId $parentId,
|
||||
int $sortOrder,
|
||||
): self {
|
||||
return new self(
|
||||
id: CompetencyId::generate(),
|
||||
frameworkId: $frameworkId,
|
||||
code: $code,
|
||||
name: $name,
|
||||
description: $description,
|
||||
parentId: $parentId,
|
||||
sortOrder: $sortOrder,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Pour usage Infrastructure uniquement
|
||||
*/
|
||||
public static function reconstitute(
|
||||
CompetencyId $id,
|
||||
CompetencyFrameworkId $frameworkId,
|
||||
string $code,
|
||||
string $name,
|
||||
?string $description,
|
||||
?CompetencyId $parentId,
|
||||
int $sortOrder,
|
||||
): self {
|
||||
return new self(
|
||||
id: $id,
|
||||
frameworkId: $frameworkId,
|
||||
code: $code,
|
||||
name: $name,
|
||||
description: $description,
|
||||
parentId: $parentId,
|
||||
sortOrder: $sortOrder,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Model\Competency;
|
||||
|
||||
use App\Scolarite\Domain\Model\Evaluation\EvaluationId;
|
||||
|
||||
final class CompetencyEvaluation
|
||||
{
|
||||
private function __construct(
|
||||
public private(set) CompetencyEvaluationId $id,
|
||||
public private(set) EvaluationId $evaluationId,
|
||||
public private(set) CompetencyId $competencyId,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function creer(
|
||||
EvaluationId $evaluationId,
|
||||
CompetencyId $competencyId,
|
||||
): self {
|
||||
return new self(
|
||||
id: CompetencyEvaluationId::generate(),
|
||||
evaluationId: $evaluationId,
|
||||
competencyId: $competencyId,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Pour usage Infrastructure uniquement
|
||||
*/
|
||||
public static function reconstitute(
|
||||
CompetencyEvaluationId $id,
|
||||
EvaluationId $evaluationId,
|
||||
CompetencyId $competencyId,
|
||||
): self {
|
||||
return new self(
|
||||
id: $id,
|
||||
evaluationId: $evaluationId,
|
||||
competencyId: $competencyId,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Model\Competency;
|
||||
|
||||
use App\Shared\Domain\EntityId;
|
||||
|
||||
final readonly class CompetencyEvaluationId extends EntityId
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Model\Competency;
|
||||
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use DateTimeImmutable;
|
||||
|
||||
final class CompetencyFramework
|
||||
{
|
||||
private function __construct(
|
||||
public private(set) CompetencyFrameworkId $id,
|
||||
public private(set) TenantId $tenantId,
|
||||
public private(set) string $name,
|
||||
public private(set) bool $isDefault,
|
||||
public private(set) DateTimeImmutable $createdAt,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function creer(
|
||||
TenantId $tenantId,
|
||||
string $name,
|
||||
bool $isDefault,
|
||||
DateTimeImmutable $now,
|
||||
): self {
|
||||
return new self(
|
||||
id: CompetencyFrameworkId::generate(),
|
||||
tenantId: $tenantId,
|
||||
name: $name,
|
||||
isDefault: $isDefault,
|
||||
createdAt: $now,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Pour usage Infrastructure uniquement
|
||||
*/
|
||||
public static function reconstitute(
|
||||
CompetencyFrameworkId $id,
|
||||
TenantId $tenantId,
|
||||
string $name,
|
||||
bool $isDefault,
|
||||
DateTimeImmutable $createdAt,
|
||||
): self {
|
||||
return new self(
|
||||
id: $id,
|
||||
tenantId: $tenantId,
|
||||
name: $name,
|
||||
isDefault: $isDefault,
|
||||
createdAt: $createdAt,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Model\Competency;
|
||||
|
||||
use App\Shared\Domain\EntityId;
|
||||
|
||||
final readonly class CompetencyFrameworkId extends EntityId
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Model\Competency;
|
||||
|
||||
use App\Shared\Domain\EntityId;
|
||||
|
||||
final readonly class CompetencyId extends EntityId
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Model\Competency;
|
||||
|
||||
/**
|
||||
* Niveaux de compétence standards du référentiel français.
|
||||
*
|
||||
* Ces niveaux sont les valeurs par défaut pour tout établissement
|
||||
* en mode compétences. Un établissement peut définir des niveaux
|
||||
* personnalisés dans la table competency_levels.
|
||||
*
|
||||
* @see FR23 : Mode compétences sans notes chiffrées
|
||||
*/
|
||||
enum CompetencyLevel: string
|
||||
{
|
||||
case NOT_ACQUIRED = 'not_acquired';
|
||||
case IN_PROGRESS = 'in_progress';
|
||||
case ACQUIRED = 'acquired';
|
||||
case EXCEEDED = 'exceeded';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::NOT_ACQUIRED => 'Non acquis',
|
||||
self::IN_PROGRESS => 'En cours d\'acquisition',
|
||||
self::ACQUIRED => 'Acquis',
|
||||
self::EXCEEDED => 'Dépassé',
|
||||
};
|
||||
}
|
||||
|
||||
public function sortOrder(): int
|
||||
{
|
||||
return match ($this) {
|
||||
self::NOT_ACQUIRED => 1,
|
||||
self::IN_PROGRESS => 2,
|
||||
self::ACQUIRED => 3,
|
||||
self::EXCEEDED => 4,
|
||||
};
|
||||
}
|
||||
|
||||
public function color(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::NOT_ACQUIRED => '#e74c3c',
|
||||
self::IN_PROGRESS => '#f39c12',
|
||||
self::ACQUIRED => '#2ecc71',
|
||||
self::EXCEEDED => '#3498db',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Model\Competency;
|
||||
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use DomainException;
|
||||
|
||||
use function preg_match;
|
||||
|
||||
/**
|
||||
* Niveau de compétence personnalisé par établissement.
|
||||
*
|
||||
* Permet à chaque établissement de définir ses propres niveaux
|
||||
* au lieu d'utiliser les niveaux standards (CompetencyLevel enum).
|
||||
*/
|
||||
final class CustomCompetencyLevel
|
||||
{
|
||||
private function __construct(
|
||||
public private(set) CustomCompetencyLevelId $id,
|
||||
public private(set) TenantId $tenantId,
|
||||
public private(set) string $code,
|
||||
public private(set) string $name,
|
||||
public private(set) ?string $color,
|
||||
public private(set) int $sortOrder,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function creer(
|
||||
TenantId $tenantId,
|
||||
string $code,
|
||||
string $name,
|
||||
?string $color,
|
||||
int $sortOrder,
|
||||
): self {
|
||||
if ($color !== null && preg_match('/^#[0-9a-fA-F]{6}$/', $color) !== 1) {
|
||||
throw new DomainException('La couleur doit être au format hexadécimal (#rrggbb).');
|
||||
}
|
||||
|
||||
return new self(
|
||||
id: CustomCompetencyLevelId::generate(),
|
||||
tenantId: $tenantId,
|
||||
code: $code,
|
||||
name: $name,
|
||||
color: $color,
|
||||
sortOrder: $sortOrder,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Pour usage Infrastructure uniquement
|
||||
*/
|
||||
public static function reconstitute(
|
||||
CustomCompetencyLevelId $id,
|
||||
TenantId $tenantId,
|
||||
string $code,
|
||||
string $name,
|
||||
?string $color,
|
||||
int $sortOrder,
|
||||
): self {
|
||||
return new self(
|
||||
id: $id,
|
||||
tenantId: $tenantId,
|
||||
code: $code,
|
||||
name: $name,
|
||||
color: $color,
|
||||
sortOrder: $sortOrder,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Model\Competency;
|
||||
|
||||
use App\Shared\Domain\EntityId;
|
||||
|
||||
final readonly class CustomCompetencyLevelId extends EntityId
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Model\Competency;
|
||||
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Domain\Event\ResultatCompetenceModifie;
|
||||
use App\Scolarite\Domain\Event\ResultatCompetenceSaisi;
|
||||
use App\Shared\Domain\AggregateRoot;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use DateTimeImmutable;
|
||||
|
||||
final class StudentCompetencyResult extends AggregateRoot
|
||||
{
|
||||
public private(set) DateTimeImmutable $updatedAt;
|
||||
|
||||
private function __construct(
|
||||
public private(set) StudentCompetencyResultId $id,
|
||||
public private(set) TenantId $tenantId,
|
||||
public private(set) CompetencyEvaluationId $competencyEvaluationId,
|
||||
public private(set) UserId $studentId,
|
||||
public private(set) string $levelCode,
|
||||
public private(set) DateTimeImmutable $createdAt,
|
||||
) {
|
||||
$this->updatedAt = $createdAt;
|
||||
}
|
||||
|
||||
public static function saisir(
|
||||
TenantId $tenantId,
|
||||
CompetencyEvaluationId $competencyEvaluationId,
|
||||
UserId $studentId,
|
||||
string $levelCode,
|
||||
DateTimeImmutable $now,
|
||||
): self {
|
||||
$result = new self(
|
||||
id: StudentCompetencyResultId::generate(),
|
||||
tenantId: $tenantId,
|
||||
competencyEvaluationId: $competencyEvaluationId,
|
||||
studentId: $studentId,
|
||||
levelCode: $levelCode,
|
||||
createdAt: $now,
|
||||
);
|
||||
|
||||
$result->recordEvent(new ResultatCompetenceSaisi(
|
||||
resultId: $result->id,
|
||||
competencyEvaluationId: (string) $competencyEvaluationId,
|
||||
studentId: (string) $studentId,
|
||||
levelCode: $levelCode,
|
||||
occurredOn: $now,
|
||||
));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function modifier(
|
||||
string $levelCode,
|
||||
DateTimeImmutable $now,
|
||||
): void {
|
||||
if ($this->levelCode === $levelCode) {
|
||||
return;
|
||||
}
|
||||
|
||||
$oldLevelCode = $this->levelCode;
|
||||
|
||||
$this->levelCode = $levelCode;
|
||||
$this->updatedAt = $now;
|
||||
|
||||
$this->recordEvent(new ResultatCompetenceModifie(
|
||||
resultId: $this->id,
|
||||
competencyEvaluationId: (string) $this->competencyEvaluationId,
|
||||
studentId: (string) $this->studentId,
|
||||
oldLevelCode: $oldLevelCode,
|
||||
newLevelCode: $levelCode,
|
||||
occurredOn: $now,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Pour usage Infrastructure uniquement
|
||||
*/
|
||||
public static function reconstitute(
|
||||
StudentCompetencyResultId $id,
|
||||
TenantId $tenantId,
|
||||
CompetencyEvaluationId $competencyEvaluationId,
|
||||
UserId $studentId,
|
||||
string $levelCode,
|
||||
DateTimeImmutable $createdAt,
|
||||
DateTimeImmutable $updatedAt,
|
||||
): self {
|
||||
$result = new self(
|
||||
id: $id,
|
||||
tenantId: $tenantId,
|
||||
competencyEvaluationId: $competencyEvaluationId,
|
||||
studentId: $studentId,
|
||||
levelCode: $levelCode,
|
||||
createdAt: $createdAt,
|
||||
);
|
||||
|
||||
$result->updatedAt = $updatedAt;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Model\Competency;
|
||||
|
||||
use App\Shared\Domain\EntityId;
|
||||
|
||||
final readonly class StudentCompetencyResultId extends EntityId
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Model\Evaluation;
|
||||
|
||||
final readonly class ClassStatistics
|
||||
{
|
||||
public function __construct(
|
||||
public ?float $average,
|
||||
public ?float $min,
|
||||
public ?float $max,
|
||||
public ?float $median,
|
||||
public int $gradedCount,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Model\Grade;
|
||||
|
||||
enum AppreciationCategory: string
|
||||
{
|
||||
case POSITIVE = 'positive';
|
||||
case NEUTRAL = 'neutral';
|
||||
case IMPROVEMENT = 'improvement';
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Model\Grade;
|
||||
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use DateTimeImmutable;
|
||||
|
||||
final class AppreciationTemplate
|
||||
{
|
||||
public private(set) DateTimeImmutable $updatedAt;
|
||||
public private(set) int $usageCount;
|
||||
|
||||
private function __construct(
|
||||
public private(set) AppreciationTemplateId $id,
|
||||
public private(set) TenantId $tenantId,
|
||||
public private(set) UserId $teacherId,
|
||||
public private(set) string $title,
|
||||
public private(set) string $content,
|
||||
public private(set) ?AppreciationCategory $category,
|
||||
public private(set) DateTimeImmutable $createdAt,
|
||||
) {
|
||||
$this->updatedAt = $createdAt;
|
||||
$this->usageCount = 0;
|
||||
}
|
||||
|
||||
public static function creer(
|
||||
TenantId $tenantId,
|
||||
UserId $teacherId,
|
||||
string $title,
|
||||
string $content,
|
||||
?AppreciationCategory $category,
|
||||
DateTimeImmutable $now,
|
||||
): self {
|
||||
return new self(
|
||||
id: AppreciationTemplateId::generate(),
|
||||
tenantId: $tenantId,
|
||||
teacherId: $teacherId,
|
||||
title: $title,
|
||||
content: $content,
|
||||
category: $category,
|
||||
createdAt: $now,
|
||||
);
|
||||
}
|
||||
|
||||
public function modifier(
|
||||
string $title,
|
||||
string $content,
|
||||
?AppreciationCategory $category,
|
||||
DateTimeImmutable $now,
|
||||
): void {
|
||||
$this->title = $title;
|
||||
$this->content = $content;
|
||||
$this->category = $category;
|
||||
$this->updatedAt = $now;
|
||||
}
|
||||
|
||||
public function incrementerUtilisation(): void
|
||||
{
|
||||
++$this->usageCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Pour usage Infrastructure uniquement
|
||||
*/
|
||||
public static function reconstitute(
|
||||
AppreciationTemplateId $id,
|
||||
TenantId $tenantId,
|
||||
UserId $teacherId,
|
||||
string $title,
|
||||
string $content,
|
||||
?AppreciationCategory $category,
|
||||
int $usageCount,
|
||||
DateTimeImmutable $createdAt,
|
||||
DateTimeImmutable $updatedAt,
|
||||
): self {
|
||||
$template = new self(
|
||||
id: $id,
|
||||
tenantId: $tenantId,
|
||||
teacherId: $teacherId,
|
||||
title: $title,
|
||||
content: $content,
|
||||
category: $category,
|
||||
createdAt: $createdAt,
|
||||
);
|
||||
|
||||
$template->updatedAt = $updatedAt;
|
||||
$template->usageCount = $usageCount;
|
||||
|
||||
return $template;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Model\Grade;
|
||||
|
||||
use App\Shared\Domain\EntityId;
|
||||
|
||||
final readonly class AppreciationTemplateId extends EntityId
|
||||
{
|
||||
}
|
||||
@@ -7,6 +7,7 @@ namespace App\Scolarite\Domain\Model\Grade;
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Domain\Event\NoteModifiee;
|
||||
use App\Scolarite\Domain\Event\NoteSaisie;
|
||||
use App\Scolarite\Domain\Exception\AppreciationTropLongueException;
|
||||
use App\Scolarite\Domain\Exception\NoteRequiseException;
|
||||
use App\Scolarite\Domain\Exception\ValeurNoteInvalideException;
|
||||
use App\Scolarite\Domain\Model\Evaluation\EvaluationId;
|
||||
@@ -15,9 +16,15 @@ use App\Shared\Domain\AggregateRoot;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use DateTimeImmutable;
|
||||
|
||||
use function mb_strlen;
|
||||
|
||||
final class Grade extends AggregateRoot
|
||||
{
|
||||
public const int MAX_APPRECIATION_LENGTH = 500;
|
||||
|
||||
public private(set) DateTimeImmutable $updatedAt;
|
||||
public private(set) ?string $appreciation;
|
||||
public private(set) ?DateTimeImmutable $appreciationUpdatedAt;
|
||||
|
||||
private function __construct(
|
||||
public private(set) GradeId $id,
|
||||
@@ -30,6 +37,8 @@ final class Grade extends AggregateRoot
|
||||
public private(set) DateTimeImmutable $createdAt,
|
||||
) {
|
||||
$this->updatedAt = $createdAt;
|
||||
$this->appreciation = null;
|
||||
$this->appreciationUpdatedAt = null;
|
||||
}
|
||||
|
||||
public static function saisir(
|
||||
@@ -96,6 +105,17 @@ final class Grade extends AggregateRoot
|
||||
));
|
||||
}
|
||||
|
||||
public function saisirAppreciation(?string $appreciation, DateTimeImmutable $now): void
|
||||
{
|
||||
if ($appreciation !== null && mb_strlen($appreciation) > self::MAX_APPRECIATION_LENGTH) {
|
||||
throw AppreciationTropLongueException::depasseLimite(mb_strlen($appreciation), self::MAX_APPRECIATION_LENGTH);
|
||||
}
|
||||
|
||||
$this->appreciation = $appreciation !== null && $appreciation !== '' ? $appreciation : null;
|
||||
$this->appreciationUpdatedAt = $now;
|
||||
$this->updatedAt = $now;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Pour usage Infrastructure uniquement
|
||||
*/
|
||||
@@ -109,6 +129,8 @@ final class Grade extends AggregateRoot
|
||||
UserId $createdBy,
|
||||
DateTimeImmutable $createdAt,
|
||||
DateTimeImmutable $updatedAt,
|
||||
?string $appreciation = null,
|
||||
?DateTimeImmutable $appreciationUpdatedAt = null,
|
||||
): self {
|
||||
$grade = new self(
|
||||
id: $id,
|
||||
@@ -122,6 +144,8 @@ final class Grade extends AggregateRoot
|
||||
);
|
||||
|
||||
$grade->updatedAt = $updatedAt;
|
||||
$grade->appreciation = $appreciation;
|
||||
$grade->appreciationUpdatedAt = $appreciationUpdatedAt;
|
||||
|
||||
return $grade;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Repository;
|
||||
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Domain\Model\Grade\AppreciationTemplate;
|
||||
use App\Scolarite\Domain\Model\Grade\AppreciationTemplateId;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
|
||||
interface AppreciationTemplateRepository
|
||||
{
|
||||
public function save(AppreciationTemplate $template): void;
|
||||
|
||||
public function findById(AppreciationTemplateId $id, TenantId $tenantId): ?AppreciationTemplate;
|
||||
|
||||
/** @return array<AppreciationTemplate> */
|
||||
public function findByTeacher(UserId $teacherId, TenantId $tenantId): array;
|
||||
|
||||
public function delete(AppreciationTemplateId $id, TenantId $tenantId): void;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Repository;
|
||||
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyEvaluation;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyEvaluationId;
|
||||
use App\Scolarite\Domain\Model\Evaluation\EvaluationId;
|
||||
|
||||
interface CompetencyEvaluationRepository
|
||||
{
|
||||
public function save(CompetencyEvaluation $competencyEvaluation): void;
|
||||
|
||||
public function findById(CompetencyEvaluationId $id): ?CompetencyEvaluation;
|
||||
|
||||
/** @return array<CompetencyEvaluation> */
|
||||
public function findByEvaluation(EvaluationId $evaluationId): array;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Repository;
|
||||
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyFramework;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyFrameworkId;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
|
||||
interface CompetencyFrameworkRepository
|
||||
{
|
||||
public function save(CompetencyFramework $framework): void;
|
||||
|
||||
public function findById(CompetencyFrameworkId $id, TenantId $tenantId): ?CompetencyFramework;
|
||||
|
||||
public function findDefault(TenantId $tenantId): ?CompetencyFramework;
|
||||
|
||||
/** @return array<CompetencyFramework> */
|
||||
public function findByTenant(TenantId $tenantId): array;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Repository;
|
||||
|
||||
use App\Scolarite\Domain\Model\Competency\Competency;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyFrameworkId;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyId;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
|
||||
interface CompetencyRepository
|
||||
{
|
||||
public function save(Competency $competency): void;
|
||||
|
||||
public function findById(CompetencyId $id, TenantId $tenantId): ?Competency;
|
||||
|
||||
/** @return array<Competency> */
|
||||
public function findByFramework(CompetencyFrameworkId $frameworkId): array;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Repository;
|
||||
|
||||
use App\Scolarite\Domain\Model\Competency\CustomCompetencyLevel;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
|
||||
interface CustomCompetencyLevelRepository
|
||||
{
|
||||
public function save(CustomCompetencyLevel $level): void;
|
||||
|
||||
/** @return array<CustomCompetencyLevel> */
|
||||
public function findByTenant(TenantId $tenantId): array;
|
||||
|
||||
public function hasByTenant(TenantId $tenantId): bool;
|
||||
}
|
||||
@@ -5,11 +5,13 @@ declare(strict_types=1);
|
||||
namespace App\Scolarite\Domain\Repository;
|
||||
|
||||
use App\Administration\Domain\Model\SchoolClass\ClassId;
|
||||
use App\Administration\Domain\Model\Subject\SubjectId;
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Domain\Exception\EvaluationNotFoundException;
|
||||
use App\Scolarite\Domain\Model\Evaluation\Evaluation;
|
||||
use App\Scolarite\Domain\Model\Evaluation\EvaluationId;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use DateTimeImmutable;
|
||||
|
||||
interface EvaluationRepository
|
||||
{
|
||||
@@ -28,4 +30,16 @@ interface EvaluationRepository
|
||||
|
||||
/** @return array<Evaluation> */
|
||||
public function findByClass(ClassId $classId, TenantId $tenantId): array;
|
||||
|
||||
/** @return array<Evaluation> Toutes les évaluations publiées (notes visibles) */
|
||||
public function findAllWithPublishedGrades(TenantId $tenantId): array;
|
||||
|
||||
/** @return array<Evaluation> Évaluations dont les notes sont publiées */
|
||||
public function findWithPublishedGradesBySubjectAndClassInDateRange(
|
||||
SubjectId $subjectId,
|
||||
ClassId $classId,
|
||||
DateTimeImmutable $startDate,
|
||||
DateTimeImmutable $endDate,
|
||||
TenantId $tenantId,
|
||||
): array;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Repository;
|
||||
|
||||
use App\Scolarite\Domain\Model\Evaluation\ClassStatistics;
|
||||
use App\Scolarite\Domain\Model\Evaluation\EvaluationId;
|
||||
|
||||
interface EvaluationStatisticsRepository
|
||||
{
|
||||
public function save(EvaluationId $evaluationId, ClassStatistics $statistics): void;
|
||||
|
||||
public function findByEvaluation(EvaluationId $evaluationId): ?ClassStatistics;
|
||||
|
||||
public function delete(EvaluationId $evaluationId): void;
|
||||
}
|
||||
@@ -14,6 +14,8 @@ interface GradeRepository
|
||||
{
|
||||
public function save(Grade $grade): void;
|
||||
|
||||
public function saveAppreciation(Grade $grade): void;
|
||||
|
||||
/** @throws GradeNotFoundException */
|
||||
public function get(GradeId $id, TenantId $tenantId): Grade;
|
||||
|
||||
@@ -22,5 +24,12 @@ interface GradeRepository
|
||||
/** @return array<Grade> */
|
||||
public function findByEvaluation(EvaluationId $evaluationId, TenantId $tenantId): array;
|
||||
|
||||
/**
|
||||
* @param array<EvaluationId> $evaluationIds
|
||||
*
|
||||
* @return array<string, list<Grade>> Clé = evaluationId (string)
|
||||
*/
|
||||
public function findByEvaluations(array $evaluationIds, TenantId $tenantId): array;
|
||||
|
||||
public function hasGradesForEvaluation(EvaluationId $evaluationId, TenantId $tenantId): bool;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Repository;
|
||||
|
||||
use App\Administration\Domain\Model\Subject\SubjectId;
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
|
||||
interface StudentAverageRepository
|
||||
{
|
||||
public function saveSubjectAverage(
|
||||
TenantId $tenantId,
|
||||
UserId $studentId,
|
||||
SubjectId $subjectId,
|
||||
string $periodId,
|
||||
float $average,
|
||||
int $gradeCount,
|
||||
): void;
|
||||
|
||||
public function saveGeneralAverage(
|
||||
TenantId $tenantId,
|
||||
UserId $studentId,
|
||||
string $periodId,
|
||||
float $average,
|
||||
): void;
|
||||
|
||||
/** @return list<float> Moyennes matières d'un élève pour une période */
|
||||
public function findSubjectAveragesForStudent(
|
||||
UserId $studentId,
|
||||
string $periodId,
|
||||
TenantId $tenantId,
|
||||
): array;
|
||||
|
||||
/** @return list<array{subjectId: string, subjectName: string|null, average: float, gradeCount: int}> */
|
||||
public function findDetailedSubjectAveragesForStudent(
|
||||
UserId $studentId,
|
||||
string $periodId,
|
||||
TenantId $tenantId,
|
||||
): array;
|
||||
|
||||
public function findGeneralAverageForStudent(
|
||||
UserId $studentId,
|
||||
string $periodId,
|
||||
TenantId $tenantId,
|
||||
): ?float;
|
||||
|
||||
public function deleteSubjectAverage(
|
||||
UserId $studentId,
|
||||
SubjectId $subjectId,
|
||||
string $periodId,
|
||||
TenantId $tenantId,
|
||||
): void;
|
||||
|
||||
public function deleteGeneralAverage(
|
||||
UserId $studentId,
|
||||
string $periodId,
|
||||
TenantId $tenantId,
|
||||
): void;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Repository;
|
||||
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyEvaluationId;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyId;
|
||||
use App\Scolarite\Domain\Model\Competency\StudentCompetencyResult;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
|
||||
interface StudentCompetencyResultRepository
|
||||
{
|
||||
public function save(StudentCompetencyResult $result): void;
|
||||
|
||||
public function delete(StudentCompetencyResult $result): void;
|
||||
|
||||
/** @return array<StudentCompetencyResult> */
|
||||
public function findByCompetencyEvaluation(
|
||||
CompetencyEvaluationId $competencyEvaluationId,
|
||||
TenantId $tenantId,
|
||||
): array;
|
||||
|
||||
public function findByCompetencyEvaluationAndStudent(
|
||||
CompetencyEvaluationId $competencyEvaluationId,
|
||||
UserId $studentId,
|
||||
TenantId $tenantId,
|
||||
): ?StudentCompetencyResult;
|
||||
|
||||
/** @return array<StudentCompetencyResult> */
|
||||
public function findByStudentAndCompetency(
|
||||
UserId $studentId,
|
||||
CompetencyId $competencyId,
|
||||
TenantId $tenantId,
|
||||
): array;
|
||||
}
|
||||
102
backend/src/Scolarite/Domain/Service/AverageCalculator.php
Normal file
102
backend/src/Scolarite/Domain/Service/AverageCalculator.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Service;
|
||||
|
||||
use App\Scolarite\Domain\Model\Evaluation\ClassStatistics;
|
||||
|
||||
use function array_sum;
|
||||
use function count;
|
||||
use function intdiv;
|
||||
use function round;
|
||||
use function sort;
|
||||
|
||||
final class AverageCalculator
|
||||
{
|
||||
/**
|
||||
* Moyenne matière pondérée par les coefficients, normalisée sur /20.
|
||||
* Les notes absent/dispensé doivent être exclues en amont.
|
||||
*
|
||||
* Formule : Σ(note_sur_20 × coef) / Σ(coef)
|
||||
*
|
||||
* @param list<GradeEntry> $grades
|
||||
*/
|
||||
public function calculateSubjectAverage(array $grades): ?float
|
||||
{
|
||||
if ($grades === []) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$sumWeighted = 0.0;
|
||||
$sumCoef = 0.0;
|
||||
|
||||
foreach ($grades as $entry) {
|
||||
$normalizedValue = $entry->gradeScale->convertTo20($entry->value);
|
||||
$sumWeighted += $normalizedValue * $entry->coefficient->value;
|
||||
$sumCoef += $entry->coefficient->value;
|
||||
}
|
||||
|
||||
return round($sumWeighted / $sumCoef, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moyenne générale : moyenne arithmétique des moyennes matières.
|
||||
* Les matières sans note sont exclues en amont.
|
||||
*
|
||||
* @param list<float> $subjectAverages
|
||||
*/
|
||||
public function calculateGeneralAverage(array $subjectAverages): ?float
|
||||
{
|
||||
if ($subjectAverages === []) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return round(array_sum($subjectAverages) / count($subjectAverages), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Statistiques de classe pour une évaluation : min, max, moyenne, médiane.
|
||||
* Les absents et dispensés doivent être exclus en amont.
|
||||
*
|
||||
* @param list<float> $values
|
||||
*/
|
||||
public function calculateClassStatistics(array $values): ClassStatistics
|
||||
{
|
||||
if ($values === []) {
|
||||
return new ClassStatistics(
|
||||
average: null,
|
||||
min: null,
|
||||
max: null,
|
||||
median: null,
|
||||
gradedCount: 0,
|
||||
);
|
||||
}
|
||||
|
||||
sort($values);
|
||||
$count = count($values);
|
||||
|
||||
return new ClassStatistics(
|
||||
average: round(array_sum($values) / $count, 2),
|
||||
min: $values[0],
|
||||
max: $values[$count - 1],
|
||||
median: $this->calculateMedian($values),
|
||||
gradedCount: $count,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<float> $sortedValues Valeurs déjà triées par ordre croissant
|
||||
*/
|
||||
private function calculateMedian(array $sortedValues): float
|
||||
{
|
||||
$count = count($sortedValues);
|
||||
$middle = intdiv($count, 2);
|
||||
|
||||
if ($count % 2 === 0) {
|
||||
return round(($sortedValues[$middle - 1] + $sortedValues[$middle]) / 2, 2);
|
||||
}
|
||||
|
||||
return $sortedValues[$middle];
|
||||
}
|
||||
}
|
||||
18
backend/src/Scolarite/Domain/Service/GradeEntry.php
Normal file
18
backend/src/Scolarite/Domain/Service/GradeEntry.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Service;
|
||||
|
||||
use App\Scolarite\Domain\Model\Evaluation\Coefficient;
|
||||
use App\Scolarite\Domain\Model\Evaluation\GradeScale;
|
||||
|
||||
final readonly class GradeEntry
|
||||
{
|
||||
public function __construct(
|
||||
public float $value,
|
||||
public GradeScale $gradeScale,
|
||||
public Coefficient $coefficient,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Processor;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use App\Administration\Infrastructure\Security\SecurityUser;
|
||||
use App\Scolarite\Application\Command\CreateAppreciationTemplate\CreateAppreciationTemplateCommand;
|
||||
use App\Scolarite\Application\Command\CreateAppreciationTemplate\CreateAppreciationTemplateHandler;
|
||||
use App\Scolarite\Domain\Exception\CategorieAppreciationInvalideException;
|
||||
use App\Scolarite\Infrastructure\Api\Resource\AppreciationTemplateResource;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
use Override;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
/**
|
||||
* @implements ProcessorInterface<AppreciationTemplateResource, AppreciationTemplateResource>
|
||||
*/
|
||||
final readonly class CreateAppreciationTemplateProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private CreateAppreciationTemplateHandler $handler,
|
||||
private TenantContext $tenantContext,
|
||||
private Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AppreciationTemplateResource $data
|
||||
*/
|
||||
#[Override]
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): AppreciationTemplateResource
|
||||
{
|
||||
if (!$this->tenantContext->hasTenant()) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Tenant non défini.');
|
||||
}
|
||||
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof SecurityUser) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Authentification requise.');
|
||||
}
|
||||
|
||||
try {
|
||||
$command = new CreateAppreciationTemplateCommand(
|
||||
tenantId: (string) $this->tenantContext->getCurrentTenantId(),
|
||||
teacherId: $user->userId(),
|
||||
title: $data->title ?? '',
|
||||
content: $data->content ?? '',
|
||||
category: $data->category,
|
||||
);
|
||||
|
||||
$template = ($this->handler)($command);
|
||||
|
||||
return AppreciationTemplateResource::fromDomain($template);
|
||||
} catch (CategorieAppreciationInvalideException $e) {
|
||||
throw new BadRequestHttpException($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Processor;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use App\Administration\Infrastructure\Security\SecurityUser;
|
||||
use App\Scolarite\Application\Command\DeleteAppreciationTemplate\DeleteAppreciationTemplateCommand;
|
||||
use App\Scolarite\Application\Command\DeleteAppreciationTemplate\DeleteAppreciationTemplateHandler;
|
||||
use App\Scolarite\Domain\Exception\AppreciationTemplateNonTrouveeException;
|
||||
use App\Scolarite\Domain\Exception\NonProprietaireDuModeleException;
|
||||
use App\Scolarite\Infrastructure\Api\Resource\AppreciationTemplateResource;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
use Override;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
/**
|
||||
* @implements ProcessorInterface<AppreciationTemplateResource, null>
|
||||
*/
|
||||
final readonly class DeleteAppreciationTemplateProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private DeleteAppreciationTemplateHandler $handler,
|
||||
private TenantContext $tenantContext,
|
||||
private Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AppreciationTemplateResource $data
|
||||
*/
|
||||
#[Override]
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): null
|
||||
{
|
||||
if (!$this->tenantContext->hasTenant()) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Tenant non défini.');
|
||||
}
|
||||
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof SecurityUser) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Authentification requise.');
|
||||
}
|
||||
|
||||
/** @var string $templateId */
|
||||
$templateId = $uriVariables['id'] ?? '';
|
||||
|
||||
try {
|
||||
$command = new DeleteAppreciationTemplateCommand(
|
||||
tenantId: (string) $this->tenantContext->getCurrentTenantId(),
|
||||
teacherId: $user->userId(),
|
||||
templateId: $templateId,
|
||||
);
|
||||
|
||||
($this->handler)($command);
|
||||
|
||||
return null;
|
||||
} catch (AppreciationTemplateNonTrouveeException $e) {
|
||||
throw new NotFoundHttpException($e->getMessage());
|
||||
} catch (NonProprietaireDuModeleException $e) {
|
||||
throw new AccessDeniedHttpException($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Processor;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use App\Administration\Infrastructure\Security\SecurityUser;
|
||||
use App\Scolarite\Application\Command\LinkCompetenciesToEvaluation\LinkCompetenciesToEvaluationCommand;
|
||||
use App\Scolarite\Application\Command\LinkCompetenciesToEvaluation\LinkCompetenciesToEvaluationHandler;
|
||||
use App\Scolarite\Domain\Exception\EvaluationNotFoundException;
|
||||
use App\Scolarite\Domain\Exception\NonProprietaireDeLEvaluationException;
|
||||
use App\Scolarite\Infrastructure\Api\Resource\CompetencyEvaluationResource;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
|
||||
use function array_map;
|
||||
|
||||
use DomainException;
|
||||
use Override;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
/**
|
||||
* @implements ProcessorInterface<CompetencyEvaluationResource, array<CompetencyEvaluationResource>>
|
||||
*/
|
||||
final readonly class LinkCompetenciesToEvaluationProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private LinkCompetenciesToEvaluationHandler $handler,
|
||||
private TenantContext $tenantContext,
|
||||
private Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CompetencyEvaluationResource $data
|
||||
*
|
||||
* @return array<CompetencyEvaluationResource>
|
||||
*/
|
||||
#[Override]
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): array
|
||||
{
|
||||
if (!$this->tenantContext->hasTenant()) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Tenant non défini.');
|
||||
}
|
||||
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof SecurityUser) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Authentification requise.');
|
||||
}
|
||||
|
||||
/** @var string $evaluationId */
|
||||
$evaluationId = $uriVariables['evaluationId'] ?? '';
|
||||
|
||||
try {
|
||||
$command = new LinkCompetenciesToEvaluationCommand(
|
||||
tenantId: (string) $this->tenantContext->getCurrentTenantId(),
|
||||
evaluationId: $evaluationId,
|
||||
teacherId: $user->userId(),
|
||||
competencyIds: $data->competencyIds ?? [],
|
||||
);
|
||||
|
||||
$linked = ($this->handler)($command);
|
||||
|
||||
return array_map(static function ($ce): CompetencyEvaluationResource {
|
||||
$resource = new CompetencyEvaluationResource();
|
||||
$resource->id = (string) $ce->id;
|
||||
$resource->evaluationId = (string) $ce->evaluationId;
|
||||
$resource->competencyId = (string) $ce->competencyId;
|
||||
|
||||
return $resource;
|
||||
}, $linked);
|
||||
} catch (EvaluationNotFoundException $e) {
|
||||
throw new NotFoundHttpException($e->getMessage());
|
||||
} catch (NonProprietaireDeLEvaluationException $e) {
|
||||
throw new AccessDeniedHttpException($e->getMessage());
|
||||
} catch (DomainException $e) {
|
||||
throw new BadRequestHttpException($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Processor;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use App\Administration\Infrastructure\Security\SecurityUser;
|
||||
use App\Scolarite\Application\Command\SaveAppreciation\SaveAppreciationCommand;
|
||||
use App\Scolarite\Application\Command\SaveAppreciation\SaveAppreciationHandler;
|
||||
use App\Scolarite\Domain\Exception\AppreciationTropLongueException;
|
||||
use App\Scolarite\Domain\Exception\GradeNotFoundException;
|
||||
use App\Scolarite\Domain\Exception\NonProprietaireDeLEvaluationException;
|
||||
use App\Scolarite\Infrastructure\Api\Resource\GradeResource;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
use Override;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
/**
|
||||
* @implements ProcessorInterface<GradeResource, GradeResource>
|
||||
*/
|
||||
final readonly class SaveAppreciationProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private SaveAppreciationHandler $handler,
|
||||
private TenantContext $tenantContext,
|
||||
private Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GradeResource $data
|
||||
*/
|
||||
#[Override]
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): GradeResource
|
||||
{
|
||||
if (!$this->tenantContext->hasTenant()) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Tenant non défini.');
|
||||
}
|
||||
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof SecurityUser) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Authentification requise.');
|
||||
}
|
||||
|
||||
/** @var string $gradeId */
|
||||
$gradeId = $uriVariables['id'] ?? '';
|
||||
|
||||
try {
|
||||
$command = new SaveAppreciationCommand(
|
||||
tenantId: (string) $this->tenantContext->getCurrentTenantId(),
|
||||
gradeId: $gradeId,
|
||||
teacherId: $user->userId(),
|
||||
appreciation: $data->appreciation,
|
||||
);
|
||||
|
||||
$grade = ($this->handler)($command);
|
||||
|
||||
return GradeResource::fromDomain($grade);
|
||||
} catch (NonProprietaireDeLEvaluationException $e) {
|
||||
throw new AccessDeniedHttpException($e->getMessage());
|
||||
} catch (GradeNotFoundException) {
|
||||
throw new NotFoundHttpException('Aucune note trouvée. Veuillez d\'abord saisir une note pour cet élève avant d\'ajouter une appréciation.');
|
||||
} catch (AppreciationTropLongueException $e) {
|
||||
throw new BadRequestHttpException($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Processor;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use App\Administration\Infrastructure\Security\SecurityUser;
|
||||
use App\Scolarite\Application\Command\SaveCompetencyResults\SaveCompetencyResultsCommand;
|
||||
use App\Scolarite\Application\Command\SaveCompetencyResults\SaveCompetencyResultsHandler;
|
||||
use App\Scolarite\Domain\Exception\EvaluationNotFoundException;
|
||||
use App\Scolarite\Domain\Exception\NonProprietaireDeLEvaluationException;
|
||||
use App\Scolarite\Infrastructure\Api\Resource\CompetencyResultResource;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
|
||||
use function array_map;
|
||||
|
||||
use DomainException;
|
||||
use Override;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
|
||||
/**
|
||||
* @implements ProcessorInterface<CompetencyResultResource, array<CompetencyResultResource>>
|
||||
*/
|
||||
final readonly class SaveCompetencyResultsProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private SaveCompetencyResultsHandler $handler,
|
||||
private TenantContext $tenantContext,
|
||||
private MessageBusInterface $eventBus,
|
||||
private Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CompetencyResultResource $data
|
||||
*
|
||||
* @return array<CompetencyResultResource>
|
||||
*/
|
||||
#[Override]
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): array
|
||||
{
|
||||
if (!$this->tenantContext->hasTenant()) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Tenant non défini.');
|
||||
}
|
||||
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof SecurityUser) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Authentification requise.');
|
||||
}
|
||||
|
||||
/** @var string $evaluationId */
|
||||
$evaluationId = $uriVariables['evaluationId'] ?? '';
|
||||
|
||||
try {
|
||||
$command = new SaveCompetencyResultsCommand(
|
||||
tenantId: (string) $this->tenantContext->getCurrentTenantId(),
|
||||
evaluationId: $evaluationId,
|
||||
teacherId: $user->userId(),
|
||||
results: $data->results ?? [],
|
||||
);
|
||||
|
||||
$savedResults = ($this->handler)($command);
|
||||
|
||||
foreach ($savedResults as $result) {
|
||||
foreach ($result->pullDomainEvents() as $event) {
|
||||
$this->eventBus->dispatch($event);
|
||||
}
|
||||
}
|
||||
|
||||
return array_map(static function ($result) use ($evaluationId): CompetencyResultResource {
|
||||
$resource = new CompetencyResultResource();
|
||||
$resource->id = (string) $result->id;
|
||||
$resource->evaluationId = $evaluationId;
|
||||
$resource->competencyEvaluationId = (string) $result->competencyEvaluationId;
|
||||
$resource->studentId = (string) $result->studentId;
|
||||
$resource->levelCode = $result->levelCode;
|
||||
|
||||
return $resource;
|
||||
}, $savedResults);
|
||||
} catch (EvaluationNotFoundException $e) {
|
||||
throw new NotFoundHttpException($e->getMessage());
|
||||
} catch (NonProprietaireDeLEvaluationException $e) {
|
||||
throw new AccessDeniedHttpException($e->getMessage());
|
||||
} catch (DomainException $e) {
|
||||
throw new BadRequestHttpException($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Processor;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use App\Administration\Infrastructure\Security\SecurityUser;
|
||||
use App\Scolarite\Application\Command\UpdateAppreciationTemplate\UpdateAppreciationTemplateCommand;
|
||||
use App\Scolarite\Application\Command\UpdateAppreciationTemplate\UpdateAppreciationTemplateHandler;
|
||||
use App\Scolarite\Domain\Exception\AppreciationTemplateNonTrouveeException;
|
||||
use App\Scolarite\Domain\Exception\CategorieAppreciationInvalideException;
|
||||
use App\Scolarite\Domain\Exception\NonProprietaireDuModeleException;
|
||||
use App\Scolarite\Infrastructure\Api\Resource\AppreciationTemplateResource;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
use Override;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
/**
|
||||
* @implements ProcessorInterface<AppreciationTemplateResource, AppreciationTemplateResource>
|
||||
*/
|
||||
final readonly class UpdateAppreciationTemplateProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private UpdateAppreciationTemplateHandler $handler,
|
||||
private TenantContext $tenantContext,
|
||||
private Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AppreciationTemplateResource $data
|
||||
*/
|
||||
#[Override]
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): AppreciationTemplateResource
|
||||
{
|
||||
if (!$this->tenantContext->hasTenant()) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Tenant non défini.');
|
||||
}
|
||||
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof SecurityUser) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Authentification requise.');
|
||||
}
|
||||
|
||||
/** @var string $templateId */
|
||||
$templateId = $uriVariables['id'] ?? '';
|
||||
|
||||
try {
|
||||
$command = new UpdateAppreciationTemplateCommand(
|
||||
tenantId: (string) $this->tenantContext->getCurrentTenantId(),
|
||||
teacherId: $user->userId(),
|
||||
templateId: $templateId,
|
||||
title: $data->title ?? '',
|
||||
content: $data->content ?? '',
|
||||
category: $data->category,
|
||||
);
|
||||
|
||||
$template = ($this->handler)($command);
|
||||
|
||||
return AppreciationTemplateResource::fromDomain($template);
|
||||
} catch (AppreciationTemplateNonTrouveeException $e) {
|
||||
throw new NotFoundHttpException($e->getMessage());
|
||||
} catch (NonProprietaireDuModeleException $e) {
|
||||
throw new AccessDeniedHttpException($e->getMessage());
|
||||
} catch (CategorieAppreciationInvalideException $e) {
|
||||
throw new BadRequestHttpException($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Provider;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Administration\Infrastructure\Security\SecurityUser;
|
||||
use App\Scolarite\Domain\Repository\AppreciationTemplateRepository;
|
||||
use App\Scolarite\Infrastructure\Api\Resource\AppreciationTemplateResource;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
|
||||
use function array_map;
|
||||
|
||||
use Override;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
/**
|
||||
* @implements ProviderInterface<AppreciationTemplateResource>
|
||||
*/
|
||||
final readonly class AppreciationTemplateCollectionProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private AppreciationTemplateRepository $templateRepository,
|
||||
private TenantContext $tenantContext,
|
||||
private Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
/** @return array<AppreciationTemplateResource> */
|
||||
#[Override]
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): array
|
||||
{
|
||||
if (!$this->tenantContext->hasTenant()) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Tenant non défini.');
|
||||
}
|
||||
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof SecurityUser) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Authentification requise.');
|
||||
}
|
||||
|
||||
$tenantId = $this->tenantContext->getCurrentTenantId();
|
||||
$teacherId = UserId::fromString($user->userId());
|
||||
|
||||
$templates = $this->templateRepository->findByTeacher($teacherId, $tenantId);
|
||||
|
||||
return array_map(
|
||||
static fn ($template) => AppreciationTemplateResource::fromDomain($template),
|
||||
$templates,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Provider;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Administration\Domain\Model\User\Role;
|
||||
use App\Administration\Infrastructure\Security\SecurityUser;
|
||||
use App\Scolarite\Domain\Model\Evaluation\EvaluationStatus;
|
||||
use App\Scolarite\Infrastructure\Api\Resource\ClassStatisticsResource;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
use Doctrine\DBAL\Connection;
|
||||
|
||||
use function in_array;
|
||||
|
||||
use Override;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
/**
|
||||
* @implements ProviderInterface<ClassStatisticsResource>
|
||||
*/
|
||||
final readonly class ClassStatisticsProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private Connection $connection,
|
||||
private TenantContext $tenantContext,
|
||||
private Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): ClassStatisticsResource
|
||||
{
|
||||
if (!$this->tenantContext->hasTenant()) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Tenant non défini.');
|
||||
}
|
||||
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof SecurityUser) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Authentification requise.');
|
||||
}
|
||||
|
||||
$isStaff = $this->hasAnyRole($user->getRoles(), [
|
||||
Role::ADMIN->value,
|
||||
Role::PROF->value,
|
||||
Role::VIE_SCOLAIRE->value,
|
||||
]);
|
||||
|
||||
if (!$isStaff) {
|
||||
throw new AccessDeniedHttpException('Accès réservé au personnel éducatif.');
|
||||
}
|
||||
|
||||
/** @var string $classId */
|
||||
$classId = $uriVariables['classId'];
|
||||
$tenantId = (string) $this->tenantContext->getCurrentTenantId();
|
||||
|
||||
$resource = new ClassStatisticsResource();
|
||||
$resource->classId = $classId;
|
||||
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
'SELECT e.id as evaluation_id, e.title, es.average, es.min_grade, es.max_grade, es.median_grade, es.graded_count
|
||||
FROM evaluations e
|
||||
LEFT JOIN evaluation_statistics es ON es.evaluation_id = e.id
|
||||
WHERE e.class_id = :class_id
|
||||
AND e.tenant_id = :tenant_id
|
||||
AND e.status != :deleted
|
||||
AND e.grades_published_at IS NOT NULL
|
||||
ORDER BY e.evaluation_date DESC',
|
||||
[
|
||||
'class_id' => $classId,
|
||||
'tenant_id' => $tenantId,
|
||||
'deleted' => EvaluationStatus::DELETED->value,
|
||||
],
|
||||
);
|
||||
|
||||
foreach ($rows as $row) {
|
||||
/** @var string $evaluationId */
|
||||
$evaluationId = $row['evaluation_id'];
|
||||
/** @var string $title */
|
||||
$title = $row['title'];
|
||||
/** @var string|float|null $average */
|
||||
$average = $row['average'];
|
||||
/** @var string|float|null $minGrade */
|
||||
$minGrade = $row['min_grade'];
|
||||
/** @var string|float|null $maxGrade */
|
||||
$maxGrade = $row['max_grade'];
|
||||
/** @var string|float|null $medianGrade */
|
||||
$medianGrade = $row['median_grade'];
|
||||
/** @var string|int|null $gradedCount */
|
||||
$gradedCount = $row['graded_count'];
|
||||
|
||||
$resource->evaluations[] = [
|
||||
'evaluationId' => $evaluationId,
|
||||
'title' => $title,
|
||||
'average' => $average !== null ? (float) $average : null,
|
||||
'min' => $minGrade !== null ? (float) $minGrade : null,
|
||||
'max' => $maxGrade !== null ? (float) $maxGrade : null,
|
||||
'median' => $medianGrade !== null ? (float) $medianGrade : null,
|
||||
'gradedCount' => $gradedCount !== null ? (int) $gradedCount : 0,
|
||||
];
|
||||
}
|
||||
|
||||
return $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $userRoles
|
||||
* @param list<string> $allowedRoles
|
||||
*/
|
||||
private function hasAnyRole(array $userRoles, array $allowedRoles): bool
|
||||
{
|
||||
foreach ($userRoles as $role) {
|
||||
if (in_array($role, $allowedRoles, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Provider;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Administration\Infrastructure\Security\SecurityUser;
|
||||
use App\Scolarite\Infrastructure\Api\Resource\CompetencyResource;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
|
||||
use function array_map;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Override;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
/**
|
||||
* @implements ProviderInterface<CompetencyResource>
|
||||
*/
|
||||
final readonly class CompetencyCollectionProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private Connection $connection,
|
||||
private TenantContext $tenantContext,
|
||||
private Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
/** @return array<CompetencyResource> */
|
||||
#[Override]
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): array
|
||||
{
|
||||
if (!$this->tenantContext->hasTenant()) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Tenant non défini.');
|
||||
}
|
||||
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof SecurityUser) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Authentification requise.');
|
||||
}
|
||||
|
||||
$tenantId = (string) $this->tenantContext->getCurrentTenantId();
|
||||
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
'SELECT c.id, c.framework_id, c.code, c.name, c.description, c.parent_id, c.sort_order,
|
||||
cf.name AS framework_name
|
||||
FROM competencies c
|
||||
JOIN competency_frameworks cf ON cf.id = c.framework_id
|
||||
WHERE cf.tenant_id = :tenant_id
|
||||
AND cf.is_default = true
|
||||
ORDER BY c.sort_order ASC',
|
||||
['tenant_id' => $tenantId],
|
||||
);
|
||||
|
||||
return array_map(static function (array $row): CompetencyResource {
|
||||
$resource = new CompetencyResource();
|
||||
/** @var string $id */
|
||||
$id = $row['id'];
|
||||
$resource->id = $id;
|
||||
/** @var string $frameworkId */
|
||||
$frameworkId = $row['framework_id'];
|
||||
$resource->frameworkId = $frameworkId;
|
||||
/** @var string $frameworkName */
|
||||
$frameworkName = $row['framework_name'];
|
||||
$resource->frameworkName = $frameworkName;
|
||||
/** @var string $code */
|
||||
$code = $row['code'];
|
||||
$resource->code = $code;
|
||||
/** @var string $name */
|
||||
$name = $row['name'];
|
||||
$resource->name = $name;
|
||||
/** @var string|null $description */
|
||||
$description = $row['description'];
|
||||
$resource->description = $description;
|
||||
/** @var string|null $parentId */
|
||||
$parentId = $row['parent_id'];
|
||||
$resource->parentId = $parentId;
|
||||
/** @var string|int $sortOrder */
|
||||
$sortOrder = $row['sort_order'];
|
||||
$resource->sortOrder = (int) $sortOrder;
|
||||
|
||||
return $resource;
|
||||
}, $rows);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Provider;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Administration\Infrastructure\Security\SecurityUser;
|
||||
use App\Scolarite\Domain\Model\Evaluation\EvaluationId;
|
||||
use App\Scolarite\Domain\Repository\EvaluationRepository;
|
||||
use App\Scolarite\Infrastructure\Api\Resource\CompetencyEvaluationResource;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
|
||||
use function array_map;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
|
||||
use function is_string;
|
||||
|
||||
use Override;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
/**
|
||||
* @implements ProviderInterface<CompetencyEvaluationResource>
|
||||
*/
|
||||
final readonly class CompetencyEvaluationCollectionProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private Connection $connection,
|
||||
private EvaluationRepository $evaluationRepository,
|
||||
private TenantContext $tenantContext,
|
||||
private Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
/** @return array<CompetencyEvaluationResource> */
|
||||
#[Override]
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): array
|
||||
{
|
||||
if (!$this->tenantContext->hasTenant()) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Tenant non défini.');
|
||||
}
|
||||
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof SecurityUser) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Authentification requise.');
|
||||
}
|
||||
|
||||
/** @var string $evaluationIdStr */
|
||||
$evaluationIdStr = $uriVariables['evaluationId'] ?? '';
|
||||
|
||||
if (!is_string($evaluationIdStr) || $evaluationIdStr === '') {
|
||||
throw new NotFoundHttpException('Évaluation non trouvée.');
|
||||
}
|
||||
|
||||
$tenantId = $this->tenantContext->getCurrentTenantId();
|
||||
$evaluationId = EvaluationId::fromString($evaluationIdStr);
|
||||
|
||||
$evaluation = $this->evaluationRepository->findById($evaluationId, $tenantId);
|
||||
|
||||
if ($evaluation === null) {
|
||||
throw new NotFoundHttpException('Évaluation non trouvée.');
|
||||
}
|
||||
|
||||
if ((string) $evaluation->teacherId !== $user->userId()) {
|
||||
throw new AccessDeniedHttpException('Accès refusé.');
|
||||
}
|
||||
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
'SELECT ce.id, ce.evaluation_id, ce.competency_id,
|
||||
c.code AS competency_code, c.name AS competency_name
|
||||
FROM competency_evaluations ce
|
||||
JOIN competencies c ON c.id = ce.competency_id
|
||||
WHERE ce.evaluation_id = :evaluation_id
|
||||
ORDER BY c.sort_order ASC',
|
||||
['evaluation_id' => $evaluationIdStr],
|
||||
);
|
||||
|
||||
return array_map(static function (array $row): CompetencyEvaluationResource {
|
||||
$resource = new CompetencyEvaluationResource();
|
||||
/** @var string $id */
|
||||
$id = $row['id'];
|
||||
$resource->id = $id;
|
||||
/** @var string $evaluationId */
|
||||
$evaluationId = $row['evaluation_id'];
|
||||
$resource->evaluationId = $evaluationId;
|
||||
/** @var string $competencyId */
|
||||
$competencyId = $row['competency_id'];
|
||||
$resource->competencyId = $competencyId;
|
||||
/** @var string $code */
|
||||
$code = $row['competency_code'];
|
||||
$resource->competencyCode = $code;
|
||||
/** @var string $name */
|
||||
$name = $row['competency_name'];
|
||||
$resource->competencyName = $name;
|
||||
|
||||
return $resource;
|
||||
}, $rows);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Provider;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Administration\Infrastructure\Security\SecurityUser;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyLevel;
|
||||
use App\Scolarite\Domain\Repository\CustomCompetencyLevelRepository;
|
||||
use App\Scolarite\Infrastructure\Api\Resource\CompetencyLevelResource;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
use Override;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
/**
|
||||
* @implements ProviderInterface<CompetencyLevelResource>
|
||||
*/
|
||||
final readonly class CompetencyLevelCollectionProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private CustomCompetencyLevelRepository $customLevelRepository,
|
||||
private TenantContext $tenantContext,
|
||||
private Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
/** @return array<CompetencyLevelResource> */
|
||||
#[Override]
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): array
|
||||
{
|
||||
if (!$this->tenantContext->hasTenant()) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Tenant non défini.');
|
||||
}
|
||||
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof SecurityUser) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Authentification requise.');
|
||||
}
|
||||
|
||||
$tenantId = $this->tenantContext->getCurrentTenantId();
|
||||
|
||||
// Utiliser les niveaux personnalisés si définis, sinon les niveaux standards
|
||||
$customLevels = $this->customLevelRepository->findByTenant($tenantId);
|
||||
|
||||
if ($customLevels !== []) {
|
||||
$resources = [];
|
||||
foreach ($customLevels as $level) {
|
||||
$resource = new CompetencyLevelResource();
|
||||
$resource->code = $level->code;
|
||||
$resource->name = $level->name;
|
||||
$resource->color = $level->color;
|
||||
$resource->sortOrder = $level->sortOrder;
|
||||
$resources[] = $resource;
|
||||
}
|
||||
|
||||
return $resources;
|
||||
}
|
||||
|
||||
// Niveaux standards par défaut
|
||||
$resources = [];
|
||||
foreach (CompetencyLevel::cases() as $level) {
|
||||
$resource = new CompetencyLevelResource();
|
||||
$resource->code = $level->value;
|
||||
$resource->name = $level->label();
|
||||
$resource->color = $level->color();
|
||||
$resource->sortOrder = $level->sortOrder();
|
||||
$resources[] = $resource;
|
||||
}
|
||||
|
||||
return $resources;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Provider;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Administration\Infrastructure\Security\SecurityUser;
|
||||
use App\Scolarite\Domain\Model\Evaluation\EvaluationId;
|
||||
use App\Scolarite\Domain\Repository\EvaluationRepository;
|
||||
use App\Scolarite\Infrastructure\Api\Resource\CompetencyResultResource;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
|
||||
use function array_map;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
|
||||
use function is_string;
|
||||
|
||||
use Override;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
/**
|
||||
* @implements ProviderInterface<CompetencyResultResource>
|
||||
*/
|
||||
final readonly class CompetencyResultCollectionProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private Connection $connection,
|
||||
private EvaluationRepository $evaluationRepository,
|
||||
private TenantContext $tenantContext,
|
||||
private Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
/** @return array<CompetencyResultResource> */
|
||||
#[Override]
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): array
|
||||
{
|
||||
if (!$this->tenantContext->hasTenant()) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Tenant non défini.');
|
||||
}
|
||||
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof SecurityUser) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Authentification requise.');
|
||||
}
|
||||
|
||||
/** @var string $evaluationIdStr */
|
||||
$evaluationIdStr = $uriVariables['evaluationId'] ?? '';
|
||||
|
||||
if (!is_string($evaluationIdStr) || $evaluationIdStr === '') {
|
||||
throw new NotFoundHttpException('Évaluation non trouvée.');
|
||||
}
|
||||
|
||||
$tenantId = $this->tenantContext->getCurrentTenantId();
|
||||
$evaluationId = EvaluationId::fromString($evaluationIdStr);
|
||||
|
||||
$evaluation = $this->evaluationRepository->findById($evaluationId, $tenantId);
|
||||
|
||||
if ($evaluation === null) {
|
||||
throw new NotFoundHttpException('Évaluation non trouvée.');
|
||||
}
|
||||
|
||||
if ((string) $evaluation->teacherId !== $user->userId()) {
|
||||
throw new AccessDeniedHttpException('Accès refusé.');
|
||||
}
|
||||
|
||||
$classId = (string) $evaluation->classId;
|
||||
|
||||
// Matrice : élèves x compétences avec LEFT JOIN sur les résultats
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
'SELECT u.id AS student_id, u.first_name, u.last_name,
|
||||
ce.id AS competency_evaluation_id, ce.competency_id,
|
||||
c.code AS competency_code, c.name AS competency_name,
|
||||
scr.id AS result_id, scr.level_code
|
||||
FROM class_assignments ca
|
||||
JOIN users u ON u.id = ca.user_id
|
||||
CROSS JOIN competency_evaluations ce
|
||||
JOIN competencies c ON c.id = ce.competency_id
|
||||
LEFT JOIN student_competency_results scr
|
||||
ON scr.competency_evaluation_id = ce.id
|
||||
AND scr.student_id = u.id
|
||||
AND scr.tenant_id = :tenant_id
|
||||
WHERE ca.school_class_id = :class_id
|
||||
AND ca.tenant_id = :tenant_id
|
||||
AND ce.evaluation_id = :evaluation_id
|
||||
ORDER BY u.last_name ASC, u.first_name ASC, c.sort_order ASC',
|
||||
[
|
||||
'evaluation_id' => $evaluationIdStr,
|
||||
'tenant_id' => (string) $tenantId,
|
||||
'class_id' => $classId,
|
||||
],
|
||||
);
|
||||
|
||||
return array_map(static function (array $row) use ($evaluationIdStr): CompetencyResultResource {
|
||||
$resource = new CompetencyResultResource();
|
||||
/** @var string $studentId */
|
||||
$studentId = $row['student_id'];
|
||||
/** @var string|null $resultId */
|
||||
$resultId = $row['result_id'];
|
||||
/** @var string $ceId */
|
||||
$ceId = $row['competency_evaluation_id'];
|
||||
/** @var string $competencyId */
|
||||
$competencyId = $row['competency_id'];
|
||||
$resource->id = $resultId ?? 'pending-' . $studentId . '-' . $ceId;
|
||||
$resource->evaluationId = $evaluationIdStr;
|
||||
$resource->competencyEvaluationId = $ceId;
|
||||
$resource->competencyId = $competencyId;
|
||||
/** @var string $competencyCode */
|
||||
$competencyCode = $row['competency_code'];
|
||||
$resource->competencyCode = $competencyCode;
|
||||
/** @var string $competencyName */
|
||||
$competencyName = $row['competency_name'];
|
||||
$resource->competencyName = $competencyName;
|
||||
$resource->studentId = $studentId;
|
||||
/** @var string|null $firstName */
|
||||
$firstName = $row['first_name'];
|
||||
/** @var string|null $lastName */
|
||||
$lastName = $row['last_name'];
|
||||
$resource->studentName = $lastName . ' ' . $firstName;
|
||||
/** @var string|null $levelCode */
|
||||
$levelCode = $row['level_code'];
|
||||
$resource->levelCode = $levelCode;
|
||||
|
||||
return $resource;
|
||||
}, $rows);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Provider;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Administration\Infrastructure\Security\SecurityUser;
|
||||
use App\Scolarite\Domain\Model\Evaluation\EvaluationId;
|
||||
use App\Scolarite\Domain\Repository\EvaluationRepository;
|
||||
use App\Scolarite\Domain\Repository\EvaluationStatisticsRepository;
|
||||
use App\Scolarite\Infrastructure\Api\Resource\EvaluationStatisticsResource;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
use InvalidArgumentException;
|
||||
use Override;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
/**
|
||||
* @implements ProviderInterface<EvaluationStatisticsResource>
|
||||
*/
|
||||
final readonly class EvaluationStatisticsProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private EvaluationRepository $evaluationRepository,
|
||||
private EvaluationStatisticsRepository $evaluationStatisticsRepository,
|
||||
private TenantContext $tenantContext,
|
||||
private Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): EvaluationStatisticsResource
|
||||
{
|
||||
if (!$this->tenantContext->hasTenant()) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Tenant non défini.');
|
||||
}
|
||||
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof SecurityUser) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Authentification requise.');
|
||||
}
|
||||
|
||||
/** @var string $evaluationId */
|
||||
$evaluationId = $uriVariables['evaluationId'];
|
||||
|
||||
try {
|
||||
$evalId = EvaluationId::fromString($evaluationId);
|
||||
} catch (InvalidArgumentException) {
|
||||
throw new BadRequestHttpException('Identifiant d\'évaluation invalide.');
|
||||
}
|
||||
|
||||
$tenantId = $this->tenantContext->getCurrentTenantId();
|
||||
|
||||
$evaluation = $this->evaluationRepository->findById($evalId, $tenantId);
|
||||
|
||||
if ($evaluation === null) {
|
||||
throw new NotFoundHttpException('Évaluation non trouvée.');
|
||||
}
|
||||
|
||||
if ((string) $evaluation->teacherId !== $user->userId()) {
|
||||
throw new AccessDeniedHttpException('Vous n\'êtes pas le propriétaire de cette évaluation.');
|
||||
}
|
||||
|
||||
$statistics = $this->evaluationStatisticsRepository->findByEvaluation($evalId);
|
||||
|
||||
if ($statistics === null) {
|
||||
throw new NotFoundHttpException('Statistiques non disponibles pour cette évaluation.');
|
||||
}
|
||||
|
||||
return EvaluationStatisticsResource::fromStatistics($evaluationId, $statistics);
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,8 @@ final readonly class GradeCollectionProvider implements ProviderInterface
|
||||
// Return all students in the class, with LEFT JOIN to grades
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
'SELECT u.id AS student_id, u.first_name, u.last_name,
|
||||
g.id AS grade_id, g.evaluation_id, g.value, g.status AS grade_status
|
||||
g.id AS grade_id, g.evaluation_id, g.value, g.status AS grade_status,
|
||||
g.appreciation
|
||||
FROM class_assignments ca
|
||||
JOIN users u ON u.id = ca.user_id
|
||||
LEFT JOIN grades g ON g.student_id = u.id AND g.evaluation_id = :evaluation_id AND g.tenant_id = :tenant_id
|
||||
@@ -96,7 +97,7 @@ final readonly class GradeCollectionProvider implements ProviderInterface
|
||||
$studentId = $row['student_id'];
|
||||
/** @var string|null $gradeId */
|
||||
$gradeId = $row['grade_id'] ?? null;
|
||||
$resource->id = $gradeId ?? $studentId;
|
||||
$resource->id = $gradeId ?? 'pending-' . $studentId;
|
||||
$resource->evaluationId = $evaluationIdStr;
|
||||
$resource->studentId = $studentId;
|
||||
/** @var string|null $firstName */
|
||||
@@ -112,6 +113,9 @@ final readonly class GradeCollectionProvider implements ProviderInterface
|
||||
/** @var string|null $gradeStatus */
|
||||
$gradeStatus = $row['grade_status'] ?? null;
|
||||
$resource->status = $gradeStatus;
|
||||
/** @var string|null $appreciation */
|
||||
$appreciation = $row['appreciation'] ?? null;
|
||||
$resource->appreciation = $appreciation;
|
||||
|
||||
return $resource;
|
||||
}, $rows);
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Provider;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Administration\Domain\Model\User\Role;
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Administration\Infrastructure\Security\SecurityUser;
|
||||
use App\Scolarite\Domain\Repository\StudentAverageRepository;
|
||||
use App\Scolarite\Infrastructure\Api\Resource\StudentAveragesResource;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
|
||||
use function in_array;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Override;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
/**
|
||||
* @implements ProviderInterface<StudentAveragesResource>
|
||||
*/
|
||||
final readonly class StudentAveragesProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private StudentAverageRepository $studentAverageRepository,
|
||||
private TenantContext $tenantContext,
|
||||
private Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): StudentAveragesResource
|
||||
{
|
||||
if (!$this->tenantContext->hasTenant()) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Tenant non défini.');
|
||||
}
|
||||
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof SecurityUser) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Authentification requise.');
|
||||
}
|
||||
|
||||
/** @var string $studentId */
|
||||
$studentId = $uriVariables['studentId'];
|
||||
|
||||
try {
|
||||
$userId = UserId::fromString($studentId);
|
||||
} catch (InvalidArgumentException) {
|
||||
throw new BadRequestHttpException('Identifiant d\'élève invalide.');
|
||||
}
|
||||
|
||||
// L'élève peut voir ses propres moyennes, les enseignants et admins aussi
|
||||
$isOwner = $user->userId() === $studentId;
|
||||
$isStaff = $this->hasAnyRole($user->getRoles(), [
|
||||
Role::ADMIN->value,
|
||||
Role::PROF->value,
|
||||
Role::VIE_SCOLAIRE->value,
|
||||
]);
|
||||
|
||||
if (!$isOwner && !$isStaff) {
|
||||
throw new AccessDeniedHttpException('Accès non autorisé aux moyennes de cet élève.');
|
||||
}
|
||||
|
||||
$tenantId = $this->tenantContext->getCurrentTenantId();
|
||||
|
||||
/** @var array<string, mixed> $filters */
|
||||
$filters = $context['filters'] ?? [];
|
||||
/** @var string|null $periodId */
|
||||
$periodId = $filters['periodId'] ?? null;
|
||||
|
||||
$resource = new StudentAveragesResource();
|
||||
$resource->studentId = $studentId;
|
||||
$resource->periodId = $periodId;
|
||||
|
||||
if ($periodId === null) {
|
||||
return $resource;
|
||||
}
|
||||
|
||||
$resource->subjectAverages = $this->studentAverageRepository->findDetailedSubjectAveragesForStudent(
|
||||
$userId,
|
||||
$periodId,
|
||||
$tenantId,
|
||||
);
|
||||
|
||||
$resource->generalAverage = $this->studentAverageRepository->findGeneralAverageForStudent(
|
||||
$userId,
|
||||
$periodId,
|
||||
$tenantId,
|
||||
);
|
||||
|
||||
return $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $userRoles
|
||||
* @param list<string> $allowedRoles
|
||||
*/
|
||||
private function hasAnyRole(array $userRoles, array $allowedRoles): bool
|
||||
{
|
||||
foreach ($userRoles as $role) {
|
||||
if (in_array($role, $allowedRoles, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Provider;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Administration\Infrastructure\Security\SecurityUser;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyLevel;
|
||||
use App\Scolarite\Domain\Repository\CustomCompetencyLevelRepository;
|
||||
use App\Scolarite\Infrastructure\Api\Resource\StudentCompetencyProgressResource;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
|
||||
use function array_values;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
|
||||
use function is_string;
|
||||
|
||||
use Override;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
/**
|
||||
* @implements ProviderInterface<StudentCompetencyProgressResource>
|
||||
*/
|
||||
final readonly class StudentCompetencyProgressProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private Connection $connection,
|
||||
private CustomCompetencyLevelRepository $customLevelRepository,
|
||||
private TenantContext $tenantContext,
|
||||
private Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
/** @return array<StudentCompetencyProgressResource> */
|
||||
#[Override]
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): array
|
||||
{
|
||||
if (!$this->tenantContext->hasTenant()) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Tenant non défini.');
|
||||
}
|
||||
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof SecurityUser) {
|
||||
throw new UnauthorizedHttpException('Bearer', 'Authentification requise.');
|
||||
}
|
||||
|
||||
/** @var string $studentIdStr */
|
||||
$studentIdStr = $uriVariables['studentId'] ?? '';
|
||||
|
||||
if (!is_string($studentIdStr) || $studentIdStr === '') {
|
||||
throw new NotFoundHttpException('Élève non trouvé.');
|
||||
}
|
||||
|
||||
// Un élève ne peut consulter que sa propre progression
|
||||
if ($studentIdStr !== $user->userId() && !$this->security->isGranted('ROLE_PROF') && !$this->security->isGranted('ROLE_ADMIN')) {
|
||||
throw new AccessDeniedHttpException('Accès refusé.');
|
||||
}
|
||||
|
||||
$tenantId = (string) $this->tenantContext->getCurrentTenantId();
|
||||
|
||||
// Récupérer tous les résultats de compétences pour l'élève, avec historique
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
'SELECT c.id AS competency_id, c.code AS competency_code, c.name AS competency_name,
|
||||
scr.level_code, e.evaluation_date, e.title AS evaluation_title
|
||||
FROM student_competency_results scr
|
||||
JOIN competency_evaluations ce ON ce.id = scr.competency_evaluation_id
|
||||
JOIN competencies c ON c.id = ce.competency_id
|
||||
JOIN evaluations e ON e.id = ce.evaluation_id
|
||||
WHERE scr.student_id = :student_id
|
||||
AND scr.tenant_id = :tenant_id
|
||||
ORDER BY c.sort_order ASC, e.evaluation_date ASC',
|
||||
[
|
||||
'student_id' => $studentIdStr,
|
||||
'tenant_id' => $tenantId,
|
||||
],
|
||||
);
|
||||
|
||||
// Build level name map (custom levels override standard)
|
||||
$levelNameMap = [];
|
||||
$customLevels = $this->customLevelRepository->findByTenant(TenantId::fromString($tenantId));
|
||||
if ($customLevels !== []) {
|
||||
foreach ($customLevels as $cl) {
|
||||
$levelNameMap[$cl->code] = $cl->name;
|
||||
}
|
||||
} else {
|
||||
foreach (CompetencyLevel::cases() as $sl) {
|
||||
$levelNameMap[$sl->value] = $sl->label();
|
||||
}
|
||||
}
|
||||
|
||||
// Grouper par compétence
|
||||
/** @var array<string, StudentCompetencyProgressResource> $progressByCompetency */
|
||||
$progressByCompetency = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
/** @var string $competencyId */
|
||||
$competencyId = $row['competency_id'];
|
||||
/** @var string $levelCode */
|
||||
$levelCode = $row['level_code'];
|
||||
/** @var string $evaluationDate */
|
||||
$evaluationDate = $row['evaluation_date'];
|
||||
/** @var string $evaluationTitle */
|
||||
$evaluationTitle = $row['evaluation_title'];
|
||||
|
||||
if (!isset($progressByCompetency[$competencyId])) {
|
||||
$resource = new StudentCompetencyProgressResource();
|
||||
$resource->competencyId = $competencyId;
|
||||
/** @var string $code */
|
||||
$code = $row['competency_code'];
|
||||
$resource->competencyCode = $code;
|
||||
/** @var string $name */
|
||||
$name = $row['competency_name'];
|
||||
$resource->competencyName = $name;
|
||||
$progressByCompetency[$competencyId] = $resource;
|
||||
}
|
||||
|
||||
$progressByCompetency[$competencyId]->history[] = [
|
||||
'date' => $evaluationDate,
|
||||
'levelCode' => $levelCode,
|
||||
'evaluationTitle' => $evaluationTitle,
|
||||
];
|
||||
|
||||
// Le dernier résultat (trié par date ASC) est le niveau actuel
|
||||
$progressByCompetency[$competencyId]->currentLevelCode = $levelCode;
|
||||
$progressByCompetency[$competencyId]->currentLevelName = $levelNameMap[$levelCode] ?? $levelCode;
|
||||
}
|
||||
|
||||
return array_values($progressByCompetency);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Resource;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Delete;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use ApiPlatform\Metadata\Put;
|
||||
use App\Scolarite\Domain\Model\Grade\AppreciationTemplate;
|
||||
use App\Scolarite\Infrastructure\Api\Processor\CreateAppreciationTemplateProcessor;
|
||||
use App\Scolarite\Infrastructure\Api\Processor\DeleteAppreciationTemplateProcessor;
|
||||
use App\Scolarite\Infrastructure\Api\Processor\UpdateAppreciationTemplateProcessor;
|
||||
use App\Scolarite\Infrastructure\Api\Provider\AppreciationTemplateCollectionProvider;
|
||||
use DateTimeImmutable;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[ApiResource(
|
||||
shortName: 'AppreciationTemplate',
|
||||
operations: [
|
||||
new GetCollection(
|
||||
uriTemplate: '/me/appreciation-templates',
|
||||
provider: AppreciationTemplateCollectionProvider::class,
|
||||
name: 'get_appreciation_templates',
|
||||
),
|
||||
new Post(
|
||||
uriTemplate: '/me/appreciation-templates',
|
||||
read: false,
|
||||
processor: CreateAppreciationTemplateProcessor::class,
|
||||
validationContext: ['groups' => ['Default', 'create']],
|
||||
name: 'create_appreciation_template',
|
||||
),
|
||||
new Put(
|
||||
uriTemplate: '/me/appreciation-templates/{id}',
|
||||
read: false,
|
||||
processor: UpdateAppreciationTemplateProcessor::class,
|
||||
validationContext: ['groups' => ['Default', 'update']],
|
||||
name: 'update_appreciation_template',
|
||||
),
|
||||
new Delete(
|
||||
uriTemplate: '/me/appreciation-templates/{id}',
|
||||
read: false,
|
||||
processor: DeleteAppreciationTemplateProcessor::class,
|
||||
name: 'delete_appreciation_template',
|
||||
),
|
||||
],
|
||||
)]
|
||||
final class AppreciationTemplateResource
|
||||
{
|
||||
#[ApiProperty(identifier: true)]
|
||||
public ?string $id = null;
|
||||
|
||||
#[Assert\NotBlank(groups: ['create', 'update'])]
|
||||
#[Assert\Length(max: 100, groups: ['create', 'update'])]
|
||||
public ?string $title = null;
|
||||
|
||||
#[Assert\NotBlank(groups: ['create', 'update'])]
|
||||
#[Assert\Length(max: 500, groups: ['create', 'update'])]
|
||||
public ?string $content = null;
|
||||
|
||||
public ?string $category = null;
|
||||
|
||||
public ?int $usageCount = null;
|
||||
|
||||
public ?DateTimeImmutable $createdAt = null;
|
||||
|
||||
public ?DateTimeImmutable $updatedAt = null;
|
||||
|
||||
public static function fromDomain(AppreciationTemplate $template): self
|
||||
{
|
||||
$resource = new self();
|
||||
$resource->id = (string) $template->id;
|
||||
$resource->title = $template->title;
|
||||
$resource->content = $template->content;
|
||||
$resource->category = $template->category?->value;
|
||||
$resource->usageCount = $template->usageCount;
|
||||
$resource->createdAt = $template->createdAt;
|
||||
$resource->updatedAt = $template->updatedAt;
|
||||
|
||||
return $resource;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Resource;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Scolarite\Infrastructure\Api\Provider\ClassStatisticsProvider;
|
||||
|
||||
#[ApiResource(
|
||||
shortName: 'ClassStatistics',
|
||||
operations: [
|
||||
new Get(
|
||||
uriTemplate: '/classes/{classId}/statistics',
|
||||
provider: ClassStatisticsProvider::class,
|
||||
name: 'get_class_statistics',
|
||||
),
|
||||
],
|
||||
)]
|
||||
final class ClassStatisticsResource
|
||||
{
|
||||
#[ApiProperty(identifier: true)]
|
||||
public ?string $classId = null;
|
||||
|
||||
public ?string $periodId = null;
|
||||
|
||||
/** @var list<array{evaluationId: string, title: string, average: float|null, min: float|null, max: float|null, median: float|null, gradedCount: int}> */
|
||||
public array $evaluations = [];
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Resource;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use App\Scolarite\Infrastructure\Api\Processor\LinkCompetenciesToEvaluationProcessor;
|
||||
use App\Scolarite\Infrastructure\Api\Provider\CompetencyEvaluationCollectionProvider;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[ApiResource(
|
||||
shortName: 'CompetencyEvaluation',
|
||||
operations: [
|
||||
new GetCollection(
|
||||
uriTemplate: '/evaluations/{evaluationId}/competencies',
|
||||
uriVariables: ['evaluationId'],
|
||||
provider: CompetencyEvaluationCollectionProvider::class,
|
||||
name: 'get_evaluation_competencies',
|
||||
),
|
||||
new Post(
|
||||
uriTemplate: '/evaluations/{evaluationId}/competencies',
|
||||
uriVariables: ['evaluationId'],
|
||||
read: false,
|
||||
processor: LinkCompetenciesToEvaluationProcessor::class,
|
||||
validationContext: ['groups' => ['Default', 'create']],
|
||||
name: 'link_competencies_to_evaluation',
|
||||
),
|
||||
],
|
||||
)]
|
||||
final class CompetencyEvaluationResource
|
||||
{
|
||||
#[ApiProperty(identifier: true)]
|
||||
public ?string $id = null;
|
||||
|
||||
public ?string $evaluationId = null;
|
||||
|
||||
public ?string $competencyId = null;
|
||||
|
||||
public ?string $competencyCode = null;
|
||||
|
||||
public ?string $competencyName = null;
|
||||
|
||||
/** @var array<string>|null */
|
||||
#[Assert\NotBlank(message: 'Les compétences sont requises.', groups: ['create'])]
|
||||
public ?array $competencyIds = null;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Resource;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use App\Scolarite\Infrastructure\Api\Provider\CompetencyLevelCollectionProvider;
|
||||
|
||||
#[ApiResource(
|
||||
shortName: 'CompetencyLevel',
|
||||
operations: [
|
||||
new GetCollection(
|
||||
uriTemplate: '/competency-levels',
|
||||
provider: CompetencyLevelCollectionProvider::class,
|
||||
name: 'get_competency_level_list',
|
||||
),
|
||||
],
|
||||
)]
|
||||
final class CompetencyLevelResource
|
||||
{
|
||||
#[ApiProperty(identifier: true)]
|
||||
public ?string $code = null;
|
||||
|
||||
public ?string $name = null;
|
||||
|
||||
public ?string $color = null;
|
||||
|
||||
public int $sortOrder = 0;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Resource;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use App\Scolarite\Infrastructure\Api\Provider\CompetencyCollectionProvider;
|
||||
|
||||
#[ApiResource(
|
||||
shortName: 'Competency',
|
||||
operations: [
|
||||
new GetCollection(
|
||||
uriTemplate: '/competencies',
|
||||
provider: CompetencyCollectionProvider::class,
|
||||
name: 'get_competency_list',
|
||||
),
|
||||
],
|
||||
)]
|
||||
final class CompetencyResource
|
||||
{
|
||||
#[ApiProperty(identifier: true)]
|
||||
public ?string $id = null;
|
||||
|
||||
public ?string $frameworkId = null;
|
||||
|
||||
public ?string $frameworkName = null;
|
||||
|
||||
public ?string $code = null;
|
||||
|
||||
public ?string $name = null;
|
||||
|
||||
public ?string $description = null;
|
||||
|
||||
public ?string $parentId = null;
|
||||
|
||||
public int $sortOrder = 0;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Resource;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use ApiPlatform\Metadata\Put;
|
||||
use App\Scolarite\Infrastructure\Api\Processor\SaveCompetencyResultsProcessor;
|
||||
use App\Scolarite\Infrastructure\Api\Provider\CompetencyResultCollectionProvider;
|
||||
|
||||
#[ApiResource(
|
||||
shortName: 'CompetencyResult',
|
||||
operations: [
|
||||
new GetCollection(
|
||||
uriTemplate: '/evaluations/{evaluationId}/competency-results',
|
||||
uriVariables: ['evaluationId'],
|
||||
provider: CompetencyResultCollectionProvider::class,
|
||||
name: 'get_competency_result_list',
|
||||
),
|
||||
new Put(
|
||||
uriTemplate: '/evaluations/{evaluationId}/competency-results',
|
||||
uriVariables: ['evaluationId'],
|
||||
read: false,
|
||||
processor: SaveCompetencyResultsProcessor::class,
|
||||
name: 'save_competency_results',
|
||||
),
|
||||
],
|
||||
)]
|
||||
final class CompetencyResultResource
|
||||
{
|
||||
#[ApiProperty(identifier: true)]
|
||||
public ?string $id = null;
|
||||
|
||||
public ?string $evaluationId = null;
|
||||
|
||||
public ?string $competencyEvaluationId = null;
|
||||
|
||||
public ?string $competencyId = null;
|
||||
|
||||
public ?string $competencyCode = null;
|
||||
|
||||
public ?string $competencyName = null;
|
||||
|
||||
public ?string $studentId = null;
|
||||
|
||||
public ?string $studentName = null;
|
||||
|
||||
public ?string $levelCode = null;
|
||||
|
||||
public ?string $levelName = null;
|
||||
|
||||
/** @var array<array{studentId: string, competencyEvaluationId: string, levelCode: string}>|null */
|
||||
public ?array $results = null;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Resource;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Scolarite\Domain\Model\Evaluation\ClassStatistics;
|
||||
use App\Scolarite\Infrastructure\Api\Provider\EvaluationStatisticsProvider;
|
||||
|
||||
#[ApiResource(
|
||||
shortName: 'EvaluationStatistics',
|
||||
operations: [
|
||||
new Get(
|
||||
uriTemplate: '/evaluations/{evaluationId}/statistics',
|
||||
provider: EvaluationStatisticsProvider::class,
|
||||
name: 'get_evaluation_statistics',
|
||||
),
|
||||
],
|
||||
)]
|
||||
final class EvaluationStatisticsResource
|
||||
{
|
||||
#[ApiProperty(identifier: true)]
|
||||
public ?string $evaluationId = null;
|
||||
|
||||
public ?float $average = null;
|
||||
|
||||
public ?float $min = null;
|
||||
|
||||
public ?float $max = null;
|
||||
|
||||
public ?float $median = null;
|
||||
|
||||
public int $gradedCount = 0;
|
||||
|
||||
public static function fromStatistics(string $evaluationId, ClassStatistics $statistics): self
|
||||
{
|
||||
$resource = new self();
|
||||
$resource->evaluationId = $evaluationId;
|
||||
$resource->average = $statistics->average;
|
||||
$resource->min = $statistics->min;
|
||||
$resource->max = $statistics->max;
|
||||
$resource->median = $statistics->median;
|
||||
$resource->gradedCount = $statistics->gradedCount;
|
||||
|
||||
return $resource;
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ use ApiPlatform\Metadata\Post;
|
||||
use ApiPlatform\Metadata\Put;
|
||||
use App\Scolarite\Domain\Model\Grade\Grade;
|
||||
use App\Scolarite\Infrastructure\Api\Processor\PublishGradesProcessor;
|
||||
use App\Scolarite\Infrastructure\Api\Processor\SaveAppreciationProcessor;
|
||||
use App\Scolarite\Infrastructure\Api\Processor\SaveGradesProcessor;
|
||||
use App\Scolarite\Infrastructure\Api\Provider\GradeCollectionProvider;
|
||||
use DateTimeImmutable;
|
||||
@@ -32,6 +33,12 @@ use DateTimeImmutable;
|
||||
processor: SaveGradesProcessor::class,
|
||||
name: 'save_evaluation_grades',
|
||||
),
|
||||
new Put(
|
||||
uriTemplate: '/grades/{id}/appreciation',
|
||||
read: false,
|
||||
processor: SaveAppreciationProcessor::class,
|
||||
name: 'save_grade_appreciation',
|
||||
),
|
||||
new Post(
|
||||
uriTemplate: '/evaluations/{evaluationId}/publish',
|
||||
uriVariables: ['evaluationId'],
|
||||
@@ -56,6 +63,8 @@ final class GradeResource
|
||||
|
||||
public ?string $status = null;
|
||||
|
||||
public ?string $appreciation = null;
|
||||
|
||||
public ?DateTimeImmutable $createdAt = null;
|
||||
|
||||
public ?DateTimeImmutable $updatedAt = null;
|
||||
@@ -76,6 +85,7 @@ final class GradeResource
|
||||
$resource->studentName = $studentName;
|
||||
$resource->value = $grade->value?->value;
|
||||
$resource->status = $grade->status->value;
|
||||
$resource->appreciation = $grade->appreciation;
|
||||
$resource->createdAt = $grade->createdAt;
|
||||
$resource->updatedAt = $grade->updatedAt;
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Resource;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Scolarite\Infrastructure\Api\Provider\StudentAveragesProvider;
|
||||
|
||||
#[ApiResource(
|
||||
shortName: 'StudentAverages',
|
||||
operations: [
|
||||
new Get(
|
||||
uriTemplate: '/students/{studentId}/averages',
|
||||
provider: StudentAveragesProvider::class,
|
||||
name: 'get_student_averages',
|
||||
),
|
||||
],
|
||||
)]
|
||||
final class StudentAveragesResource
|
||||
{
|
||||
#[ApiProperty(identifier: true)]
|
||||
public ?string $studentId = null;
|
||||
|
||||
public ?string $periodId = null;
|
||||
|
||||
/** @var list<array{subjectId: string, subjectName: string|null, average: float, gradeCount: int}> */
|
||||
public array $subjectAverages = [];
|
||||
|
||||
public ?float $generalAverage = null;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Api\Resource;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use App\Scolarite\Infrastructure\Api\Provider\StudentCompetencyProgressProvider;
|
||||
|
||||
#[ApiResource(
|
||||
shortName: 'StudentCompetencyProgress',
|
||||
operations: [
|
||||
new GetCollection(
|
||||
uriTemplate: '/students/{studentId}/competency-progress',
|
||||
uriVariables: ['studentId'],
|
||||
provider: StudentCompetencyProgressProvider::class,
|
||||
name: 'get_student_competency_progress',
|
||||
),
|
||||
],
|
||||
)]
|
||||
final class StudentCompetencyProgressResource
|
||||
{
|
||||
#[ApiProperty(identifier: true)]
|
||||
public ?string $competencyId = null;
|
||||
|
||||
public ?string $competencyCode = null;
|
||||
|
||||
public ?string $competencyName = null;
|
||||
|
||||
public ?string $currentLevelCode = null;
|
||||
|
||||
public ?string $currentLevelName = null;
|
||||
|
||||
/** @var array<array{date: string, levelCode: string, evaluationTitle: string}> */
|
||||
public array $history = [];
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Cache;
|
||||
|
||||
use App\Scolarite\Domain\Model\Evaluation\ClassStatistics;
|
||||
use App\Scolarite\Domain\Model\Evaluation\EvaluationId;
|
||||
use App\Scolarite\Domain\Repository\EvaluationStatisticsRepository;
|
||||
use Override;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
|
||||
final readonly class CachingEvaluationStatisticsRepository implements EvaluationStatisticsRepository
|
||||
{
|
||||
public function __construct(
|
||||
private EvaluationStatisticsRepository $inner,
|
||||
private CacheItemPoolInterface $cache,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function save(EvaluationId $evaluationId, ClassStatistics $statistics): void
|
||||
{
|
||||
$this->inner->save($evaluationId, $statistics);
|
||||
$this->cache->deleteItem($this->cacheKey($evaluationId));
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findByEvaluation(EvaluationId $evaluationId): ?ClassStatistics
|
||||
{
|
||||
$key = $this->cacheKey($evaluationId);
|
||||
$item = $this->cache->getItem($key);
|
||||
|
||||
if ($item->isHit()) {
|
||||
/** @var ClassStatistics|null $cached */
|
||||
$cached = $item->get();
|
||||
|
||||
return $cached;
|
||||
}
|
||||
|
||||
$stats = $this->inner->findByEvaluation($evaluationId);
|
||||
|
||||
$item->set($stats);
|
||||
$this->cache->save($item);
|
||||
|
||||
return $stats;
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function delete(EvaluationId $evaluationId): void
|
||||
{
|
||||
$this->inner->delete($evaluationId);
|
||||
$this->cache->deleteItem($this->cacheKey($evaluationId));
|
||||
}
|
||||
|
||||
private function cacheKey(EvaluationId $evaluationId): string
|
||||
{
|
||||
return 'eval_stats_' . $evaluationId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Cache;
|
||||
|
||||
use App\Administration\Domain\Model\Subject\SubjectId;
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Domain\Repository\StudentAverageRepository;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use Override;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
|
||||
final readonly class CachingStudentAverageRepository implements StudentAverageRepository
|
||||
{
|
||||
public function __construct(
|
||||
private StudentAverageRepository $inner,
|
||||
private CacheItemPoolInterface $cache,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function saveSubjectAverage(
|
||||
TenantId $tenantId,
|
||||
UserId $studentId,
|
||||
SubjectId $subjectId,
|
||||
string $periodId,
|
||||
float $average,
|
||||
int $gradeCount,
|
||||
): void {
|
||||
$this->inner->saveSubjectAverage($tenantId, $studentId, $subjectId, $periodId, $average, $gradeCount);
|
||||
|
||||
// Invalider le cache des moyennes matières de l'élève
|
||||
$this->cache->deleteItem($this->subjectAveragesKey($studentId, $periodId, $tenantId));
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function saveGeneralAverage(
|
||||
TenantId $tenantId,
|
||||
UserId $studentId,
|
||||
string $periodId,
|
||||
float $average,
|
||||
): void {
|
||||
$this->inner->saveGeneralAverage($tenantId, $studentId, $periodId, $average);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findSubjectAveragesForStudent(
|
||||
UserId $studentId,
|
||||
string $periodId,
|
||||
TenantId $tenantId,
|
||||
): array {
|
||||
$key = $this->subjectAveragesKey($studentId, $periodId, $tenantId);
|
||||
$item = $this->cache->getItem($key);
|
||||
|
||||
if ($item->isHit()) {
|
||||
/** @var list<float> $cached */
|
||||
$cached = $item->get();
|
||||
|
||||
return $cached;
|
||||
}
|
||||
|
||||
$averages = $this->inner->findSubjectAveragesForStudent($studentId, $periodId, $tenantId);
|
||||
|
||||
$item->set($averages);
|
||||
$this->cache->save($item);
|
||||
|
||||
return $averages;
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findDetailedSubjectAveragesForStudent(
|
||||
UserId $studentId,
|
||||
string $periodId,
|
||||
TenantId $tenantId,
|
||||
): array {
|
||||
return $this->inner->findDetailedSubjectAveragesForStudent($studentId, $periodId, $tenantId);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findGeneralAverageForStudent(
|
||||
UserId $studentId,
|
||||
string $periodId,
|
||||
TenantId $tenantId,
|
||||
): ?float {
|
||||
return $this->inner->findGeneralAverageForStudent($studentId, $periodId, $tenantId);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function deleteSubjectAverage(
|
||||
UserId $studentId,
|
||||
SubjectId $subjectId,
|
||||
string $periodId,
|
||||
TenantId $tenantId,
|
||||
): void {
|
||||
$this->inner->deleteSubjectAverage($studentId, $subjectId, $periodId, $tenantId);
|
||||
$this->cache->deleteItem($this->subjectAveragesKey($studentId, $periodId, $tenantId));
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function deleteGeneralAverage(
|
||||
UserId $studentId,
|
||||
string $periodId,
|
||||
TenantId $tenantId,
|
||||
): void {
|
||||
$this->inner->deleteGeneralAverage($studentId, $periodId, $tenantId);
|
||||
}
|
||||
|
||||
private function subjectAveragesKey(UserId $studentId, string $periodId, TenantId $tenantId): string
|
||||
{
|
||||
return 'avg_' . $tenantId . '_' . $studentId . '_' . $periodId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Console;
|
||||
|
||||
use App\Scolarite\Application\Service\RecalculerMoyennesService;
|
||||
use App\Scolarite\Domain\Repository\EvaluationRepository;
|
||||
use App\Shared\Infrastructure\Tenant\TenantConfig;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
use App\Shared\Infrastructure\Tenant\TenantDatabaseSwitcher;
|
||||
use App\Shared\Infrastructure\Tenant\TenantId;
|
||||
use App\Shared\Infrastructure\Tenant\TenantRegistry;
|
||||
|
||||
use function count;
|
||||
|
||||
use Override;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Recalcule toutes les projections de moyennes à partir des données existantes.
|
||||
*
|
||||
* Usage:
|
||||
* php bin/console app:recalculer-moyennes # Tous les tenants
|
||||
* php bin/console app:recalculer-moyennes --tenant=UUID # Un seul tenant
|
||||
*/
|
||||
#[AsCommand(
|
||||
name: 'app:recalculer-moyennes',
|
||||
description: 'Recalcule les statistiques évaluations et moyennes élèves depuis les notes publiées',
|
||||
)]
|
||||
final class RecalculerToutesMoyennesCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EvaluationRepository $evaluationRepository,
|
||||
private readonly TenantRegistry $tenantRegistry,
|
||||
private readonly TenantContext $tenantContext,
|
||||
private readonly TenantDatabaseSwitcher $databaseSwitcher,
|
||||
private readonly RecalculerMoyennesService $service,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
#[Override]
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->addOption('tenant', 't', InputOption::VALUE_REQUIRED, 'Limiter à un tenant spécifique (UUID)');
|
||||
}
|
||||
|
||||
#[Override]
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$io->title('Recalcul des moyennes et statistiques');
|
||||
|
||||
/** @var string|null $tenantOption */
|
||||
$tenantOption = $input->getOption('tenant');
|
||||
|
||||
if ($tenantOption !== null) {
|
||||
$configs = [$this->tenantRegistry->getConfig(TenantId::fromString($tenantOption))];
|
||||
} else {
|
||||
$configs = $this->tenantRegistry->getAllConfigs();
|
||||
}
|
||||
|
||||
$totalEvals = 0;
|
||||
$totalErrors = 0;
|
||||
|
||||
foreach ($configs as $config) {
|
||||
[$processed, $errors] = $this->processTenant($config, $io);
|
||||
$totalEvals += $processed;
|
||||
$totalErrors += $errors;
|
||||
}
|
||||
|
||||
if ($totalErrors > 0) {
|
||||
$io->warning(sprintf(
|
||||
'%d évaluation(s) traitée(s), %d erreur(s).',
|
||||
$totalEvals,
|
||||
$totalErrors,
|
||||
));
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$io->success(sprintf('%d évaluation(s) traitée(s) avec succès.', $totalEvals));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{int, int} [processed, errors]
|
||||
*/
|
||||
private function processTenant(TenantConfig $config, SymfonyStyle $io): array
|
||||
{
|
||||
$this->tenantContext->setCurrentTenant($config);
|
||||
$this->databaseSwitcher->useTenantDatabase($config->databaseUrl);
|
||||
|
||||
$tenantId = \App\Shared\Domain\Tenant\TenantId::fromString((string) $config->tenantId);
|
||||
|
||||
$evaluations = $this->evaluationRepository->findAllWithPublishedGrades($tenantId);
|
||||
|
||||
if ($evaluations === []) {
|
||||
$io->text(sprintf(' Tenant %s : aucune évaluation publiée.', $config->subdomain));
|
||||
|
||||
return [0, 0];
|
||||
}
|
||||
|
||||
$io->text(sprintf(' Tenant %s : %d évaluation(s) publiée(s)', $config->subdomain, count($evaluations)));
|
||||
|
||||
$processed = 0;
|
||||
$errors = 0;
|
||||
|
||||
foreach ($evaluations as $evaluation) {
|
||||
try {
|
||||
$this->service->recalculerStatistiquesEvaluation($evaluation->id, $tenantId);
|
||||
$this->service->recalculerTousElevesPourEvaluation($evaluation->id, $tenantId);
|
||||
++$processed;
|
||||
} catch (Throwable $e) {
|
||||
$io->error(sprintf(' Erreur évaluation %s : %s', $evaluation->id, $e->getMessage()));
|
||||
++$errors;
|
||||
}
|
||||
}
|
||||
|
||||
$io->text(sprintf(' → %d traitée(s), %d erreur(s)', $processed, $errors));
|
||||
|
||||
return [$processed, $errors];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\EventHandler;
|
||||
|
||||
use App\Scolarite\Application\Service\RecalculerMoyennesService;
|
||||
use App\Scolarite\Domain\Event\EvaluationModifiee;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
#[AsMessageHandler(bus: 'event.bus')]
|
||||
final readonly class RecalculerMoyennesOnEvaluationModifieeHandler
|
||||
{
|
||||
public function __construct(
|
||||
private TenantContext $tenantContext,
|
||||
private RecalculerMoyennesService $service,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(EvaluationModifiee $event): void
|
||||
{
|
||||
$tenantId = $this->tenantContext->getCurrentTenantId();
|
||||
|
||||
$this->service->recalculerStatistiquesEvaluation($event->evaluationId, $tenantId);
|
||||
$this->service->recalculerTousElevesPourEvaluation($event->evaluationId, $tenantId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\EventHandler;
|
||||
|
||||
use App\Scolarite\Application\Port\PeriodFinder;
|
||||
use App\Scolarite\Application\Service\RecalculerMoyennesService;
|
||||
use App\Scolarite\Domain\Event\EvaluationSupprimee;
|
||||
use App\Scolarite\Domain\Repository\EvaluationRepository;
|
||||
use App\Scolarite\Domain\Repository\EvaluationStatisticsRepository;
|
||||
use App\Scolarite\Domain\Repository\GradeRepository;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
#[AsMessageHandler(bus: 'event.bus')]
|
||||
final readonly class RecalculerMoyennesOnEvaluationSupprimeeHandler
|
||||
{
|
||||
public function __construct(
|
||||
private TenantContext $tenantContext,
|
||||
private EvaluationRepository $evaluationRepository,
|
||||
private GradeRepository $gradeRepository,
|
||||
private EvaluationStatisticsRepository $evaluationStatisticsRepository,
|
||||
private PeriodFinder $periodFinder,
|
||||
private RecalculerMoyennesService $service,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(EvaluationSupprimee $event): void
|
||||
{
|
||||
$tenantId = $this->tenantContext->getCurrentTenantId();
|
||||
$evaluationId = $event->evaluationId;
|
||||
|
||||
// Charger l'évaluation (encore accessible même en DELETED)
|
||||
$evaluation = $this->evaluationRepository->findById($evaluationId, $tenantId);
|
||||
|
||||
if ($evaluation === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Supprimer les stats de l'évaluation
|
||||
$this->evaluationStatisticsRepository->delete($evaluationId);
|
||||
|
||||
// Si les notes étaient publiées, recalculer les moyennes des élèves affectés
|
||||
if ($evaluation->gradesPublishedAt === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$period = $this->periodFinder->findForDate($evaluation->evaluationDate, $tenantId);
|
||||
|
||||
if ($period === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$grades = $this->gradeRepository->findByEvaluation($evaluationId, $tenantId);
|
||||
$studentIds = [];
|
||||
|
||||
foreach ($grades as $g) {
|
||||
$studentIds[(string) $g->studentId] = $g->studentId;
|
||||
}
|
||||
|
||||
// Recalculer : l'évaluation DELETED sera exclue par findWithPublishedGrades...
|
||||
foreach ($studentIds as $studentId) {
|
||||
$this->service->recalculerMoyenneEleve(
|
||||
$studentId,
|
||||
$evaluation->subjectId,
|
||||
$evaluation->classId,
|
||||
$period,
|
||||
$tenantId,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\EventHandler;
|
||||
|
||||
use App\Scolarite\Application\Port\PeriodFinder;
|
||||
use App\Scolarite\Application\Service\RecalculerMoyennesService;
|
||||
use App\Scolarite\Domain\Event\NoteModifiee;
|
||||
use App\Scolarite\Domain\Event\NoteSaisie;
|
||||
use App\Scolarite\Domain\Model\Evaluation\EvaluationId;
|
||||
use App\Scolarite\Domain\Repository\EvaluationRepository;
|
||||
use App\Scolarite\Domain\Repository\GradeRepository;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
#[AsMessageHandler(bus: 'event.bus')]
|
||||
final readonly class RecalculerMoyennesOnNoteModifieeHandler
|
||||
{
|
||||
public function __construct(
|
||||
private TenantContext $tenantContext,
|
||||
private EvaluationRepository $evaluationRepository,
|
||||
private GradeRepository $gradeRepository,
|
||||
private PeriodFinder $periodFinder,
|
||||
private RecalculerMoyennesService $service,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(NoteSaisie|NoteModifiee $event): void
|
||||
{
|
||||
$tenantId = $this->tenantContext->getCurrentTenantId();
|
||||
$evaluationId = EvaluationId::fromString($event->evaluationId);
|
||||
|
||||
$evaluation = $this->evaluationRepository->findById($evaluationId, $tenantId);
|
||||
|
||||
if ($evaluation === null || !$evaluation->notesPubliees()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->service->recalculerStatistiquesEvaluation($evaluationId, $tenantId);
|
||||
|
||||
$gradeId = $event instanceof NoteSaisie ? $event->gradeId : $event->gradeId;
|
||||
$grade = $this->gradeRepository->findById($gradeId, $tenantId);
|
||||
|
||||
if ($grade === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$period = $this->periodFinder->findForDate($evaluation->evaluationDate, $tenantId);
|
||||
|
||||
if ($period === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->service->recalculerMoyenneEleve(
|
||||
$grade->studentId,
|
||||
$evaluation->subjectId,
|
||||
$evaluation->classId,
|
||||
$period,
|
||||
$tenantId,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\EventHandler;
|
||||
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Application\Port\PeriodFinder;
|
||||
use App\Scolarite\Application\Service\RecalculerMoyennesService;
|
||||
use App\Scolarite\Domain\Event\NotesPubliees;
|
||||
use App\Scolarite\Domain\Model\Grade\GradeStatus;
|
||||
use App\Scolarite\Domain\Repository\EvaluationRepository;
|
||||
use App\Scolarite\Domain\Repository\GradeRepository;
|
||||
use App\Shared\Infrastructure\Tenant\TenantContext;
|
||||
|
||||
use function array_filter;
|
||||
use function array_map;
|
||||
use function array_unique;
|
||||
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
#[AsMessageHandler(bus: 'event.bus')]
|
||||
final readonly class RecalculerMoyennesOnNotesPublieesHandler
|
||||
{
|
||||
public function __construct(
|
||||
private TenantContext $tenantContext,
|
||||
private EvaluationRepository $evaluationRepository,
|
||||
private GradeRepository $gradeRepository,
|
||||
private PeriodFinder $periodFinder,
|
||||
private RecalculerMoyennesService $service,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(NotesPubliees $event): void
|
||||
{
|
||||
$tenantId = $this->tenantContext->getCurrentTenantId();
|
||||
$evaluationId = $event->evaluationId;
|
||||
|
||||
$evaluation = $this->evaluationRepository->findById($evaluationId, $tenantId);
|
||||
|
||||
if ($evaluation === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->service->recalculerStatistiquesEvaluation($evaluationId, $tenantId);
|
||||
|
||||
$period = $this->periodFinder->findForDate($evaluation->evaluationDate, $tenantId);
|
||||
|
||||
if ($period === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$grades = $this->gradeRepository->findByEvaluation($evaluationId, $tenantId);
|
||||
|
||||
$studentIds = array_unique(array_map(
|
||||
static fn ($g) => (string) $g->studentId,
|
||||
array_filter($grades, static fn ($g) => $g->status === GradeStatus::GRADED),
|
||||
));
|
||||
|
||||
foreach ($studentIds as $studentIdStr) {
|
||||
$this->service->recalculerMoyenneEleve(
|
||||
UserId::fromString($studentIdStr),
|
||||
$evaluation->subjectId,
|
||||
$evaluation->classId,
|
||||
$period,
|
||||
$tenantId,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Persistence\Doctrine;
|
||||
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Domain\Model\Grade\AppreciationCategory;
|
||||
use App\Scolarite\Domain\Model\Grade\AppreciationTemplate;
|
||||
use App\Scolarite\Domain\Model\Grade\AppreciationTemplateId;
|
||||
use App\Scolarite\Domain\Repository\AppreciationTemplateRepository;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
|
||||
use function array_map;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Override;
|
||||
|
||||
final readonly class DoctrineAppreciationTemplateRepository implements AppreciationTemplateRepository
|
||||
{
|
||||
public function __construct(
|
||||
private Connection $connection,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function save(AppreciationTemplate $template): void
|
||||
{
|
||||
$this->connection->executeStatement(
|
||||
'INSERT INTO appreciation_templates (id, tenant_id, teacher_id, title, content, category, usage_count, created_at, updated_at)
|
||||
VALUES (:id, :tenant_id, :teacher_id, :title, :content, :category, :usage_count, :created_at, :updated_at)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
title = EXCLUDED.title,
|
||||
content = EXCLUDED.content,
|
||||
category = EXCLUDED.category,
|
||||
usage_count = EXCLUDED.usage_count,
|
||||
updated_at = EXCLUDED.updated_at',
|
||||
[
|
||||
'id' => (string) $template->id,
|
||||
'tenant_id' => (string) $template->tenantId,
|
||||
'teacher_id' => (string) $template->teacherId,
|
||||
'title' => $template->title,
|
||||
'content' => $template->content,
|
||||
'category' => $template->category?->value,
|
||||
'usage_count' => $template->usageCount,
|
||||
'created_at' => $template->createdAt->format(DateTimeImmutable::ATOM),
|
||||
'updated_at' => $template->updatedAt->format(DateTimeImmutable::ATOM),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findById(AppreciationTemplateId $id, TenantId $tenantId): ?AppreciationTemplate
|
||||
{
|
||||
$row = $this->connection->fetchAssociative(
|
||||
'SELECT * FROM appreciation_templates WHERE id = :id AND tenant_id = :tenant_id',
|
||||
['id' => (string) $id, 'tenant_id' => (string) $tenantId],
|
||||
);
|
||||
|
||||
if ($row === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->hydrate($row);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findByTeacher(UserId $teacherId, TenantId $tenantId): array
|
||||
{
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
'SELECT * FROM appreciation_templates
|
||||
WHERE teacher_id = :teacher_id AND tenant_id = :tenant_id
|
||||
ORDER BY usage_count DESC, title ASC',
|
||||
[
|
||||
'teacher_id' => (string) $teacherId,
|
||||
'tenant_id' => (string) $tenantId,
|
||||
],
|
||||
);
|
||||
|
||||
return array_map($this->hydrate(...), $rows);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function delete(AppreciationTemplateId $id, TenantId $tenantId): void
|
||||
{
|
||||
$this->connection->executeStatement(
|
||||
'DELETE FROM appreciation_templates WHERE id = :id AND tenant_id = :tenant_id',
|
||||
['id' => (string) $id, 'tenant_id' => (string) $tenantId],
|
||||
);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $row */
|
||||
private function hydrate(array $row): AppreciationTemplate
|
||||
{
|
||||
/** @var string $id */
|
||||
$id = $row['id'];
|
||||
/** @var string $tenantId */
|
||||
$tenantId = $row['tenant_id'];
|
||||
/** @var string $teacherId */
|
||||
$teacherId = $row['teacher_id'];
|
||||
/** @var string $title */
|
||||
$title = $row['title'];
|
||||
/** @var string $content */
|
||||
$content = $row['content'];
|
||||
/** @var string|null $category */
|
||||
$category = $row['category'] ?? null;
|
||||
/** @var int|string $usageCount */
|
||||
$usageCount = $row['usage_count'];
|
||||
/** @var string $createdAt */
|
||||
$createdAt = $row['created_at'];
|
||||
/** @var string $updatedAt */
|
||||
$updatedAt = $row['updated_at'];
|
||||
|
||||
return AppreciationTemplate::reconstitute(
|
||||
id: AppreciationTemplateId::fromString($id),
|
||||
tenantId: TenantId::fromString($tenantId),
|
||||
teacherId: UserId::fromString($teacherId),
|
||||
title: $title,
|
||||
content: $content,
|
||||
category: $category !== null ? AppreciationCategory::from($category) : null,
|
||||
usageCount: (int) $usageCount,
|
||||
createdAt: new DateTimeImmutable($createdAt),
|
||||
updatedAt: new DateTimeImmutable($updatedAt),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Persistence\Doctrine;
|
||||
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyEvaluation;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyEvaluationId;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyId;
|
||||
use App\Scolarite\Domain\Model\Evaluation\EvaluationId;
|
||||
use App\Scolarite\Domain\Repository\CompetencyEvaluationRepository;
|
||||
|
||||
use function array_map;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Override;
|
||||
|
||||
final readonly class DoctrineCompetencyEvaluationRepository implements CompetencyEvaluationRepository
|
||||
{
|
||||
public function __construct(
|
||||
private Connection $connection,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function save(CompetencyEvaluation $competencyEvaluation): void
|
||||
{
|
||||
$this->connection->executeStatement(
|
||||
'INSERT INTO competency_evaluations (id, evaluation_id, competency_id)
|
||||
VALUES (:id, :evaluation_id, :competency_id)
|
||||
ON CONFLICT (evaluation_id, competency_id) DO UPDATE SET id = competency_evaluations.id',
|
||||
[
|
||||
'id' => (string) $competencyEvaluation->id,
|
||||
'evaluation_id' => (string) $competencyEvaluation->evaluationId,
|
||||
'competency_id' => (string) $competencyEvaluation->competencyId,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findById(CompetencyEvaluationId $id): ?CompetencyEvaluation
|
||||
{
|
||||
$row = $this->connection->fetchAssociative(
|
||||
'SELECT * FROM competency_evaluations WHERE id = :id',
|
||||
['id' => (string) $id],
|
||||
);
|
||||
|
||||
if ($row === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->hydrate($row);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findByEvaluation(EvaluationId $evaluationId): array
|
||||
{
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
'SELECT ce.*, c.code AS competency_code, c.name AS competency_name
|
||||
FROM competency_evaluations ce
|
||||
JOIN competencies c ON c.id = ce.competency_id
|
||||
WHERE ce.evaluation_id = :evaluation_id
|
||||
ORDER BY c.sort_order ASC',
|
||||
['evaluation_id' => (string) $evaluationId],
|
||||
);
|
||||
|
||||
return array_map($this->hydrate(...), $rows);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $row */
|
||||
private function hydrate(array $row): CompetencyEvaluation
|
||||
{
|
||||
/** @var string $id */
|
||||
$id = $row['id'];
|
||||
/** @var string $evaluationId */
|
||||
$evaluationId = $row['evaluation_id'];
|
||||
/** @var string $competencyId */
|
||||
$competencyId = $row['competency_id'];
|
||||
|
||||
return CompetencyEvaluation::reconstitute(
|
||||
id: CompetencyEvaluationId::fromString($id),
|
||||
evaluationId: EvaluationId::fromString($evaluationId),
|
||||
competencyId: CompetencyId::fromString($competencyId),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Persistence\Doctrine;
|
||||
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyFramework;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyFrameworkId;
|
||||
use App\Scolarite\Domain\Repository\CompetencyFrameworkRepository;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
|
||||
use function array_map;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Override;
|
||||
|
||||
final readonly class DoctrineCompetencyFrameworkRepository implements CompetencyFrameworkRepository
|
||||
{
|
||||
public function __construct(
|
||||
private Connection $connection,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function save(CompetencyFramework $framework): void
|
||||
{
|
||||
$this->connection->executeStatement(
|
||||
'INSERT INTO competency_frameworks (id, tenant_id, name, is_default, created_at)
|
||||
VALUES (:id, :tenant_id, :name, :is_default, :created_at)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
name = EXCLUDED.name,
|
||||
is_default = EXCLUDED.is_default',
|
||||
[
|
||||
'id' => (string) $framework->id,
|
||||
'tenant_id' => (string) $framework->tenantId,
|
||||
'name' => $framework->name,
|
||||
'is_default' => $framework->isDefault ? 'true' : 'false',
|
||||
'created_at' => $framework->createdAt->format(DateTimeImmutable::ATOM),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findById(CompetencyFrameworkId $id, TenantId $tenantId): ?CompetencyFramework
|
||||
{
|
||||
$row = $this->connection->fetchAssociative(
|
||||
'SELECT * FROM competency_frameworks WHERE id = :id AND tenant_id = :tenant_id',
|
||||
['id' => (string) $id, 'tenant_id' => (string) $tenantId],
|
||||
);
|
||||
|
||||
if ($row === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->hydrate($row);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findDefault(TenantId $tenantId): ?CompetencyFramework
|
||||
{
|
||||
$row = $this->connection->fetchAssociative(
|
||||
'SELECT * FROM competency_frameworks WHERE tenant_id = :tenant_id AND is_default = true LIMIT 1',
|
||||
['tenant_id' => (string) $tenantId],
|
||||
);
|
||||
|
||||
if ($row === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->hydrate($row);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findByTenant(TenantId $tenantId): array
|
||||
{
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
'SELECT * FROM competency_frameworks WHERE tenant_id = :tenant_id ORDER BY is_default DESC, name ASC',
|
||||
['tenant_id' => (string) $tenantId],
|
||||
);
|
||||
|
||||
return array_map($this->hydrate(...), $rows);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $row */
|
||||
private function hydrate(array $row): CompetencyFramework
|
||||
{
|
||||
/** @var string $id */
|
||||
$id = $row['id'];
|
||||
/** @var string $tenantId */
|
||||
$tenantId = $row['tenant_id'];
|
||||
/** @var string $name */
|
||||
$name = $row['name'];
|
||||
/** @var bool $isDefault */
|
||||
$isDefault = (bool) $row['is_default'];
|
||||
/** @var string $createdAt */
|
||||
$createdAt = $row['created_at'];
|
||||
|
||||
return CompetencyFramework::reconstitute(
|
||||
id: CompetencyFrameworkId::fromString($id),
|
||||
tenantId: TenantId::fromString($tenantId),
|
||||
name: $name,
|
||||
isDefault: $isDefault,
|
||||
createdAt: new DateTimeImmutable($createdAt),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Persistence\Doctrine;
|
||||
|
||||
use App\Scolarite\Domain\Model\Competency\Competency;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyFrameworkId;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyId;
|
||||
use App\Scolarite\Domain\Repository\CompetencyRepository;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
|
||||
use function array_map;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Override;
|
||||
|
||||
final readonly class DoctrineCompetencyRepository implements CompetencyRepository
|
||||
{
|
||||
public function __construct(
|
||||
private Connection $connection,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function save(Competency $competency): void
|
||||
{
|
||||
$this->connection->executeStatement(
|
||||
'INSERT INTO competencies (id, framework_id, code, name, description, parent_id, sort_order)
|
||||
VALUES (:id, :framework_id, :code, :name, :description, :parent_id, :sort_order)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
code = EXCLUDED.code,
|
||||
name = EXCLUDED.name,
|
||||
description = EXCLUDED.description,
|
||||
parent_id = EXCLUDED.parent_id,
|
||||
sort_order = EXCLUDED.sort_order',
|
||||
[
|
||||
'id' => (string) $competency->id,
|
||||
'framework_id' => (string) $competency->frameworkId,
|
||||
'code' => $competency->code,
|
||||
'name' => $competency->name,
|
||||
'description' => $competency->description,
|
||||
'parent_id' => $competency->parentId !== null ? (string) $competency->parentId : null,
|
||||
'sort_order' => $competency->sortOrder,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findById(CompetencyId $id, TenantId $tenantId): ?Competency
|
||||
{
|
||||
$row = $this->connection->fetchAssociative(
|
||||
'SELECT c.* FROM competencies c
|
||||
JOIN competency_frameworks cf ON cf.id = c.framework_id
|
||||
WHERE c.id = :id AND cf.tenant_id = :tenant_id',
|
||||
['id' => (string) $id, 'tenant_id' => (string) $tenantId],
|
||||
);
|
||||
|
||||
if ($row === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->hydrate($row);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findByFramework(CompetencyFrameworkId $frameworkId): array
|
||||
{
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
'SELECT * FROM competencies WHERE framework_id = :framework_id ORDER BY sort_order ASC',
|
||||
['framework_id' => (string) $frameworkId],
|
||||
);
|
||||
|
||||
return array_map($this->hydrate(...), $rows);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $row */
|
||||
private function hydrate(array $row): Competency
|
||||
{
|
||||
/** @var string $id */
|
||||
$id = $row['id'];
|
||||
/** @var string $frameworkId */
|
||||
$frameworkId = $row['framework_id'];
|
||||
/** @var string $code */
|
||||
$code = $row['code'];
|
||||
/** @var string $name */
|
||||
$name = $row['name'];
|
||||
/** @var string|null $description */
|
||||
$description = $row['description'];
|
||||
/** @var string|null $parentId */
|
||||
$parentId = $row['parent_id'];
|
||||
/** @var string|int $sortOrder */
|
||||
$sortOrder = $row['sort_order'];
|
||||
|
||||
return Competency::reconstitute(
|
||||
id: CompetencyId::fromString($id),
|
||||
frameworkId: CompetencyFrameworkId::fromString($frameworkId),
|
||||
code: $code,
|
||||
name: $name,
|
||||
description: $description,
|
||||
parentId: $parentId !== null ? CompetencyId::fromString($parentId) : null,
|
||||
sortOrder: (int) $sortOrder,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Persistence\Doctrine;
|
||||
|
||||
use App\Scolarite\Domain\Model\Competency\CustomCompetencyLevel;
|
||||
use App\Scolarite\Domain\Model\Competency\CustomCompetencyLevelId;
|
||||
use App\Scolarite\Domain\Repository\CustomCompetencyLevelRepository;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
|
||||
use function array_map;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Override;
|
||||
|
||||
final readonly class DoctrineCustomCompetencyLevelRepository implements CustomCompetencyLevelRepository
|
||||
{
|
||||
public function __construct(
|
||||
private Connection $connection,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function save(CustomCompetencyLevel $level): void
|
||||
{
|
||||
$this->connection->executeStatement(
|
||||
'INSERT INTO competency_levels (id, tenant_id, code, name, color, sort_order)
|
||||
VALUES (:id, :tenant_id, :code, :name, :color, :sort_order)
|
||||
ON CONFLICT (tenant_id, code) DO UPDATE SET
|
||||
name = EXCLUDED.name,
|
||||
color = EXCLUDED.color,
|
||||
sort_order = EXCLUDED.sort_order',
|
||||
[
|
||||
'id' => (string) $level->id,
|
||||
'tenant_id' => (string) $level->tenantId,
|
||||
'code' => $level->code,
|
||||
'name' => $level->name,
|
||||
'color' => $level->color,
|
||||
'sort_order' => $level->sortOrder,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findByTenant(TenantId $tenantId): array
|
||||
{
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
'SELECT * FROM competency_levels WHERE tenant_id = :tenant_id ORDER BY sort_order ASC',
|
||||
['tenant_id' => (string) $tenantId],
|
||||
);
|
||||
|
||||
return array_map($this->hydrate(...), $rows);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function hasByTenant(TenantId $tenantId): bool
|
||||
{
|
||||
/** @var string|int $count */
|
||||
$count = $this->connection->fetchOne(
|
||||
'SELECT COUNT(*) FROM competency_levels WHERE tenant_id = :tenant_id',
|
||||
['tenant_id' => (string) $tenantId],
|
||||
);
|
||||
|
||||
return (int) $count > 0;
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $row */
|
||||
private function hydrate(array $row): CustomCompetencyLevel
|
||||
{
|
||||
/** @var string $id */
|
||||
$id = $row['id'];
|
||||
/** @var string $tenantId */
|
||||
$tenantId = $row['tenant_id'];
|
||||
/** @var string $code */
|
||||
$code = $row['code'];
|
||||
/** @var string $name */
|
||||
$name = $row['name'];
|
||||
/** @var string|null $color */
|
||||
$color = $row['color'];
|
||||
/** @var string|int $sortOrder */
|
||||
$sortOrder = $row['sort_order'];
|
||||
|
||||
return CustomCompetencyLevel::reconstitute(
|
||||
id: CustomCompetencyLevelId::fromString($id),
|
||||
tenantId: TenantId::fromString($tenantId),
|
||||
code: $code,
|
||||
name: $name,
|
||||
color: $color,
|
||||
sortOrder: (int) $sortOrder,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -158,6 +158,54 @@ final readonly class DoctrineEvaluationRepository implements EvaluationRepositor
|
||||
return array_map($this->hydrate(...), $rows);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findAllWithPublishedGrades(TenantId $tenantId): array
|
||||
{
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
'SELECT * FROM evaluations
|
||||
WHERE tenant_id = :tenant_id
|
||||
AND status != :deleted
|
||||
AND grades_published_at IS NOT NULL
|
||||
ORDER BY evaluation_date ASC',
|
||||
[
|
||||
'tenant_id' => (string) $tenantId,
|
||||
'deleted' => EvaluationStatus::DELETED->value,
|
||||
],
|
||||
);
|
||||
|
||||
return array_map($this->hydrate(...), $rows);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findWithPublishedGradesBySubjectAndClassInDateRange(
|
||||
SubjectId $subjectId,
|
||||
ClassId $classId,
|
||||
DateTimeImmutable $startDate,
|
||||
DateTimeImmutable $endDate,
|
||||
TenantId $tenantId,
|
||||
): array {
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
'SELECT * FROM evaluations
|
||||
WHERE subject_id = :subject_id
|
||||
AND class_id = :class_id
|
||||
AND tenant_id = :tenant_id
|
||||
AND status != :deleted
|
||||
AND grades_published_at IS NOT NULL
|
||||
AND evaluation_date BETWEEN :start_date AND :end_date
|
||||
ORDER BY evaluation_date ASC',
|
||||
[
|
||||
'subject_id' => (string) $subjectId,
|
||||
'class_id' => (string) $classId,
|
||||
'tenant_id' => (string) $tenantId,
|
||||
'deleted' => EvaluationStatus::DELETED->value,
|
||||
'start_date' => $startDate->format('Y-m-d'),
|
||||
'end_date' => $endDate->format('Y-m-d'),
|
||||
],
|
||||
);
|
||||
|
||||
return array_map($this->hydrate(...), $rows);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $row */
|
||||
private function hydrate(array $row): Evaluation
|
||||
{
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Persistence\Doctrine;
|
||||
|
||||
use App\Scolarite\Domain\Model\Evaluation\ClassStatistics;
|
||||
use App\Scolarite\Domain\Model\Evaluation\EvaluationId;
|
||||
use App\Scolarite\Domain\Repository\EvaluationStatisticsRepository;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Override;
|
||||
|
||||
final readonly class DoctrineEvaluationStatisticsRepository implements EvaluationStatisticsRepository
|
||||
{
|
||||
public function __construct(
|
||||
private Connection $connection,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function save(EvaluationId $evaluationId, ClassStatistics $statistics): void
|
||||
{
|
||||
$this->connection->executeStatement(
|
||||
'INSERT INTO evaluation_statistics (evaluation_id, average, min_grade, max_grade, median_grade, graded_count, updated_at)
|
||||
VALUES (:evaluation_id, :average, :min_grade, :max_grade, :median_grade, :graded_count, NOW())
|
||||
ON CONFLICT (evaluation_id) DO UPDATE SET
|
||||
average = EXCLUDED.average,
|
||||
min_grade = EXCLUDED.min_grade,
|
||||
max_grade = EXCLUDED.max_grade,
|
||||
median_grade = EXCLUDED.median_grade,
|
||||
graded_count = EXCLUDED.graded_count,
|
||||
updated_at = NOW()',
|
||||
[
|
||||
'evaluation_id' => (string) $evaluationId,
|
||||
'average' => $statistics->average,
|
||||
'min_grade' => $statistics->min,
|
||||
'max_grade' => $statistics->max,
|
||||
'median_grade' => $statistics->median,
|
||||
'graded_count' => $statistics->gradedCount,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findByEvaluation(EvaluationId $evaluationId): ?ClassStatistics
|
||||
{
|
||||
$row = $this->connection->fetchAssociative(
|
||||
'SELECT * FROM evaluation_statistics WHERE evaluation_id = :evaluation_id',
|
||||
['evaluation_id' => (string) $evaluationId],
|
||||
);
|
||||
|
||||
if ($row === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var string|float|null $average */
|
||||
$average = $row['average'];
|
||||
/** @var string|float|null $minGrade */
|
||||
$minGrade = $row['min_grade'];
|
||||
/** @var string|float|null $maxGrade */
|
||||
$maxGrade = $row['max_grade'];
|
||||
/** @var string|float|null $medianGrade */
|
||||
$medianGrade = $row['median_grade'];
|
||||
/** @var string|int $gradedCount */
|
||||
$gradedCount = $row['graded_count'];
|
||||
|
||||
return new ClassStatistics(
|
||||
average: $average !== null ? (float) $average : null,
|
||||
min: $minGrade !== null ? (float) $minGrade : null,
|
||||
max: $maxGrade !== null ? (float) $maxGrade : null,
|
||||
median: $medianGrade !== null ? (float) $medianGrade : null,
|
||||
gradedCount: (int) $gradedCount,
|
||||
);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function delete(EvaluationId $evaluationId): void
|
||||
{
|
||||
$this->connection->executeStatement(
|
||||
'DELETE FROM evaluation_statistics WHERE evaluation_id = :evaluation_id',
|
||||
['evaluation_id' => (string) $evaluationId],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,9 @@ use function array_map;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\DBAL\Connection;
|
||||
|
||||
use function implode;
|
||||
|
||||
use Override;
|
||||
|
||||
final readonly class DoctrineGradeRepository implements GradeRepository
|
||||
@@ -31,8 +34,8 @@ final readonly class DoctrineGradeRepository implements GradeRepository
|
||||
public function save(Grade $grade): void
|
||||
{
|
||||
$this->connection->executeStatement(
|
||||
'INSERT INTO grades (id, tenant_id, evaluation_id, student_id, value, status, created_by, created_at, updated_at)
|
||||
VALUES (:id, :tenant_id, :evaluation_id, :student_id, :value, :status, :created_by, :created_at, :updated_at)
|
||||
'INSERT INTO grades (id, tenant_id, evaluation_id, student_id, value, status, created_by, created_at, updated_at, appreciation, appreciation_updated_at)
|
||||
VALUES (:id, :tenant_id, :evaluation_id, :student_id, :value, :status, :created_by, :created_at, :updated_at, :appreciation, :appreciation_updated_at)
|
||||
ON CONFLICT (evaluation_id, student_id) DO UPDATE SET
|
||||
value = EXCLUDED.value,
|
||||
status = EXCLUDED.status,
|
||||
@@ -47,6 +50,24 @@ final readonly class DoctrineGradeRepository implements GradeRepository
|
||||
'created_by' => (string) $grade->createdBy,
|
||||
'created_at' => $grade->createdAt->format(DateTimeImmutable::ATOM),
|
||||
'updated_at' => $grade->updatedAt->format(DateTimeImmutable::ATOM),
|
||||
'appreciation' => $grade->appreciation,
|
||||
'appreciation_updated_at' => $grade->appreciationUpdatedAt?->format(DateTimeImmutable::ATOM),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function saveAppreciation(Grade $grade): void
|
||||
{
|
||||
$this->connection->executeStatement(
|
||||
'UPDATE grades SET appreciation = :appreciation, appreciation_updated_at = :appreciation_updated_at, updated_at = :updated_at
|
||||
WHERE id = :id AND tenant_id = :tenant_id',
|
||||
[
|
||||
'id' => (string) $grade->id,
|
||||
'tenant_id' => (string) $grade->tenantId,
|
||||
'appreciation' => $grade->appreciation,
|
||||
'appreciation_updated_at' => $grade->appreciationUpdatedAt?->format(DateTimeImmutable::ATOM),
|
||||
'updated_at' => $grade->updatedAt->format(DateTimeImmutable::ATOM),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -95,6 +116,43 @@ final readonly class DoctrineGradeRepository implements GradeRepository
|
||||
return array_map($this->hydrate(...), $rows);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findByEvaluations(array $evaluationIds, TenantId $tenantId): array
|
||||
{
|
||||
if ($evaluationIds === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$placeholders = [];
|
||||
$params = ['tenant_id' => (string) $tenantId];
|
||||
|
||||
foreach ($evaluationIds as $i => $evalId) {
|
||||
$key = 'eval_' . $i;
|
||||
$placeholders[] = ':' . $key;
|
||||
$params[$key] = (string) $evalId;
|
||||
}
|
||||
|
||||
$in = implode(', ', $placeholders);
|
||||
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
"SELECT * FROM grades
|
||||
WHERE evaluation_id IN ({$in})
|
||||
AND tenant_id = :tenant_id
|
||||
ORDER BY created_at ASC",
|
||||
$params,
|
||||
);
|
||||
|
||||
$grouped = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
/** @var string $evalId */
|
||||
$evalId = $row['evaluation_id'];
|
||||
$grouped[$evalId][] = $this->hydrate($row);
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function hasGradesForEvaluation(EvaluationId $evaluationId, TenantId $tenantId): bool
|
||||
{
|
||||
@@ -133,6 +191,10 @@ final readonly class DoctrineGradeRepository implements GradeRepository
|
||||
$createdAt = $row['created_at'];
|
||||
/** @var string $updatedAt */
|
||||
$updatedAt = $row['updated_at'];
|
||||
/** @var string|null $appreciation */
|
||||
$appreciation = $row['appreciation'] ?? null;
|
||||
/** @var string|null $appreciationUpdatedAt */
|
||||
$appreciationUpdatedAt = $row['appreciation_updated_at'] ?? null;
|
||||
|
||||
return Grade::reconstitute(
|
||||
id: GradeId::fromString($id),
|
||||
@@ -144,6 +206,8 @@ final readonly class DoctrineGradeRepository implements GradeRepository
|
||||
createdBy: UserId::fromString($createdBy),
|
||||
createdAt: new DateTimeImmutable($createdAt),
|
||||
updatedAt: new DateTimeImmutable($updatedAt),
|
||||
appreciation: $appreciation,
|
||||
appreciationUpdatedAt: $appreciationUpdatedAt !== null ? new DateTimeImmutable($appreciationUpdatedAt) : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Persistence\Doctrine;
|
||||
|
||||
use App\Administration\Domain\Model\Subject\SubjectId;
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Domain\Repository\StudentAverageRepository;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Override;
|
||||
|
||||
final readonly class DoctrineStudentAverageRepository implements StudentAverageRepository
|
||||
{
|
||||
public function __construct(
|
||||
private Connection $connection,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function saveSubjectAverage(
|
||||
TenantId $tenantId,
|
||||
UserId $studentId,
|
||||
SubjectId $subjectId,
|
||||
string $periodId,
|
||||
float $average,
|
||||
int $gradeCount,
|
||||
): void {
|
||||
$this->connection->executeStatement(
|
||||
'INSERT INTO student_averages (id, tenant_id, student_id, subject_id, period_id, average, grade_count, updated_at)
|
||||
VALUES (gen_random_uuid(), :tenant_id, :student_id, :subject_id, :period_id, :average, :grade_count, NOW())
|
||||
ON CONFLICT (student_id, subject_id, period_id) DO UPDATE SET
|
||||
average = EXCLUDED.average,
|
||||
grade_count = EXCLUDED.grade_count,
|
||||
updated_at = NOW()',
|
||||
[
|
||||
'tenant_id' => (string) $tenantId,
|
||||
'student_id' => (string) $studentId,
|
||||
'subject_id' => (string) $subjectId,
|
||||
'period_id' => $periodId,
|
||||
'average' => $average,
|
||||
'grade_count' => $gradeCount,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function saveGeneralAverage(
|
||||
TenantId $tenantId,
|
||||
UserId $studentId,
|
||||
string $periodId,
|
||||
float $average,
|
||||
): void {
|
||||
$this->connection->executeStatement(
|
||||
'INSERT INTO student_general_averages (id, tenant_id, student_id, period_id, average, updated_at)
|
||||
VALUES (gen_random_uuid(), :tenant_id, :student_id, :period_id, :average, NOW())
|
||||
ON CONFLICT (student_id, period_id) DO UPDATE SET
|
||||
average = EXCLUDED.average,
|
||||
updated_at = NOW()',
|
||||
[
|
||||
'tenant_id' => (string) $tenantId,
|
||||
'student_id' => (string) $studentId,
|
||||
'period_id' => $periodId,
|
||||
'average' => $average,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findSubjectAveragesForStudent(
|
||||
UserId $studentId,
|
||||
string $periodId,
|
||||
TenantId $tenantId,
|
||||
): array {
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
'SELECT average FROM student_averages
|
||||
WHERE student_id = :student_id
|
||||
AND period_id = :period_id
|
||||
AND tenant_id = :tenant_id',
|
||||
[
|
||||
'student_id' => (string) $studentId,
|
||||
'period_id' => $periodId,
|
||||
'tenant_id' => (string) $tenantId,
|
||||
],
|
||||
);
|
||||
|
||||
return array_map(
|
||||
/** @param array<string, mixed> $row */
|
||||
static function (array $row): float {
|
||||
/** @var string|float $avg */
|
||||
$avg = $row['average'];
|
||||
|
||||
return (float) $avg;
|
||||
},
|
||||
$rows,
|
||||
);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findDetailedSubjectAveragesForStudent(
|
||||
UserId $studentId,
|
||||
string $periodId,
|
||||
TenantId $tenantId,
|
||||
): array {
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
'SELECT sa.subject_id, sa.average, sa.grade_count, s.name as subject_name
|
||||
FROM student_averages sa
|
||||
LEFT JOIN subjects s ON s.id = sa.subject_id
|
||||
WHERE sa.student_id = :student_id
|
||||
AND sa.period_id = :period_id
|
||||
AND sa.tenant_id = :tenant_id
|
||||
ORDER BY s.name ASC',
|
||||
[
|
||||
'student_id' => (string) $studentId,
|
||||
'period_id' => $periodId,
|
||||
'tenant_id' => (string) $tenantId,
|
||||
],
|
||||
);
|
||||
|
||||
return array_map(
|
||||
/** @param array<string, mixed> $row */
|
||||
static function (array $row): array {
|
||||
/** @var string $subjectId */
|
||||
$subjectId = $row['subject_id'];
|
||||
/** @var string|null $subjectName */
|
||||
$subjectName = $row['subject_name'];
|
||||
/** @var string|float $average */
|
||||
$average = $row['average'];
|
||||
/** @var string|int $gradeCount */
|
||||
$gradeCount = $row['grade_count'];
|
||||
|
||||
return [
|
||||
'subjectId' => $subjectId,
|
||||
'subjectName' => $subjectName,
|
||||
'average' => (float) $average,
|
||||
'gradeCount' => (int) $gradeCount,
|
||||
];
|
||||
},
|
||||
$rows,
|
||||
);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findGeneralAverageForStudent(
|
||||
UserId $studentId,
|
||||
string $periodId,
|
||||
TenantId $tenantId,
|
||||
): ?float {
|
||||
$row = $this->connection->fetchAssociative(
|
||||
'SELECT average FROM student_general_averages
|
||||
WHERE student_id = :student_id
|
||||
AND period_id = :period_id
|
||||
AND tenant_id = :tenant_id',
|
||||
[
|
||||
'student_id' => (string) $studentId,
|
||||
'period_id' => $periodId,
|
||||
'tenant_id' => (string) $tenantId,
|
||||
],
|
||||
);
|
||||
|
||||
if ($row === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var string|float $average */
|
||||
$average = $row['average'];
|
||||
|
||||
return (float) $average;
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function deleteSubjectAverage(
|
||||
UserId $studentId,
|
||||
SubjectId $subjectId,
|
||||
string $periodId,
|
||||
TenantId $tenantId,
|
||||
): void {
|
||||
$this->connection->executeStatement(
|
||||
'DELETE FROM student_averages
|
||||
WHERE student_id = :student_id
|
||||
AND subject_id = :subject_id
|
||||
AND period_id = :period_id
|
||||
AND tenant_id = :tenant_id',
|
||||
[
|
||||
'student_id' => (string) $studentId,
|
||||
'subject_id' => (string) $subjectId,
|
||||
'period_id' => $periodId,
|
||||
'tenant_id' => (string) $tenantId,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function deleteGeneralAverage(
|
||||
UserId $studentId,
|
||||
string $periodId,
|
||||
TenantId $tenantId,
|
||||
): void {
|
||||
$this->connection->executeStatement(
|
||||
'DELETE FROM student_general_averages
|
||||
WHERE student_id = :student_id
|
||||
AND period_id = :period_id
|
||||
AND tenant_id = :tenant_id',
|
||||
[
|
||||
'student_id' => (string) $studentId,
|
||||
'period_id' => $periodId,
|
||||
'tenant_id' => (string) $tenantId,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Persistence\Doctrine;
|
||||
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyEvaluationId;
|
||||
use App\Scolarite\Domain\Model\Competency\CompetencyId;
|
||||
use App\Scolarite\Domain\Model\Competency\StudentCompetencyResult;
|
||||
use App\Scolarite\Domain\Model\Competency\StudentCompetencyResultId;
|
||||
use App\Scolarite\Domain\Repository\StudentCompetencyResultRepository;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
|
||||
use function array_map;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Override;
|
||||
|
||||
final readonly class DoctrineStudentCompetencyResultRepository implements StudentCompetencyResultRepository
|
||||
{
|
||||
public function __construct(
|
||||
private Connection $connection,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function save(StudentCompetencyResult $result): void
|
||||
{
|
||||
$this->connection->executeStatement(
|
||||
'INSERT INTO student_competency_results (id, tenant_id, competency_evaluation_id, student_id, level_code, created_at, updated_at)
|
||||
VALUES (:id, :tenant_id, :competency_evaluation_id, :student_id, :level_code, :created_at, :updated_at)
|
||||
ON CONFLICT (competency_evaluation_id, student_id) DO UPDATE SET
|
||||
level_code = EXCLUDED.level_code,
|
||||
updated_at = EXCLUDED.updated_at',
|
||||
[
|
||||
'id' => (string) $result->id,
|
||||
'tenant_id' => (string) $result->tenantId,
|
||||
'competency_evaluation_id' => (string) $result->competencyEvaluationId,
|
||||
'student_id' => (string) $result->studentId,
|
||||
'level_code' => $result->levelCode,
|
||||
'created_at' => $result->createdAt->format(DateTimeImmutable::ATOM),
|
||||
'updated_at' => $result->updatedAt->format(DateTimeImmutable::ATOM),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function delete(StudentCompetencyResult $result): void
|
||||
{
|
||||
$this->connection->executeStatement(
|
||||
'DELETE FROM student_competency_results WHERE id = :id AND tenant_id = :tenant_id',
|
||||
[
|
||||
'id' => (string) $result->id,
|
||||
'tenant_id' => (string) $result->tenantId,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findByCompetencyEvaluation(
|
||||
CompetencyEvaluationId $competencyEvaluationId,
|
||||
TenantId $tenantId,
|
||||
): array {
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
'SELECT * FROM student_competency_results
|
||||
WHERE competency_evaluation_id = :competency_evaluation_id
|
||||
AND tenant_id = :tenant_id',
|
||||
[
|
||||
'competency_evaluation_id' => (string) $competencyEvaluationId,
|
||||
'tenant_id' => (string) $tenantId,
|
||||
],
|
||||
);
|
||||
|
||||
return array_map($this->hydrate(...), $rows);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findByCompetencyEvaluationAndStudent(
|
||||
CompetencyEvaluationId $competencyEvaluationId,
|
||||
UserId $studentId,
|
||||
TenantId $tenantId,
|
||||
): ?StudentCompetencyResult {
|
||||
$row = $this->connection->fetchAssociative(
|
||||
'SELECT * FROM student_competency_results
|
||||
WHERE competency_evaluation_id = :competency_evaluation_id
|
||||
AND student_id = :student_id
|
||||
AND tenant_id = :tenant_id',
|
||||
[
|
||||
'competency_evaluation_id' => (string) $competencyEvaluationId,
|
||||
'student_id' => (string) $studentId,
|
||||
'tenant_id' => (string) $tenantId,
|
||||
],
|
||||
);
|
||||
|
||||
if ($row === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->hydrate($row);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findByStudentAndCompetency(
|
||||
UserId $studentId,
|
||||
CompetencyId $competencyId,
|
||||
TenantId $tenantId,
|
||||
): array {
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
'SELECT scr.*
|
||||
FROM student_competency_results scr
|
||||
JOIN competency_evaluations ce ON ce.id = scr.competency_evaluation_id
|
||||
JOIN evaluations e ON e.id = ce.evaluation_id
|
||||
WHERE scr.student_id = :student_id
|
||||
AND ce.competency_id = :competency_id
|
||||
AND scr.tenant_id = :tenant_id
|
||||
ORDER BY e.evaluation_date ASC',
|
||||
[
|
||||
'student_id' => (string) $studentId,
|
||||
'competency_id' => (string) $competencyId,
|
||||
'tenant_id' => (string) $tenantId,
|
||||
],
|
||||
);
|
||||
|
||||
return array_map($this->hydrate(...), $rows);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $row */
|
||||
private function hydrate(array $row): StudentCompetencyResult
|
||||
{
|
||||
/** @var string $id */
|
||||
$id = $row['id'];
|
||||
/** @var string $tenantId */
|
||||
$tenantId = $row['tenant_id'];
|
||||
/** @var string $ceId */
|
||||
$ceId = $row['competency_evaluation_id'];
|
||||
/** @var string $studentId */
|
||||
$studentId = $row['student_id'];
|
||||
/** @var string $levelCode */
|
||||
$levelCode = $row['level_code'];
|
||||
/** @var string $createdAt */
|
||||
$createdAt = $row['created_at'];
|
||||
/** @var string $updatedAt */
|
||||
$updatedAt = $row['updated_at'];
|
||||
|
||||
return StudentCompetencyResult::reconstitute(
|
||||
id: StudentCompetencyResultId::fromString($id),
|
||||
tenantId: TenantId::fromString($tenantId),
|
||||
competencyEvaluationId: CompetencyEvaluationId::fromString($ceId),
|
||||
studentId: UserId::fromString($studentId),
|
||||
levelCode: $levelCode,
|
||||
createdAt: new DateTimeImmutable($createdAt),
|
||||
updatedAt: new DateTimeImmutable($updatedAt),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Infrastructure\Persistence\InMemory;
|
||||
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Domain\Model\Grade\AppreciationTemplate;
|
||||
use App\Scolarite\Domain\Model\Grade\AppreciationTemplateId;
|
||||
use App\Scolarite\Domain\Repository\AppreciationTemplateRepository;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
|
||||
use function array_filter;
|
||||
use function array_values;
|
||||
|
||||
use Override;
|
||||
|
||||
final class InMemoryAppreciationTemplateRepository implements AppreciationTemplateRepository
|
||||
{
|
||||
/** @var array<string, AppreciationTemplate> */
|
||||
private array $byId = [];
|
||||
|
||||
#[Override]
|
||||
public function save(AppreciationTemplate $template): void
|
||||
{
|
||||
$this->byId[(string) $template->id] = $template;
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findById(AppreciationTemplateId $id, TenantId $tenantId): ?AppreciationTemplate
|
||||
{
|
||||
$template = $this->byId[(string) $id] ?? null;
|
||||
|
||||
if ($template === null || (string) $template->tenantId !== (string) $tenantId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findByTeacher(UserId $teacherId, TenantId $tenantId): array
|
||||
{
|
||||
return array_values(array_filter(
|
||||
$this->byId,
|
||||
static fn (AppreciationTemplate $t): bool => (string) $t->teacherId === (string) $teacherId
|
||||
&& (string) $t->tenantId === (string) $tenantId,
|
||||
));
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function delete(AppreciationTemplateId $id, TenantId $tenantId): void
|
||||
{
|
||||
$template = $this->byId[(string) $id] ?? null;
|
||||
|
||||
if ($template !== null && (string) $template->tenantId === (string) $tenantId) {
|
||||
unset($this->byId[(string) $id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Scolarite\Infrastructure\Persistence\InMemory;
|
||||
|
||||
use App\Administration\Domain\Model\SchoolClass\ClassId;
|
||||
use App\Administration\Domain\Model\Subject\SubjectId;
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Domain\Exception\EvaluationNotFoundException;
|
||||
use App\Scolarite\Domain\Model\Evaluation\Evaluation;
|
||||
@@ -16,6 +17,7 @@ use App\Shared\Domain\Tenant\TenantId;
|
||||
use function array_filter;
|
||||
use function array_values;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Override;
|
||||
|
||||
final class InMemoryEvaluationRepository implements EvaluationRepository
|
||||
@@ -86,4 +88,35 @@ final class InMemoryEvaluationRepository implements EvaluationRepository
|
||||
&& $e->status !== EvaluationStatus::DELETED,
|
||||
));
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findAllWithPublishedGrades(TenantId $tenantId): array
|
||||
{
|
||||
return array_values(array_filter(
|
||||
$this->byId,
|
||||
static fn (Evaluation $e): bool => $e->tenantId->equals($tenantId)
|
||||
&& $e->status !== EvaluationStatus::DELETED
|
||||
&& $e->notesPubliees(),
|
||||
));
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function findWithPublishedGradesBySubjectAndClassInDateRange(
|
||||
SubjectId $subjectId,
|
||||
ClassId $classId,
|
||||
DateTimeImmutable $startDate,
|
||||
DateTimeImmutable $endDate,
|
||||
TenantId $tenantId,
|
||||
): array {
|
||||
return array_values(array_filter(
|
||||
$this->byId,
|
||||
static fn (Evaluation $e): bool => $e->subjectId->equals($subjectId)
|
||||
&& $e->classId->equals($classId)
|
||||
&& $e->tenantId->equals($tenantId)
|
||||
&& $e->status !== EvaluationStatus::DELETED
|
||||
&& $e->notesPubliees()
|
||||
&& $e->evaluationDate >= $startDate
|
||||
&& $e->evaluationDate <= $endDate,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user