ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTermsOfServiceDocumentTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
29 {
30  protected Factory $uiFactory;
31  protected Renderer $uiRenderer;
32  protected bool $isEditable = false;
33  protected int $factor = 10;
34  protected int $i = 1;
35  protected int $numRenderedCriteria = 0;
38  protected array $uiComponents = [];
39 
40  public function __construct(
42  string $command,
44  Factory $uiFactory,
45  Renderer $uiRenderer,
46  bool $isEditable = false
47  ) {
48  $this->criterionTypeFactory = $criterionTypeFactory;
49  $this->uiFactory = $uiFactory;
50  $this->uiRenderer = $uiRenderer;
51  $this->isEditable = $isEditable;
52 
53  $this->setId('tos_documents');
54  $this->setFormName('tos_documents');
55 
56  parent::__construct($a_parent_obj, $command);
57 
58  $this->setTitle($this->lng->txt('tos_tbl_docs_title'));
59  $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), $command));
60 
61  $this->setDefaultOrderDirection('ASC');
62  $this->setDefaultOrderField('sorting');
63  $this->setExternalSorting(true);
64  $this->setExternalSegmentation(true);
65  $this->setLimit(PHP_INT_MAX);
66 
67  $this->setRowTemplate('tpl.tos_documents_row.html', 'Services/TermsOfService');
68 
69  if ($this->isEditable) {
70  $this->setSelectAllCheckbox('tos_id[]');
71  $this->addMultiCommand('deleteDocuments', $this->lng->txt('delete'));
72  $this->addCommandButton('saveDocumentSorting', $this->lng->txt('sorting_save'));
73  }
74  }
75 
76  protected function getColumnDefinition(): array
77  {
78  $i = 0;
79 
80  $columns = [];
81 
82  if ($this->isEditable) {
83  $columns[++$i] = [
84  'field' => 'chb',
85  'txt' => '',
86  'default' => true,
87  'optional' => false,
88  'sortable' => false,
89  'is_checkbox' => true,
90  'width' => '1%'
91  ];
92  }
93 
94  $columns[++$i] = [
95  'field' => 'sorting',
96  'txt' => $this->lng->txt('tos_tbl_docs_head_sorting'),
97  'default' => true,
98  'optional' => false,
99  'sortable' => false,
100  'width' => '5%'
101  ];
102 
103  $columns[++$i] = [
104  'field' => 'title',
105  'txt' => $this->lng->txt('tos_tbl_docs_head_title'),
106  'default' => true,
107  'optional' => false,
108  'sortable' => false,
109  'width' => '25%'
110  ];
111 
112  $columns[++$i] = [
113  'field' => 'creation_ts',
114  'txt' => $this->lng->txt('tos_tbl_docs_head_created'),
115  'default' => true,
116  'optional' => true,
117  'sortable' => false
118  ];
119 
120  $columns[++$i] = [
121  'field' => 'modification_ts',
122  'txt' => $this->lng->txt('tos_tbl_docs_head_last_change'),
123  'default' => true,
124  'optional' => true,
125  'sortable' => false
126  ];
127 
128  $columns[++$i] = [
129  'field' => 'criteria',
130  'txt' => $this->lng->txt('tos_tbl_docs_head_criteria'),
131  'default' => true,
132  'optional' => false,
133  'sortable' => false
134  ];
135 
136  if ($this->isEditable) {
137  $columns[++$i] = [
138  'field' => 'actions',
139  'txt' => $this->lng->txt('actions'),
140  'default' => true,
141  'optional' => false,
142  'sortable' => false,
143  'width' => '10%'
144  ];
145  }
146 
147  return $columns;
148  }
149 
150  protected function preProcessData(array &$data): void
151  {
152  foreach ($data['items'] as $key => $document) {
155  $data['items'][$key] = [
156  'id' => $document->getId(),
157  'title' => $document->getTitle(),
158  'creation_ts' => $document->getCreationTs(),
159  'modification_ts' => $document->getModificationTs(),
160  'text' => $document->getText(),
161  'criteria' => '',
162  'criteriaAssignments' => $document->criteria()
163  ];
164  }
165  }
166 
167  protected function formatCellValue(string $column, array $row): string
168  {
169  if (in_array($column, ['creation_ts', 'modification_ts'])) {
170  return ilDatePresentation::formatDate(new ilDateTime($row[$column], IL_CAL_UNIX));
171  } elseif ('sorting' === $column) {
172  return $this->formatSorting($row);
173  } elseif ('title' === $column) {
174  return $this->formatTitle($column, $row);
175  } elseif ('actions' === $column) {
176  return $this->formatActionsDropDown($column, $row);
177  } elseif ('chb' === $column) {
178  return ilLegacyFormElementsUtil::formCheckbox(false, 'tos_id[]', (string) $row['id']);
179  } elseif ('criteria' === $column) {
180  return $this->formatCriterionAssignments($column, $row);
181  }
182 
183  return parent::formatCellValue($column, $row);
184  }
185 
186  protected function formatActionsDropDown(string $column, array $row): string
187  {
188  if (!$this->isEditable) {
189  return '';
190  }
191 
192  $this->ctrl->setParameter($this->getParentObject(), 'tos_id', $row['id']);
193 
194  $editBtn = $this->uiFactory
195  ->button()
196  ->shy(
197  $this->lng->txt('edit'),
198  $this->ctrl->getLinkTarget($this->getParentObject(), 'showEditDocumentForm')
199  );
200 
201  $deleteModal = $this->uiFactory
202  ->modal()
203  ->interruptive(
204  $this->lng->txt('tos_doc_delete'),
205  $this->lng->txt('tos_sure_delete_documents_s'),
206  $this->ctrl->getFormAction($this->getParentObject(), 'deleteDocument')
207  )
208  ->withActionButtonLabel('deleteDocument');
209 
210  $deleteBtn = $this->uiFactory
211  ->button()
212  ->shy($this->lng->txt('delete'), '#')
213  ->withOnClick($deleteModal->getShowSignal());
214 
215  $this->uiComponents[] = $deleteModal;
216 
217  $attachCriterionBtn = $this->uiFactory
218  ->button()
219  ->shy(
220  $this->lng->txt('tos_tbl_docs_action_add_criterion'),
221  $this->ctrl->getLinkTarget($this->getParentObject(), 'showAttachCriterionForm')
222  );
223 
224  $this->ctrl->setParameter($this->getParentObject(), 'tos_id', null);
225 
226  $dropDown = $this->uiFactory
227  ->dropdown()
228  ->standard([$editBtn, $deleteBtn, $attachCriterionBtn])
229  ->withLabel($this->lng->txt('actions'));
230 
231  return $this->uiRenderer->render([$dropDown]);
232  }
233 
234  protected function formatCriterionAssignments(string $column, array $row): string
235  {
236  $items = [];
237 
238  if (0 === count($row['criteriaAssignments'])) {
239  return $this->lng->txt('tos_tbl_docs_cell_not_criterion');
240  }
241 
242  foreach ($row['criteriaAssignments'] as $criterion) {
245  $this->ctrl->setParameter($this->getParentObject(), 'tos_id', $row['id']);
246  $this->ctrl->setParameter($this->getParentObject(), 'crit_id', $criterion->getId());
247 
248  $editBtn = $this->uiFactory
249  ->button()
250  ->shy(
251  $this->lng->txt('edit'),
252  $this->ctrl->getLinkTarget($this->getParentObject(), 'showChangeCriterionForm')
253  );
254 
255  $deleteModal = $this->uiFactory
256  ->modal()
257  ->interruptive(
258  $this->lng->txt('tos_doc_detach_crit_confirm_title'),
259  $this->lng->txt('tos_doc_sure_detach_crit'),
260  $this->ctrl->getFormAction($this->getParentObject(), 'detachCriterionAssignment')
261  )
262  ->withActionButtonLabel('detachCriterionAssignment');
263 
264  $deleteBtn = $this->uiFactory
265  ->button()
266  ->shy($this->lng->txt('delete'), '#')
267  ->withOnClick($deleteModal->getShowSignal());
268 
269  $dropDown = $this->uiFactory
270  ->dropdown()
271  ->standard([$editBtn, $deleteBtn]);
272 
273  $criterionType = $this->criterionTypeFactory->findByTypeIdent($criterion->getCriterionId(), true);
274  $typeGui = $criterionType->ui($this->lng);
275 
276  $items[implode(' ', [
277  $typeGui->getIdentPresentation(),
278  ($this->isEditable ? $this->uiRenderer->render($dropDown) : '')
279  ])] =
280  $this->uiFactory->legacy(
281  $this->uiRenderer->render(
282  $typeGui->getValuePresentation(
283  $criterion->getCriterionValue(),
285  )
286  )
287  );
288 
289  if ($this->isEditable) {
290  $this->uiComponents[] = $deleteModal;
291  }
292 
293  $this->ctrl->setParameter($this->getParentObject(), 'tos_id', null);
294  $this->ctrl->setParameter($this->getParentObject(), 'crit_id', null);
295  }
296 
297  $criteriaList = $this->uiFactory
298  ->listing()
299  ->descriptive($items);
300 
301  return $this->uiRenderer->render([
302  $criteriaList
303  ]);
304  }
305 
306  protected function formatTitle(string $column, array $row): string
307  {
308  $modal = $this->uiFactory
309  ->modal()
310  ->lightbox([$this->uiFactory->modal()->lightboxTextPage($row['text'], $row['title'])]);
311 
312  $titleLink = $this->uiFactory
313  ->button()
314  ->shy($row[$column], '#')
315  ->withOnClick($modal->getShowSignal());
316 
317  return $this->uiRenderer->render([$titleLink, $modal]);
318  }
319 
320  protected function formatSorting(array $row): string
321  {
322  $value = ($this->i++) * $this->factor;
323  if (!$this->isEditable) {
324  return (string) $value;
325  }
326 
327  $sortingField = new ilNumberInputGUI('', 'sorting[' . $row['id'] . ']');
328  $sortingField->setValue((string) $value);
329  $sortingField->setMaxLength(4);
330  $sortingField->setSize(2);
331 
332  return $sortingField->render();
333  }
334 
335  public function getHTML(): string
336  {
337  return parent::getHTML() . $this->uiRenderer->render($this->uiComponents);
338  }
339 }
Class ilTermsOfServiceDocumentTableGUI.
An entity that renders components to a string output.
Definition: Renderer.php:30
setFormAction(string $a_form_action, bool $a_multipart=false)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
Interface ilTermsOfServiceControllerEnabled.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
const IL_CAL_UNIX
setFormName(string $a_name="")
setId(string $a_val)
__construct(ilTermsOfServiceControllerEnabled $a_parent_obj, string $command, ilTermsOfServiceCriterionTypeFactoryInterface $criterionTypeFactory, Factory $uiFactory, Renderer $uiRenderer, bool $isEditable=false)
setExternalSorting(bool $a_val)
setDefaultOrderField(string $a_defaultorderfield)
This class represents a number property in a property form.
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
string $key
Consumer key/client ID value.
Definition: System.php:193
setDefaultOrderDirection(string $a_defaultorderdirection)
static formCheckbox(bool $checked, string $varname, string $value, bool $disabled=false)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
__construct(Container $dic, ilPlugin $plugin)
setLimit(int $a_limit=0, int $a_default_limit=0)
preProcessData(array &$data)
This method can be used to process the array of all fetched data.
addMultiCommand(string $a_cmd, string $a_text)
ilTermsOfServiceCriterionTypeFactoryInterface $criterionTypeFactory
setExternalSegmentation(bool $a_val)