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