feat: Permettre aux enseignants de contourner les règles de devoirs avec justification
Akeneo permet de configurer des règles de devoirs en mode Hard qui bloquent totalement la création. Or certains cas légitimes (sorties scolaires, événements exceptionnels) nécessitent de passer outre ces règles. Sans mécanisme d'exception, l'enseignant est bloqué et doit contacter manuellement la direction. Cette implémentation ajoute un flux complet d'exception : l'enseignant justifie sa demande (min 20 caractères), le devoir est créé immédiatement, et la direction est notifiée par email. Le handler vérifie côté serveur que les règles sont réellement bloquantes avant d'accepter l'exception, empêchant toute fabrication de fausses exceptions via l'API. La direction dispose d'un rapport filtrable par période, enseignant et type de règle.
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Model\Homework;
|
||||
|
||||
use App\Administration\Domain\Model\User\UserId;
|
||||
use App\Scolarite\Domain\Event\ExceptionDevoirDemandee;
|
||||
use App\Scolarite\Domain\Exception\JustificationTropCourteException;
|
||||
use App\Shared\Domain\AggregateRoot;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use DateTimeImmutable;
|
||||
|
||||
use function explode;
|
||||
use function implode;
|
||||
use function mb_strlen;
|
||||
|
||||
final class HomeworkRuleException extends AggregateRoot
|
||||
{
|
||||
private const int JUSTIFICATION_MIN_LENGTH = 20;
|
||||
|
||||
private function __construct(
|
||||
public private(set) HomeworkRuleExceptionId $id,
|
||||
public private(set) TenantId $tenantId,
|
||||
public private(set) HomeworkId $homeworkId,
|
||||
public private(set) string $ruleType,
|
||||
public private(set) string $justification,
|
||||
public private(set) UserId $createdBy,
|
||||
public private(set) DateTimeImmutable $createdAt,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $ruleTypes Types de règles contournées
|
||||
*/
|
||||
public static function demander(
|
||||
TenantId $tenantId,
|
||||
HomeworkId $homeworkId,
|
||||
array $ruleTypes,
|
||||
string $justification,
|
||||
UserId $createdBy,
|
||||
DateTimeImmutable $now,
|
||||
): self {
|
||||
if (mb_strlen($justification) < self::JUSTIFICATION_MIN_LENGTH) {
|
||||
throw JustificationTropCourteException::avecMinimum(self::JUSTIFICATION_MIN_LENGTH);
|
||||
}
|
||||
|
||||
$ruleType = implode(',', $ruleTypes);
|
||||
|
||||
$exception = new self(
|
||||
id: HomeworkRuleExceptionId::generate(),
|
||||
tenantId: $tenantId,
|
||||
homeworkId: $homeworkId,
|
||||
ruleType: $ruleType,
|
||||
justification: $justification,
|
||||
createdBy: $createdBy,
|
||||
createdAt: $now,
|
||||
);
|
||||
|
||||
$exception->recordEvent(new ExceptionDevoirDemandee(
|
||||
exceptionId: $exception->id,
|
||||
tenantId: $tenantId,
|
||||
homeworkId: $homeworkId,
|
||||
ruleTypes: $ruleTypes,
|
||||
justification: $justification,
|
||||
createdBy: $createdBy,
|
||||
occurredOn: $now,
|
||||
));
|
||||
|
||||
return $exception;
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function ruleTypes(): array
|
||||
{
|
||||
return explode(',', $this->ruleType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Pour usage Infrastructure uniquement
|
||||
*/
|
||||
public static function reconstitute(
|
||||
HomeworkRuleExceptionId $id,
|
||||
TenantId $tenantId,
|
||||
HomeworkId $homeworkId,
|
||||
string $ruleType,
|
||||
string $justification,
|
||||
UserId $createdBy,
|
||||
DateTimeImmutable $createdAt,
|
||||
): self {
|
||||
return new self(
|
||||
id: $id,
|
||||
tenantId: $tenantId,
|
||||
homeworkId: $homeworkId,
|
||||
ruleType: $ruleType,
|
||||
justification: $justification,
|
||||
createdBy: $createdBy,
|
||||
createdAt: $createdAt,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scolarite\Domain\Model\Homework;
|
||||
|
||||
use App\Shared\Domain\EntityId;
|
||||
|
||||
final readonly class HomeworkRuleExceptionId extends EntityId
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user