src/Lms/UserInterface/WebApp/Controller/MaterialController.php line 30

Open in your IDE?
  1. <?php
  2. namespace CodersLab\Lms\UserInterface\WebApp\Controller;
  3. use CodersLab\Lms\Modules\IdentityAccess\Application\IContentAccessContext;
  4. use CodersLab\Lms\Modules\Materials\Application\Query\MaterialQuery;
  5. use CodersLab\Lms\Modules\Materials\Application\Service\Material\ContentParser\ContentDirectory;
  6. use CodersLab\Lms\Modules\Materials\Application\Service\PresentationRenderer;
  7. use CodersLab\Lms\SharedKernel\Application\SecurityContext;
  8. use CodersLab\Lms\SharedKernel\Common\Exception\AccessDeniedHttpException;
  9. use CodersLab\Lms\SharedKernel\Domain\Identity\Uuid;
  10. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. final class MaterialController
  14. {
  15.     public function __construct(
  16.         private ParameterBagInterface $parameters,
  17.         private IContentAccessContext $contentAccessContext,
  18.         private SecurityContext $securityContext,
  19.         private MaterialQuery $materialQuery,
  20.         private PresentationRenderer $presentationRenderer
  21.     ) {
  22.     }
  23.     /**
  24.      * @Route("/build/{technology}/{lang}/{version}/{mode}/{dayDir}/{pillId}/{materialId}", name="render_presentation")
  25.      */
  26.     public function presentationAction(
  27.         string $technology,
  28.         string $lang,
  29.         string $version,
  30.         string $mode,
  31.         string $dayDir,
  32.         string $pillId,
  33.         string $materialId
  34.     ): Response {
  35.         $contentTypePath ContentDirectory::STUDENT()->getValue();
  36.         if ($this->materialQuery->isLecturerMaterial(new Uuid($materialId))) {
  37.             $contentTypePath ContentDirectory::LECTURER()->getValue();
  38.         }
  39.         $path $this->parameters->get('lms.presentations_path')
  40.             . "/${technology}/${lang}/${version}/${mode}/${dayDir}/${pillId}/${contentTypePath}/${materialId}/index.html";
  41.         $user $this->securityContext->getLoggedUser();
  42.         $materialAccess $this->contentAccessContext->hasMaterialAccess($user->id(), $materialId$user->getAccess());
  43.         $directAccess $this->contentAccessContext->hasDirectMaterialAccess($user->id(), $materialId);
  44.         if (($materialAccess || $directAccess) === false) {
  45.             throw new AccessDeniedHttpException();
  46.         }
  47.         return new Response($this->presentationRenderer->render($path));
  48.     }
  49. }