ILIAS  release_8 Revision v8.24
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 $ctrl->setParameterByClass($target_class_type, 'ref_id', $ref_id);
122 $linked_title = $ui_factory->link()->standard(
123 $title,
125 [$target_class_type]
126 )
127 );
128 $ctrl->clearParametersByClass($target_class_type);
129 return $linked_title;
130 }
131
132 private function getFirstReferenceWithCurrentUserAccess(
133 \ilAccessHandler $access,
134 bool $reference,
135 int $qpl_id,
136 array $all_ref_ids
137 ): ?int {
138 if ($reference && $access->checkAccess('read', '', $qpl_id)) {
139 return $qpl_id;
140 }
141
142 $references_with_access = array_filter(
143 array_values($all_ref_ids),
144 function ($ref_id) use ($access) {
145 return $access->checkAccess('read', '', $ref_id);
146 }
147 );
148 if ($references_with_access !== []) {
149 return array_shift($references_with_access);
150 }
151 return null;
152 }
153}
Class ilCtrl provides processing control methods.
getLinkTargetByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
clearParametersByClass(string $a_class)
@inheritDoc
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjTestGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupObjId(int $ref_id)
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkAccess(string $a_permission, string $a_cmd, int $a_ref_id, string $a_type="", ?int $a_obj_id=null, ?int $a_tree_id=null)
check access for an object (provide $a_type and $a_obj_id if available for better performance)
$ref_id
Definition: ltiauth.php:67
$lng