ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
TitleColumnsBuilder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\StaticURL\Services as StaticURLServices;
27use ILIAS\UI\Factory as UIFactory;
28use ILIAS\UI\Component\Link\Standard as StandardLink;
29
31{
32 public function __construct(
33 private readonly GeneralQuestionPropertiesRepository $properties_repository,
34 private readonly \ilCtrl $ctrl,
35 private readonly \ilAccessHandler $access,
36 private readonly \ilLanguage $lng,
37 private readonly StaticURLServices $static_url,
38 private readonly UIFactory $ui_factory,
39 private readonly Refinery $refinery
40 ) {
41 }
42
43 public function buildQuestionTitleAsLink(
44 int $question_id,
45 int $test_ref_id
46 ): StandardLink {
47 $question_title = $this->properties_repository->getForQuestionId($question_id)?->getTitle();
48
49 if ($question_title === null) {
50 return $this->ui_factory->link()->standard(
51 "{$this->lng->txt('deleted')} ({$this->lng->txt('id')}: {$question_id})",
52 ''
53 )->withDisabled();
54 }
55
56 return $this->ui_factory->link()->standard(
57 $this->refinery->encode()->htmlSpecialCharsAsEntities()->transform(
58 $this->properties_repository->getForQuestionId($question_id)?->getTitle()
59 ),
60 $this->static_url->builder()->build(
61 'tst',
62 new ReferenceId($test_ref_id),
63 ['qst', $question_id]
64 )->__toString()
65 );
66 }
67
68 public function buildQuestionTitleAsText(
69 ?int $question_id
70 ): string {
71 if ($question_id === null) {
72 return '';
73 }
74 $question_title = $this->properties_repository->getForQuestionId($question_id)?->getTitle();
75
76 if ($question_title === null) {
77 return "{$this->lng->txt('deleted')} ({$this->lng->txt('id')}: {$question_id})";
78 }
79
80 return $this->refinery->encode()->htmlSpecialCharsAsEntities()->transform($question_title);
81 }
82
83 public function buildTestTitleAsLink(int $test_ref_id): StandardLink
84 {
85 $test_obj_id = \ilObject::_lookupObjId($test_ref_id);
86 if ($test_obj_id === 0) {
87 return $this->ui_factory->link()->standard(
88 "{$this->lng->txt('deleted')} ({$this->lng->txt('id')}: {$test_ref_id})",
89 ''
90 )->withDisabled();
91 }
92
93 if (\ilObject::_isInTrash($test_ref_id)) {
94 return $this->ui_factory->link()->standard(
95 "{$this->lng->txt('in_trash')} ({$this->lng->txt('title')}: "
96 . \ilObject::_lookupTitle($test_obj_id) . ", {$this->lng->txt('id')}: {$test_ref_id})",
97 ''
98 );
99 }
100
101 return $this->ui_factory->link()->standard(
102 \ilObject::_lookupTitle($test_obj_id),
103 $this->static_url->builder()->build('tst', new ReferenceId($test_ref_id))->__toString()
104 );
105 }
106
107 public function buildTestTitleAsText(int $test_ref_id): string
108 {
109 $test_obj_id = \ilObject::_lookupObjId($test_ref_id);
110 if ($test_obj_id === 0) {
111 return "{$this->lng->txt('deleted')} ({$this->lng->txt('id')}: {$test_ref_id})";
112 }
113
114 return \ilObject::_lookupTitle($test_obj_id);
115 }
116
117
118
120 int $test_obj_id,
121 string $title
122 ): StandardLink {
123 return $this->buildPossiblyLinkedTitle(
124 $test_obj_id,
125 $title,
126 \ilObjTestGUI::class
127 );
128 }
129
131 ?int $qpl_id,
132 ?string $title = null,
133 bool $reference = false
134 ): StandardLink {
135 if ($qpl_id === null) {
136 return $this->ui_factory->link()->standard(
137 $title ?? $this->lng->txt('tst_question_not_from_pool_info'),
138 ''
139 )->withDisabled();
140 }
141
142 if (\ilObject::_lookupType($qpl_id, $reference) !== 'qpl') {
143 return $this->ui_factory->link()->standard(
144 $this->lng->txt('tst_question_not_from_pool_info'),
145 ''
146 )->withDisabled();
147 }
148
149 $qpl_obj_id = $qpl_id;
150 if ($reference) {
151 $qpl_obj_id = \ilObject::_lookupObjId($qpl_id);
152 }
153
154 return $this->buildPossiblyLinkedTitle(
155 $qpl_obj_id,
156 $title ?? \ilObject::_lookupTitle($qpl_obj_id),
157 \ilObjQuestionPoolGUI::class,
158 $reference
159 );
160 }
161
162 private function buildPossiblyLinkedTitle(
163 int $obj_id,
164 string $title,
165 string $target_class_type,
166 bool $reference = false
167 ): StandardLink {
168 $ref_id = $this->getFirstReferenceWithCurrentUserAccess(
169 $reference,
170 $obj_id,
171 \ilObject::_getAllReferences($obj_id)
172 );
173
174 if ($ref_id === null) {
175 return $this->ui_factory->link()->standard(
176 "{$title} ({$this->lng->txt('status_no_permission')})",
177 ''
178 )->withDisabled();
179 }
180
181 return $this->getLinkedTitle($ref_id, $title, $target_class_type);
182 }
183
184 private function getLinkedTitle(
185 int $ref_id,
186 string $title,
187 string $target_class_type
188 ): StandardLink {
189 $this->ctrl->setParameterByClass($target_class_type, 'ref_id', $ref_id);
190 $linked_title = $this->ui_factory->link()->standard(
191 $title,
192 $this->ctrl->getLinkTargetByClass(
193 [$target_class_type]
194 )
195 );
196 $this->ctrl->clearParametersByClass($target_class_type);
197 return $linked_title;
198 }
199
201 bool $reference,
202 int $obj_id,
203 array $all_ref_ids
204 ): ?int {
205 if ($reference && $this->access->checkAccess('read', '', $obj_id)) {
206 return $obj_id;
207 }
208
209 $references_with_access = array_filter(
210 array_values($all_ref_ids),
211 function (int $ref_id): bool {
212 return $this->access->checkAccess('read', '', $ref_id);
213 }
214 );
215 if ($references_with_access !== []) {
216 return array_shift($references_with_access);
217 }
218 return null;
219 }
220}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
__construct(private readonly GeneralQuestionPropertiesRepository $properties_repository, private readonly \ilCtrl $ctrl, private readonly \ilAccessHandler $access, private readonly \ilLanguage $lng, private readonly StaticURLServices $static_url, private readonly UIFactory $ui_factory, private readonly Refinery $refinery)
buildPossiblyLinkedTitle(int $obj_id, string $title, string $target_class_type, bool $reference=false)
buildAccessCheckedTestTitleAsLinkForObjId(int $test_obj_id, string $title)
buildAccessCheckedQuestionpoolTitleAsLink(?int $qpl_id, ?string $title=null, bool $reference=false)
buildQuestionTitleAsLink(int $question_id, int $test_ref_id)
getFirstReferenceWithCurrentUserAccess(bool $reference, int $obj_id, array $all_ref_ids)
getLinkedTitle(int $ref_id, string $title, string $target_class_type)
Class ilCtrl provides processing control methods.
language handling
Class ilObjTestGUI.
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
static _isInTrash(int $ref_id)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$static_url
Definition: goto.php:29
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
$ref_id
Definition: ltiauth.php:66
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))