ILIAS  release_7 Revision v7.30-3-g800a261c036
QuestionPoolLinkedTitleBuilder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Modules\Test;
22
23use ilObject;
25use ILIAS\UI\Factory as UIFactory;
26use ILIAS\UI\Renderer as UIRenderer;
28
29trait QuestionPoolLinkedTitleBuilder
30{
31 public function buildPossiblyLinkedTestTitle(
32 \ilCtrl $ctrl,
33 \ilAccessHandler $access,
35 UIFactory $ui_factory,
36 UIRenderer $ui_renderer,
37 int $test_id,
38 string $title
39 ) : string {
40 return $this->buildPossiblyLinkedTitle(
41 $ctrl,
42 $access,
43 $lng,
44 $ui_factory,
45 $ui_renderer,
46 $test_id,
47 $title,
48 \ilObjTestGUI::class
49 );
50 }
51
52 public function buildPossiblyLinkedQuestonPoolTitle(
53 \ilCtrl $ctrl,
54 \ilAccessHandler $access,
56 UIFactory $ui_factory,
57 UIRenderer $ui_renderer,
58 ?int $qpl_id,
59 string $title,
60 bool $reference = false
61 ) : string {
62 if ($qpl_id === null) {
63 return $title;
64 }
65
66 if (ilObject::_lookupType($qpl_id, $reference) !== 'qpl') {
67 return $lng->txt('tst_question_not_from_pool_info');
68 }
69
70 return $this->buildPossiblyLinkedTitle(
71 $ctrl,
72 $access,
73 $lng,
74 $ui_factory,
75 $ui_renderer,
76 $qpl_id,
77 $title,
78 \ilObjQuestionPoolGUI::class,
79 $reference
80 );
81 }
82
83 private function buildPossiblyLinkedTitle(
84 \ilCtrl $ctrl,
85 \ilAccessHandler $access,
87 UIFactory $ui_factory,
88 UIRenderer $ui_renderer,
89 int $qpl_id,
90 string $title,
91 string $target_class_type,
92 bool $reference = false
93 ) : string {
94 $qpl_obj_id = $qpl_id;
95 if ($reference) {
96 $qpl_obj_id = ilObject::_lookupObjId($qpl_id);
97 }
98 $ref_id = $this->getFirstReferenceWithCurrentUserAccess(
99 $access,
100 $reference,
101 $qpl_id,
102 ilObject::_getAllReferences($qpl_obj_id)
103 );
104
105 if ($ref_id === null) {
106 return $title . ' (' . $lng->txt('status_no_permission') . ')';
107 }
108
109 return $ui_renderer->render(
110 $this->getLinkedTitle($ctrl, $ui_factory, $ref_id, $title, $target_class_type)
111 );
112 }
113
114 private function getLinkedTitle(
115 \ilCtrl $ctrl,
116 UIFactory $ui_factory,
117 int $ref_id,
118 string $title,
119 string $target_class_type
120 ) : Link {
121 $linked_title = $ui_factory->link()->standard(
122 $title,
123 \ilLink::_getStaticLink($ref_id)
124 );
125 return $linked_title;
126 }
127
128 private function getFirstReferenceWithCurrentUserAccess(
129 \ilAccessHandler $access,
130 bool $reference,
131 int $qpl_id,
132 array $all_ref_ids
133 ) : ?int {
134 if ($reference && $access->checkAccess('read', '', $qpl_id)) {
135 return $qpl_id;
136 }
137
138 $references_with_access = array_filter(
139 array_values($all_ref_ids),
140 function ($ref_id) use ($access) {
141 return $access->checkAccess('read', '', $ref_id);
142 }
143 );
144 if ($references_with_access !== []) {
145 return (int) array_shift($references_with_access);
146 }
147 return null;
148 }
149}
An exception for terminatinating execution or to throw for unit testing.
This class provides processing control methods.
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObject Basic functions for all objects.
static _lookupObjId($a_id)
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
This is how the factory for UI elements looks.
Definition: Factory.php:18
An entity that renders components to a string output.
Definition: Renderer.php:15
Interface ilAccessHandler.
checkAccess($a_permission, $a_cmd, $a_ref_id, $a_type="", $a_obj_id=null, $a_tree_id=null)
check access for an object (provide $a_type and $a_obj_id if available for better performance)
$lng
standard()
This is an example, of how the Notification Slate is generated by assigning Notification Items to it.
Definition: standard.php:11