ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilTermsOfServiceDocumentTableGUI.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
6
12{
14 protected $uiFactory;
15
17 protected $uiRenderer;
18
20 protected $isEditable = false;
21
23 protected $factor = 10;
24
26 protected $i = 1;
27
29 protected $numRenderedCriteria = 0;
30
33
35 protected $uiComponents = [];
36
46 public function __construct(
48 string $command,
52 bool $isEditable = false
53 ) {
54 $this->criterionTypeFactory = $criterionTypeFactory;
55 $this->uiFactory = $uiFactory;
56 $this->uiRenderer = $uiRenderer;
57 $this->isEditable = $isEditable;
58
59 $this->setId('tos_documents');
60 $this->setFormName('tos_documents');
61
62 parent::__construct($a_parent_obj, $command);
63
64 $this->setTitle($this->lng->txt('tos_tbl_docs_title'));
65 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), $command));
66
67 $this->setDefaultOrderDirection('ASC');
68 $this->setDefaultOrderField('sorting');
69 $this->setExternalSorting(true);
70 $this->setExternalSegmentation(true);
71 $this->setLimit(PHP_INT_MAX);
72
73 $this->setRowTemplate('tpl.tos_documents_row.html', 'Services/TermsOfService');
74
75 if ($this->isEditable) {
76 $this->setSelectAllCheckbox('tos_id[]');
77 $this->addMultiCommand('deleteDocuments', $this->lng->txt('delete'));
78 $this->addCommandButton('saveDocumentSorting', $this->lng->txt('sorting_save'));
79 }
80 }
81
85 protected function getColumnDefinition() : array
86 {
87 $i = 0;
88
89 $columns = [];
90
91 if ($this->isEditable) {
92 $columns[++$i] = [
93 'field' => 'chb',
94 'txt' => '',
95 'default' => true,
96 'optional' => false,
97 'sortable' => false,
98 'is_checkbox' => true,
99 'width' => '1%'
100 ];
101 }
102
103 $columns[++$i] = [
104 'field' => 'sorting',
105 'txt' => $this->lng->txt('tos_tbl_docs_head_sorting'),
106 'default' => true,
107 'optional' => false,
108 'sortable' => false,
109 'width' => '5%'
110 ];
111
112 $columns[++$i] = [
113 'field' => 'title',
114 'txt' => $this->lng->txt('tos_tbl_docs_head_title'),
115 'default' => true,
116 'optional' => false,
117 'sortable' => false,
118 'width' => '25%'
119 ];
120
121 $columns[++$i] = [
122 'field' => 'creation_ts',
123 'txt' => $this->lng->txt('tos_tbl_docs_head_created'),
124 'default' => true,
125 'optional' => true,
126 'sortable' => false
127 ];
128
129 $columns[++$i] = [
130 'field' => 'modification_ts',
131 'txt' => $this->lng->txt('tos_tbl_docs_head_last_change'),
132 'default' => true,
133 'optional' => true,
134 'sortable' => false
135 ];
136
137 $columns[++$i] = [
138 'field' => 'criteria',
139 'txt' => $this->lng->txt('tos_tbl_docs_head_criteria'),
140 'default' => true,
141 'optional' => false,
142 'sortable' => false
143 ];
144
145 if ($this->isEditable) {
146 $columns[++$i] = [
147 'field' => 'actions',
148 'txt' => $this->lng->txt('actions'),
149 'default' => true,
150 'optional' => false,
151 'sortable' => false,
152 'width' => '10%'
153 ];
154 };
155
156 return $columns;
157 }
158
163 protected function preProcessData(array &$data) : void
164 {
165 foreach ($data['items'] as $key => $document) {
168 $data['items'][$key] = [
169 'id' => $document->getId(),
170 'title' => $document->getTitle(),
171 'creation_ts' => $document->getCreationTs(),
172 'modification_ts' => $document->getModificationTs(),
173 'text' => $document->getText(),
174 'criteria' => '',
175 'criteriaAssignments' => $document->criteria()
176 ];
177 }
178 }
179
185 protected function formatCellValue(string $column, array $row) : string
186 {
187 if (in_array($column, ['creation_ts', 'modification_ts'])) {
188 return \ilDatePresentation::formatDate(new \ilDateTime($row[$column], IL_CAL_UNIX));
189 } elseif ('sorting' === $column) {
190 return $this->formatSorting($row);
191 } elseif ('title' === $column) {
192 return $this->formatTitle($column, $row);
193 } elseif ('actions' === $column) {
194 return $this->formatActionsDropDown($column, $row);
195 } elseif ('chb' === $column) {
196 return \ilUtil::formCheckbox(false, 'tos_id[]', $row['id']);
197 } elseif ('criteria' === $column) {
198 return $this->formatCriterionAssignments($column, $row);
199 }
200
201 return parent::formatCellValue($column, $row);
202 }
203
209 protected function formatActionsDropDown(string $column, array $row) : string
210 {
211 if (!$this->isEditable) {
212 return '';
213 }
214
215 $this->ctrl->setParameter($this->getParentObject(), 'tos_id', $row['id']);
216
217 $editBtn = $this->uiFactory
218 ->button()
219 ->shy(
220 $this->lng->txt('edit'),
221 $this->ctrl->getLinkTarget($this->getParentObject(), 'showEditDocumentForm')
222 );
223
224 $deleteModal = $this->uiFactory
225 ->modal()
226 ->interruptive(
227 $this->lng->txt('tos_doc_delete'),
228 $this->lng->txt('tos_sure_delete_documents_s'),
229 $this->ctrl->getFormAction($this->getParentObject(), 'deleteDocument')
230 );
231
232 $deleteBtn = $this->uiFactory
233 ->button()
234 ->shy($this->lng->txt('delete'), '#')
235 ->withOnClick($deleteModal->getShowSignal());
236
237 $this->uiComponents[] = $deleteModal;
238
239 $attachCriterionBtn = $this->uiFactory
240 ->button()
241 ->shy(
242 $this->lng->txt('tos_tbl_docs_action_add_criterion'),
243 $this->ctrl->getLinkTarget($this->getParentObject(), 'showAttachCriterionForm')
244 );
245
246 $this->ctrl->setParameter($this->getParentObject(), 'tos_id', null);
247
248 $dropDown = $this->uiFactory
249 ->dropdown()
250 ->standard([$editBtn, $deleteBtn, $attachCriterionBtn])
251 ->withLabel($this->lng->txt('actions'));
252
253 return $this->uiRenderer->render([$dropDown]);
254 }
255
262 protected function formatCriterionAssignments(string $column, array $row) : string
263 {
264 $items = [];
265
266 if (0 === count($row['criteriaAssignments'])) {
267 return $this->lng->txt('tos_tbl_docs_cell_not_criterion');
268 }
269
270 foreach ($row['criteriaAssignments'] as $criterion) {
273 $this->ctrl->setParameter($this->getParentObject(), 'tos_id', $row['id']);
274 $this->ctrl->setParameter($this->getParentObject(), 'crit_id', $criterion->getId());
275
276 $editBtn = $this->uiFactory
277 ->button()
278 ->shy(
279 $this->lng->txt('edit'),
280 $this->ctrl->getLinkTarget($this->getParentObject(), 'showChangeCriterionForm')
281 );
282
283 $deleteModal = $this->uiFactory
284 ->modal()
285 ->interruptive(
286 $this->lng->txt('tos_doc_detach_crit_confirm_title'),
287 $this->lng->txt('tos_doc_sure_detach_crit'),
288 $this->ctrl->getFormAction($this->getParentObject(), 'detachCriterionAssignment')
289 );
290
291 $deleteBtn = $this->uiFactory
292 ->button()
293 ->shy($this->lng->txt('delete'), '#')
294 ->withOnClick($deleteModal->getShowSignal());
295
296 $dropDown = $this->uiFactory
297 ->dropdown()
298 ->standard([$editBtn, $deleteBtn]);
299
300 $criterionType = $this->criterionTypeFactory->findByTypeIdent($criterion->getCriterionId(), true);
301 $typeGui = $criterionType->ui($this->lng);
302
303 $items[implode(' ', [
304 $typeGui->getIdentPresentation(),
305 ($this->isEditable ? $this->uiRenderer->render($dropDown) : '')
306 ])] =
307 $this->uiFactory->legacy(
308 $this->uiRenderer->render(
309 $typeGui->getValuePresentation(
310 $criterion->getCriterionValue(),
311 $this->uiFactory
312 )
313 )
314 );
315
316 if ($this->isEditable) {
317 $this->uiComponents[] = $deleteModal;
318 }
319
320 $this->ctrl->setParameter($this->getParentObject(), 'tos_id', null);
321 $this->ctrl->setParameter($this->getParentObject(), 'crit_id', null);
322 }
323
324 $criteriaList = $this->uiFactory
325 ->listing()
326 ->descriptive($items);
327
328 return $this->uiRenderer->render([
329 $criteriaList
330 ]);
331 }
332
338 protected function formatTitle(string $column, array $row) : string
339 {
340 $modal = $this->uiFactory
341 ->modal()
342 ->lightbox([$this->uiFactory->modal()->lightboxTextPage($row['text'], $row['title'])]);
343
344 $titleLink = $this->uiFactory
345 ->button()
346 ->shy($row[$column], '#')
347 ->withOnClick($modal->getShowSignal());
348
349 return $this->uiRenderer->render([$titleLink, $modal]);
350 }
351
356 protected function formatSorting(array $row) : string
357 {
358 $value = ($this->i++) * $this->factor;
359 if (!$this->isEditable) {
360 return (string) $value;
361 }
362
363 $sortingField = new ilNumberInputGUI('', 'sorting[' . $row['id'] . ']');
364 $sortingField->setValue((string) $value);
365 $sortingField->setMaxLength(4);
366 $sortingField->setSize(2);
367
368 return $sortingField->render();
369 }
370
374 public function getHTML()
375 {
376 return parent::getHTML() . $this->uiRenderer->render($this->uiComponents);
377 }
378}
if(! $in) $columns
Definition: Utf8Test.php:45
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
@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.
formatCellValue(string $column, array $row)
Define a final formatting for a cell value.string
__construct(ilTermsOfServiceControllerEnabled $a_parent_obj, string $command, ilTermsOfServiceCriterionTypeFactoryInterface $criterionTypeFactory, ILIAS\UI\Factory $uiFactory, ILIAS\UI\Renderer $uiRenderer, bool $isEditable=false)
ilTermsOfServiceDocumentTableGUI constructor.
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 ilTermsOfServiceControllerEnabled.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.