*/ final class EvaluationDifficultyProvider implements ProviderInterface { use HandleTrait; public function __construct( MessageBusInterface $queryBus, private readonly TenantContext $tenantContext, private readonly Security $security, ) { $this->messageBus = $queryBus; } #[Override] public function provide(Operation $operation, array $uriVariables = [], array $context = []): EvaluationDifficultyResource { 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.'); } if (!in_array(Role::PROF->value, $user->getRoles(), true)) { throw new AccessDeniedHttpException('Accès réservé aux enseignants.'); } /** @var list $results */ $results = $this->handle(new GetEvaluationDifficultyQuery( teacherId: $user->userId(), tenantId: (string) $this->tenantContext->getCurrentTenantId(), )); $resource = new EvaluationDifficultyResource(); $resource->teacherId = $user->userId(); foreach ($results as $dto) { $resource->evaluations[] = [ 'evaluationId' => $dto->evaluationId, 'title' => $dto->title, 'classId' => $dto->classId, 'className' => $dto->className, 'subjectId' => $dto->subjectId, 'subjectName' => $dto->subjectName, 'date' => $dto->date, 'average' => $dto->average, 'gradedCount' => $dto->gradedCount, 'subjectAverage' => $dto->subjectAverage, 'percentile' => $dto->percentile, ]; } return $resource; } }