ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAccessibilityDocumentTableGUI.php
Go to the documentation of this file.
1<?php
2
21
26{
29 protected bool $isEditable = false;
30 protected int $factor = 10;
31 protected int $i = 1;
32 protected int $numRenderedCriteria = 0;
35 protected array $uiComponents = [];
36
37 public function __construct(
39 string $command,
43 bool $isEditable = false
44 ) {
45 $this->criterionTypeFactory = $criterionTypeFactory;
46 $this->uiFactory = $uiFactory;
47 $this->uiRenderer = $uiRenderer;
48 $this->isEditable = $isEditable;
49
50 $this->setId('acc_documents');
51 $this->setFormName('acc_documents');
52
53 parent::__construct($a_parent_obj, $command);
54
55 $this->setTitle($this->lng->txt('acc_tbl_docs_title'));
56 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), $command));
57
58 $this->setDefaultOrderDirection('ASC');
59 $this->setDefaultOrderField('sorting');
60 $this->setExternalSorting(true);
61 $this->setExternalSegmentation(true);
62 $this->setLimit(PHP_INT_MAX);
63
64 $this->setRowTemplate('tpl.acc_documents_row.html', 'components/ILIAS/Accessibility');
65
66 if ($this->isEditable) {
67 $this->setSelectAllCheckbox('acc_id[]');
68 $this->addMultiCommand('deleteDocuments', $this->lng->txt('delete'));
69 $this->addCommandButton('saveDocumentSorting', $this->lng->txt('sorting_save'));
70 }
71 }
72
73 protected function getColumnDefinition(): array
74 {
75 $i = 0;
76
77 $columns = [];
78
79 if ($this->isEditable) {
80 $columns[++$i] = [
81 'field' => 'chb',
82 'txt' => '',
83 'default' => true,
84 'optional' => false,
85 'sortable' => false,
86 'is_checkbox' => true,
87 'width' => '1%'
88 ];
89 }
90
91 $columns[++$i] = [
92 'field' => 'sorting',
93 'txt' => $this->lng->txt('acc_tbl_docs_head_sorting'),
94 'default' => true,
95 'optional' => false,
96 'sortable' => false,
97 'width' => '5%'
98 ];
99
100 $columns[++$i] = [
101 'field' => 'title',
102 'txt' => $this->lng->txt('acc_tbl_docs_head_title'),
103 'default' => true,
104 'optional' => false,
105 'sortable' => false,
106 'width' => '25%'
107 ];
108
109 $columns[++$i] = [
110 'field' => 'creation_ts',
111 'txt' => $this->lng->txt('acc_tbl_docs_head_created'),
112 'default' => true,
113 'optional' => true,
114 'sortable' => false
115 ];
116
117 $columns[++$i] = [
118 'field' => 'modification_ts',
119 'txt' => $this->lng->txt('acc_tbl_docs_head_last_change'),
120 'default' => true,
121 'optional' => true,
122 'sortable' => false
123 ];
124
125 $columns[++$i] = [
126 'field' => 'criteria',
127 'txt' => $this->lng->txt('acc_tbl_docs_head_criteria'),
128 'default' => true,
129 'optional' => false,
130 'sortable' => false
131 ];
132
133 if ($this->isEditable) {
134 $columns[++$i] = [
135 'field' => 'actions',
136 'txt' => $this->lng->txt('actions'),
137 'default' => true,
138 'optional' => false,
139 'sortable' => false,
140 'width' => '10%'
141 ];
142 }
143
144 return $columns;
145 }
146
147 protected function preProcessData(array &$data): void
148 {
149 foreach ($data['items'] as $key => $document) {
152 $data['items'][$key] = [
153 'id' => $document->getId(),
154 'title' => $document->getTitle(),
155 'creation_ts' => $document->getCreationTs(),
156 'modification_ts' => $document->getModificationTs(),
157 'text' => $document->getText(),
158 'criteria' => '',
159 'criteriaAssignments' => $document->criteria()
160 ];
161 }
162 }
163
168 protected function formatCellValue(string $column, array $row): string
169 {
170 if (in_array($column, ['creation_ts', 'modification_ts'])) {
171 return \ilDatePresentation::formatDate(new \ilDateTime($row[$column], IL_CAL_UNIX));
172 } elseif ('sorting' === $column) {
173 return $this->formatSorting($row);
174 } elseif ('title' === $column) {
175 return $this->formatTitle($column, $row);
176 } elseif ('actions' === $column) {
177 return $this->formatActionsDropDown($column, $row);
178 } elseif ('chb' === $column) {
179 return ilLegacyFormElementsUtil::formCheckbox(false, 'acc_id[]', $row['id']);
180 } elseif ('criteria' === $column) {
181 return $this->formatCriterionAssignments($column, $row);
182 }
183
184 return parent::formatCellValue($column, $row);
185 }
186
190 protected function formatActionsDropDown(string $column, array $row): string
191 {
192 if (!$this->isEditable) {
193 return '';
194 }
195
196 $this->ctrl->setParameter($this->getParentObject(), 'acc_id', $row['id']);
197
198 $editBtn = $this->uiFactory
199 ->button()
200 ->shy(
201 $this->lng->txt('edit'),
202 $this->ctrl->getLinkTarget($this->getParentObject(), 'showEditDocumentForm')
203 );
204
205 $deleteModal = $this->uiFactory
206 ->modal()
207 ->interruptive(
208 $this->lng->txt('acc_doc_delete'),
209 $this->lng->txt('acc_sure_delete_documents_s'),
210 $this->ctrl->getFormAction($this->getParentObject(), 'deleteDocument')
211 );
212
213 $deleteBtn = $this->uiFactory
214 ->button()
215 ->shy($this->lng->txt('delete'), '#')
216 ->withOnClick($deleteModal->getShowSignal());
217
218 $this->uiComponents[] = $deleteModal;
219
220 $attachCriterionBtn = $this->uiFactory
221 ->button()
222 ->shy(
223 $this->lng->txt('acc_tbl_docs_action_add_criterion'),
224 $this->ctrl->getLinkTarget($this->getParentObject(), 'showAttachCriterionForm')
225 );
226
227 $this->ctrl->setParameter($this->getParentObject(), 'acc_id', null);
228
229 $dropDown = $this->uiFactory
230 ->dropdown()
231 ->standard([$editBtn, $deleteBtn, $attachCriterionBtn])
232 ->withLabel($this->lng->txt('actions'));
233
234 return $this->uiRenderer->render([$dropDown]);
235 }
236
241 protected function formatCriterionAssignments(string $column, array $row): string
242 {
243 $items = [];
244
245 if (0 === count($row['criteriaAssignments'])) {
246 return $this->lng->txt('acc_tbl_docs_cell_not_criterion');
247 }
248
249 foreach ($row['criteriaAssignments'] as $criterion) {
252 $this->ctrl->setParameter($this->getParentObject(), 'acc_id', $row['id']);
253 $this->ctrl->setParameter($this->getParentObject(), 'crit_id', $criterion->getId());
254
255 $editBtn = $this->uiFactory
256 ->button()
257 ->shy(
258 $this->lng->txt('edit'),
259 $this->ctrl->getLinkTarget($this->getParentObject(), 'showChangeCriterionForm')
260 );
261
262 $deleteModal = $this->uiFactory
263 ->modal()
264 ->interruptive(
265 $this->lng->txt('acc_doc_detach_crit_confirm_title'),
266 $this->lng->txt('acc_doc_sure_detach_crit'),
267 $this->ctrl->getFormAction($this->getParentObject(), 'detachCriterionAssignment')
268 );
269
270 $deleteBtn = $this->uiFactory
271 ->button()
272 ->shy($this->lng->txt('delete'), '#')
273 ->withOnClick($deleteModal->getShowSignal());
274
275 $dropDown = $this->uiFactory
276 ->dropdown()
277 ->standard([$editBtn, $deleteBtn]);
278
279 $criterionType = $this->criterionTypeFactory->findByTypeIdent($criterion->getCriterionId(), true);
280 $typeGui = $criterionType->ui($this->lng);
281
282 $items[implode(' ', [
283 $typeGui->getIdentPresentation(),
284 ($this->isEditable ? $this->uiRenderer->render($dropDown) : '')
285 ])] =
286 $this->uiFactory->legacy()->content(
287 $this->uiRenderer->render(
288 $typeGui->getValuePresentation(
289 $criterion->getCriterionValue(),
290 $this->uiFactory
291 )
292 )
293 );
294
295 if ($this->isEditable) {
296 $this->uiComponents[] = $deleteModal;
297 }
298
299 $this->ctrl->setParameter($this->getParentObject(), 'acc_id', null);
300 $this->ctrl->setParameter($this->getParentObject(), 'crit_id', null);
301 }
302
303 $criteriaList = $this->uiFactory
304 ->listing()
305 ->descriptive($items);
306
307 return $this->uiRenderer->render([
308 $criteriaList
309 ]);
310 }
311
312 protected function formatTitle(string $column, array $row): string
313 {
314 $modal = $this->uiFactory
315 ->modal()
316 ->lightbox([$this->uiFactory->modal()->lightboxTextPage($row['text'], $row['title'])]);
317
318 $titleLink = $this->uiFactory
319 ->button()
320 ->shy($row[$column], '#')
321 ->withOnClick($modal->getShowSignal());
322
323 return $this->uiRenderer->render([$titleLink, $modal]);
324 }
325
326 protected function formatSorting(array $row): string
327 {
328 $value = ($this->i++) * $this->factor;
329 if (!$this->isEditable) {
330 return (string) $value;
331 }
332
333 $sortingField = new ilNumberInputGUI('', 'sorting[' . $row['id'] . ']');
334 $sortingField->setValue((string) $value);
335 $sortingField->setMaxLength(4);
336 $sortingField->setSize(2);
337
338 return $sortingField->render();
339 }
340
341 public function getHTML(): string
342 {
343 return parent::getHTML() . $this->uiRenderer->render($this->uiComponents);
344 }
345}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
const IL_CAL_UNIX
Class ilAccessibilityDocumentTableGUI.
__construct(ilAccessibilityControllerEnabled $a_parent_obj, string $command, ilAccessibilityCriterionTypeFactoryInterface $criterionTypeFactory, ILIAS\UI\Factory $uiFactory, ILIAS\UI\Renderer $uiRenderer, bool $isEditable=false)
ilAccessibilityCriterionTypeFactoryInterface $criterionTypeFactory
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@classDescription Date and time handling
static formCheckbox(bool $checked, string $varname, string $value, bool $disabled=false)
This class represents a number property in a property form.
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setExternalSegmentation(bool $a_val)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setFormName(string $a_name="")
addMultiCommand(string $a_cmd, string $a_text)
setFormAction(string $a_form_action, bool $a_multipart=false)
setDefaultOrderField(string $a_defaultorderfield)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setExternalSorting(bool $a_val)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.