ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilAccessibilityDocumentTableGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
3
6
11{
13 protected $uiFactory;
14
16 protected $uiRenderer;
17
19 protected $isEditable = false;
20
22 protected $factor = 10;
23
25 protected $i = 1;
26
28 protected $numRenderedCriteria = 0;
29
32
34 protected $uiComponents = [];
35
45 public function __construct(
47 string $command,
51 bool $isEditable = false
52 ) {
53 $this->criterionTypeFactory = $criterionTypeFactory;
54 $this->uiFactory = $uiFactory;
55 $this->uiRenderer = $uiRenderer;
56 $this->isEditable = $isEditable;
57
58 $this->setId('acc_documents');
59 $this->setFormName('acc_documents');
60
61 parent::__construct($a_parent_obj, $command);
62
63 $this->setTitle($this->lng->txt('acc_tbl_docs_title'));
64 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), $command));
65
66 $this->setDefaultOrderDirection('ASC');
67 $this->setDefaultOrderField('sorting');
68 $this->setExternalSorting(true);
69 $this->setExternalSegmentation(true);
70 $this->setLimit(PHP_INT_MAX);
71
72 $this->setRowTemplate('tpl.acc_documents_row.html', 'Services/Accessibility');
73
74 if ($this->isEditable) {
75 $this->setSelectAllCheckbox('acc_id[]');
76 $this->addMultiCommand('deleteDocuments', $this->lng->txt('delete'));
77 $this->addCommandButton('saveDocumentSorting', $this->lng->txt('sorting_save'));
78 }
79 }
80
84 protected function getColumnDefinition() : array
85 {
86 $i = 0;
87
88 $columns = [];
89
90 if ($this->isEditable) {
91 $columns[++$i] = [
92 'field' => 'chb',
93 'txt' => '',
94 'default' => true,
95 'optional' => false,
96 'sortable' => false,
97 'is_checkbox' => true,
98 'width' => '1%'
99 ];
100 }
101
102 $columns[++$i] = [
103 'field' => 'sorting',
104 'txt' => $this->lng->txt('acc_tbl_docs_head_sorting'),
105 'default' => true,
106 'optional' => false,
107 'sortable' => false,
108 'width' => '5%'
109 ];
110
111 $columns[++$i] = [
112 'field' => 'title',
113 'txt' => $this->lng->txt('acc_tbl_docs_head_title'),
114 'default' => true,
115 'optional' => false,
116 'sortable' => false,
117 'width' => '25%'
118 ];
119
120 $columns[++$i] = [
121 'field' => 'creation_ts',
122 'txt' => $this->lng->txt('acc_tbl_docs_head_created'),
123 'default' => true,
124 'optional' => true,
125 'sortable' => false
126 ];
127
128 $columns[++$i] = [
129 'field' => 'modification_ts',
130 'txt' => $this->lng->txt('acc_tbl_docs_head_last_change'),
131 'default' => true,
132 'optional' => true,
133 'sortable' => false
134 ];
135
136 $columns[++$i] = [
137 'field' => 'criteria',
138 'txt' => $this->lng->txt('acc_tbl_docs_head_criteria'),
139 'default' => true,
140 'optional' => false,
141 'sortable' => false
142 ];
143
144 if ($this->isEditable) {
145 $columns[++$i] = [
146 'field' => 'actions',
147 'txt' => $this->lng->txt('actions'),
148 'default' => true,
149 'optional' => false,
150 'sortable' => false,
151 'width' => '10%'
152 ];
153 };
154
155 return $columns;
156 }
157
162 protected function preProcessData(array &$data) : void
163 {
164 foreach ($data['items'] as $key => $document) {
167 $data['items'][$key] = [
168 'id' => $document->getId(),
169 'title' => $document->getTitle(),
170 'creation_ts' => $document->getCreationTs(),
171 'modification_ts' => $document->getModificationTs(),
172 'text' => $document->getText(),
173 'criteria' => '',
174 'criteriaAssignments' => $document->criteria()
175 ];
176 }
177 }
178
184 protected function formatCellValue(string $column, array $row) : string
185 {
186 if (in_array($column, ['creation_ts', 'modification_ts'])) {
187 return \ilDatePresentation::formatDate(new \ilDateTime($row[$column], IL_CAL_UNIX));
188 } elseif ('sorting' === $column) {
189 return $this->formatSorting($row);
190 } elseif ('title' === $column) {
191 return $this->formatTitle($column, $row);
192 } elseif ('actions' === $column) {
193 return $this->formatActionsDropDown($column, $row);
194 } elseif ('chb' === $column) {
195 return \ilUtil::formCheckbox(false, 'acc_id[]', $row['id']);
196 } elseif ('criteria' === $column) {
197 return $this->formatCriterionAssignments($column, $row);
198 }
199
200 return parent::formatCellValue($column, $row);
201 }
202
208 protected function formatActionsDropDown(string $column, array $row) : string
209 {
210 if (!$this->isEditable) {
211 return '';
212 }
213
214 $this->ctrl->setParameter($this->getParentObject(), 'acc_id', $row['id']);
215
216 $editBtn = $this->uiFactory
217 ->button()
218 ->shy(
219 $this->lng->txt('edit'),
220 $this->ctrl->getLinkTarget($this->getParentObject(), 'showEditDocumentForm')
221 );
222
223 $deleteModal = $this->uiFactory
224 ->modal()
225 ->interruptive(
226 $this->lng->txt('acc_doc_delete'),
227 $this->lng->txt('acc_sure_delete_documents_s'),
228 $this->ctrl->getFormAction($this->getParentObject(), 'deleteDocument')
229 );
230
231 $deleteBtn = $this->uiFactory
232 ->button()
233 ->shy($this->lng->txt('delete'), '#')
234 ->withOnClick($deleteModal->getShowSignal());
235
236 $this->uiComponents[] = $deleteModal;
237
238 $attachCriterionBtn = $this->uiFactory
239 ->button()
240 ->shy(
241 $this->lng->txt('acc_tbl_docs_action_add_criterion'),
242 $this->ctrl->getLinkTarget($this->getParentObject(), 'showAttachCriterionForm')
243 );
244
245 $this->ctrl->setParameter($this->getParentObject(), 'acc_id', null);
246
247 $dropDown = $this->uiFactory
248 ->dropdown()
249 ->standard([$editBtn, $deleteBtn, $attachCriterionBtn])
250 ->withLabel($this->lng->txt('actions'));
251
252 return $this->uiRenderer->render([$dropDown]);
253 }
254
261 protected function formatCriterionAssignments(string $column, array $row) : string
262 {
263 $items = [];
264
265 if (0 === count($row['criteriaAssignments'])) {
266 return $this->lng->txt('acc_tbl_docs_cell_not_criterion');
267 }
268
269 foreach ($row['criteriaAssignments'] as $criterion) {
272 $this->ctrl->setParameter($this->getParentObject(), 'acc_id', $row['id']);
273 $this->ctrl->setParameter($this->getParentObject(), 'crit_id', $criterion->getId());
274
275 $editBtn = $this->uiFactory
276 ->button()
277 ->shy(
278 $this->lng->txt('edit'),
279 $this->ctrl->getLinkTarget($this->getParentObject(), 'showChangeCriterionForm')
280 );
281
282 $deleteModal = $this->uiFactory
283 ->modal()
284 ->interruptive(
285 $this->lng->txt('acc_doc_detach_crit_confirm_title'),
286 $this->lng->txt('acc_doc_sure_detach_crit'),
287 $this->ctrl->getFormAction($this->getParentObject(), 'detachCriterionAssignment')
288 );
289
290 $deleteBtn = $this->uiFactory
291 ->button()
292 ->shy($this->lng->txt('delete'), '#')
293 ->withOnClick($deleteModal->getShowSignal());
294
295 $dropDown = $this->uiFactory
296 ->dropdown()
297 ->standard([$editBtn, $deleteBtn]);
298
299 $criterionType = $this->criterionTypeFactory->findByTypeIdent($criterion->getCriterionId(), true);
300 $typeGui = $criterionType->ui($this->lng);
301
302 $items[implode(' ', [
303 $typeGui->getIdentPresentation(),
304 ($this->isEditable ? $this->uiRenderer->render($dropDown) : '')
305 ])] =
306 $this->uiFactory->legacy(
307 $this->uiRenderer->render(
308 $typeGui->getValuePresentation(
309 $criterion->getCriterionValue(),
310 $this->uiFactory
311 )
312 )
313 );
314
315 if ($this->isEditable) {
316 $this->uiComponents[] = $deleteModal;
317 }
318
319 $this->ctrl->setParameter($this->getParentObject(), 'acc_id', null);
320 $this->ctrl->setParameter($this->getParentObject(), 'crit_id', null);
321 }
322
323 $criteriaList = $this->uiFactory
324 ->listing()
325 ->descriptive($items);
326
327 return $this->uiRenderer->render([
328 $criteriaList
329 ]);
330 }
331
337 protected function formatTitle(string $column, array $row) : string
338 {
339 $modal = $this->uiFactory
340 ->modal()
341 ->lightbox([$this->uiFactory->modal()->lightboxTextPage($row['text'], $row['title'])]);
342
343 $titleLink = $this->uiFactory
344 ->button()
345 ->shy($row[$column], '#')
346 ->withOnClick($modal->getShowSignal());
347
348 return $this->uiRenderer->render([$titleLink, $modal]);
349 }
350
355 protected function formatSorting(array $row) : string
356 {
357 $value = ($this->i++) * $this->factor;
358 if (!$this->isEditable) {
359 return (string) $value;
360 }
361
362 $sortingField = new ilNumberInputGUI('', 'sorting[' . $row['id'] . ']');
363 $sortingField->setValue((string) $value);
364 $sortingField->setMaxLength(4);
365 $sortingField->setSize(2);
366
367 return $sortingField->render();
368 }
369
373 public function getHTML()
374 {
375 return parent::getHTML() . $this->uiRenderer->render($this->uiComponents);
376 }
377}
if(! $in) $columns
Definition: Utf8Test.php:45
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
Class ilAccessibilityDocumentTableGUI.
formatCellValue(string $column, array $row)
Define a final formatting for a cell value.string
__construct(ilAccessibilityControllerEnabled $a_parent_obj, string $command, ilAccessibilityCriterionTypeFactoryInterface $criterionTypeFactory, ILIAS\UI\Factory $uiFactory, ILIAS\UI\Renderer $uiRenderer, bool $isEditable=false)
ilAccessibilityDocumentTableGUI constructor.
Class ilAccessibilityTableGUI.
@classDescription Date and time handling
This class represents a number property in a property form.
setExternalSorting($a_val)
Set external sorting.
getParentObject()
Get parent object.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
setLimit($a_limit=0, $a_default_limit=0)
set max.
addMultiCommand($a_cmd, $a_text)
Add Command button.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
setExternalSegmentation($a_val)
Set external segmentation.
setId($a_val)
Set id.
setFormName($a_formname="")
Set Form name.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
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 ilAccessibilityControllerEnabled.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.