ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
StaticURLHandler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Test;
22 
29 
30 class StaticURLHandler extends BaseHandler implements Handler
31 {
32  public const NAMESPACE = 'tst';
33  public const QUESTION_OPERATIONS = 'qst';
34 
35  public function getNamespace(): string
36  {
37  return self::NAMESPACE;
38  }
39 
40  public function handle(
41  Request $request,
43  Factory $response_factory
44  ): Response {
45  $ref_id = $request->getReferenceId()?->toInt() ?? 0;
46  $additional_params = $request->getAdditionalParameters();
47  $context->ctrl()->setParameterByClass(\ilObjTestGUI::class, 'ref_id', $ref_id);
48 
49  if (!$context->checkPermission('read', $ref_id) && !$context->isUserLoggedIn()) {
50  return $response_factory->can("login.php?target=tst_{$ref_id}&cmd=force_login");
51  }
52 
53  $uri = match ($additional_params[0] ?? 'default') {
54  self::QUESTION_OPERATIONS => $this->buildQuestionURL($additional_params[1], $context->ctrl()),
55  default => $context->ctrl()->getLinkTargetByClass([\ilRepositoryGUI::class, \ilObjTestGUI::class]),
56  };
57 
58  return $response_factory->can($uri);
59  }
60 
61  private function buildQuestionURL(string $q_id, \ilCtrl $ctrl): string
62  {
63  $ctrl->setParameterByClass(\ilAssQuestionPreviewGUI::class, 'q_id', $q_id);
64  $link = $ctrl->getLinkTargetByClass([\ilRepositoryGUI::class, \ilObjTestGUI::class, \ilAssQuestionPreviewGUI::class], \ilAssQuestionPreviewGUI::CMD_SHOW);
65  $ctrl->clearParameterByClass(\ilAssQuestionPreviewGUI::class, 'q_id');
66  return $link;
67  }
68 }
checkPermission(string $permission, int $ref_id)
Definition: Context.php:54
$context
Definition: webdav.php:31
setParameterByClass(string $a_class, string $a_parameter, $a_value)
clearParameterByClass(string $a_class, string $a_parameter)
$ref_id
Definition: ltiauth.php:65
handle(Request $request, Context $context, Factory $response_factory)
buildQuestionURL(string $q_id, \ilCtrl $ctrl)
getLinkTargetByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)