<?php
namespace CodersLab\Lms\UserInterface\WebApp\Controller;
use CodersLab\Lms\Modules\IdentityAccess\Application\IContentAccessContext;
use CodersLab\Lms\Modules\Materials\Application\Query\MaterialQuery;
use CodersLab\Lms\Modules\Materials\Application\Service\Material\ContentParser\ContentDirectory;
use CodersLab\Lms\Modules\Materials\Application\Service\PresentationRenderer;
use CodersLab\Lms\SharedKernel\Application\SecurityContext;
use CodersLab\Lms\SharedKernel\Common\Exception\AccessDeniedHttpException;
use CodersLab\Lms\SharedKernel\Domain\Identity\Uuid;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
final class MaterialController
{
public function __construct(
private ParameterBagInterface $parameters,
private IContentAccessContext $contentAccessContext,
private SecurityContext $securityContext,
private MaterialQuery $materialQuery,
private PresentationRenderer $presentationRenderer
) {
}
/**
* @Route("/build/{technology}/{lang}/{version}/{mode}/{dayDir}/{pillId}/{materialId}", name="render_presentation")
*/
public function presentationAction(
string $technology,
string $lang,
string $version,
string $mode,
string $dayDir,
string $pillId,
string $materialId
): Response {
$contentTypePath = ContentDirectory::STUDENT()->getValue();
if ($this->materialQuery->isLecturerMaterial(new Uuid($materialId))) {
$contentTypePath = ContentDirectory::LECTURER()->getValue();
}
$path = $this->parameters->get('lms.presentations_path')
. "/${technology}/${lang}/${version}/${mode}/${dayDir}/${pillId}/${contentTypePath}/${materialId}/index.html";
$user = $this->securityContext->getLoggedUser();
$materialAccess = $this->contentAccessContext->hasMaterialAccess($user->id(), $materialId, $user->getAccess());
$directAccess = $this->contentAccessContext->hasDirectMaterialAccess($user->id(), $materialId);
if (($materialAccess || $directAccess) === false) {
throw new AccessDeniedHttpException();
}
return new Response($this->presentationRenderer->render($path));
}
}