ILIAS  release_8 Revision v8.24
class.ilDclTableEditGUI.php
Go to the documentation of this file.
1<?php
2
20{
21 private ?int $table_id;
23 protected ilLanguage $lng;
24 protected ilCtrl $ctrl;
31 protected int $obj_id;
32
36 public function __construct(ilDclTableListGUI $a_parent_obj)
37 {
38 global $DIC;
39
40 $locator = $DIC['ilLocator'];
41
42 $this->ctrl = $DIC->ctrl();
43 $this->lng = $DIC->language();
44 $this->tpl = $DIC->ui()->mainTemplate();
45 $this->toolbar = $DIC->toolbar();
46 $this->parent_object = $a_parent_obj;
47 $this->obj_id = $a_parent_obj->getObjId();
48 $this->http = $DIC->http();
49 $this->refinery = $DIC->refinery();
50
51 $table_id = null;
52 if ($this->http->wrapper()->query()->has("table_id")) {
53 $table_id = $this->http->wrapper()->query()->retrieve('table_id', $this->refinery->kindlyTo()->int());
54 }
55
56 $this->table_id = $table_id;
57 $this->table = ilDclCache::getTableCache($this->table_id);
58
59 $this->ctrl->saveParameter($this, 'table_id');
60 if ($this->table->getTitle()) {
61 $locator->addItem($this->table->getTitle(), $this->ctrl->getLinkTarget($this, 'edit'));
62 }
63 $this->tpl->setLocator();
64
65 if (!$this->checkAccess()) {
66 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
67 $this->ctrl->redirectByClass('ildclrecordlistgui', 'listRecords');
68 }
69 }
70
71 public function executeCommand(): void
72 {
73 $cmd = $this->ctrl->getCmd();
74
75 switch ($cmd) {
76 case 'update':
77 $this->save("update");
78 break;
79 default:
80 $this->$cmd();
81 break;
82 }
83 }
84
85 public function create(): void
86 {
87 $this->initForm();
88 $this->getStandardValues();
89 $this->tpl->setContent($this->form->getHTML());
90 }
91
92 public function edit(): void
93 {
94 if (!$this->table_id) {
95 $this->ctrl->redirectByClass("ildclfieldeditgui", "listFields");
96
97 return;
98 } else {
99 $this->table = ilDclCache::getTableCache($this->table_id);
100 }
101 $this->initForm("edit");
102 $this->getValues();
103 $this->tpl->setContent($this->form->getHTML());
104 }
105
106 public function getValues(): void
107 {
108 $values = array(
109 'title' => $this->table->getTitle(),
110 'add_perm' => (int) $this->table->getAddPerm(),
111 'edit_perm' => (int) $this->table->getEditPerm(),
112 'edit_perm_mode' => $this->table->getEditByOwner() ? 'own' : 'all',
113 'delete_perm' => (int) $this->table->getDeletePerm(),
114 'delete_perm_mode' => $this->table->getDeleteByOwner() ? 'own' : 'all',
115 'export_enabled' => $this->table->getExportEnabled(),
116 'import_enabled' => $this->table->getImportEnabled(),
117 'limited' => $this->table->getLimited(),
118 'limit_start' => substr($this->table->getLimitStart(), 0, 10) . " " . substr(
119 $this->table->getLimitStart(),
120 -8
121 ),
122 'limit_end' => substr($this->table->getLimitEnd(), 0, 10) . " " . substr($this->table->getLimitEnd(), -8),
123 'default_sort_field' => $this->table->getDefaultSortField(),
124 'default_sort_field_order' => $this->table->getDefaultSortFieldOrder(),
125 'description' => $this->table->getDescription(),
126 'view_own_records_perm' => $this->table->getViewOwnRecordsPerm(),
127 'save_confirmation' => $this->table->getSaveConfirmation(),
128 );
129 if (!$this->table->getLimitStart()) {
130 $values['limit_start'] = null;
131 }
132 if (!$this->table->getLimitEnd()) {
133 $values['limit_end'] = null;
134 }
135 $this->form->setValuesByArray($values);
136 }
137
138 public function getStandardValues(): void
139 {
140 $values = array(
141 'title' => "",
142 'add_perm' => 1,
143 'edit_perm' => 1,
144 'edit_perm_mode' => 'own',
145 'delete_perm_mode' => 'own',
146 'delete_perm' => 1,
147 'edit_by_owner' => 1,
148 'export_enabled' => 0,
149 'import_enabled' => 0,
150 'limited' => 0,
151 'limit_start' => null,
152 'limit_end' => null,
153 );
154 $this->form->setValuesByArray($values);
155 }
156
157 public function cancel(): void
158 {
159 $this->ctrl->redirectByClass("ilDclTableListGUI", "listTables");
160 }
161
165 public function initForm(string $a_mode = "create"): void
166 {
167 $this->form = new ilPropertyFormGUI();
168
169 $item = new ilTextInputGUI($this->lng->txt('title'), 'title');
170 $item->setRequired(true);
171 $this->form->addItem($item);
172
173 // Show default order field, direction and tableswitcher only in edit mode, because table id is not yet given and there are no fields to select
174 if ($a_mode != 'create') {
175 $this->createTableSwitcher();
176
177 $item = new ilSelectInputGUI($this->lng->txt('dcl_default_sort_field'), 'default_sort_field');
178 $item->setInfo($this->lng->txt('dcl_default_sort_field_desc'));
179 $fields = array_filter($this->table->getFields(), function (ilDclBaseFieldModel $field) {
180 return !is_null($field->getRecordQuerySortObject());
181 });
182 $options = array(0 => $this->lng->txt('dcl_please_select'));
183 foreach ($fields as $field) {
184 if ($field->getId() == 'comments') {
185 continue;
186 }
187 $options[$field->getId()] = $field->getTitle();
188 }
189 $item->setOptions($options);
190 $this->form->addItem($item);
191
192 $item = new ilSelectInputGUI($this->lng->txt('dcl_default_sort_field_order'), 'default_sort_field_order');
193 $options = array('asc' => $this->lng->txt('dcl_asc'), 'desc' => $this->lng->txt('dcl_desc'));
194 $item->setOptions($options);
195 $this->form->addItem($item);
196 }
197
198 $item = new ilTextAreaInputGUI($this->lng->txt('additional_info'), 'description');
199 $item->setUseRte(true);
200 $item->setInfo($this->lng->txt('dcl_additional_info_desc'));
201 $item->setRteTagSet('mini');
202 $this->form->addItem($item);
203
204 $section = new ilFormSectionHeaderGUI();
205 $section->setTitle($this->lng->txt('dcl_permissions_form'));
206 $this->form->addItem($section);
207
208 $item = new ilCustomInputGUI();
209 $item->setHtml($this->lng->txt('dcl_table_info'));
210 $item->setTitle($this->lng->txt('dcl_table_info_title'));
211 $this->form->addItem($item);
212
213 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_add_perm'), 'add_perm');
214 $item->setInfo($this->lng->txt("dcl_add_perm_desc"));
215 $this->form->addItem($item);
216
217 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_save_confirmation'), 'save_confirmation');
218 $item->setInfo($this->lng->txt('dcl_save_confirmation_desc'));
219 $this->form->addItem($item);
220
221 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_edit_perm'), 'edit_perm');
222 $this->form->addItem($item);
223
224 $radios = new ilRadioGroupInputGUI('', 'edit_perm_mode');
225 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_all_entries'), 'all'));
226 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_own_entries'), 'own'));
227 $item->addSubItem($radios);
228
229 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_delete_perm'), 'delete_perm');
230 $this->form->addItem($item);
231
232 $radios = new ilRadioGroupInputGUI('', 'delete_perm_mode');
233 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_all_entries'), 'all'));
234 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_own_entries'), 'own'));
235 $item->addSubItem($radios);
236
237 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_view_own_records_perm'), 'view_own_records_perm');
238 $this->form->addItem($item);
239
240 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_export_enabled'), 'export_enabled');
241 $item->setInfo($this->lng->txt('dcl_export_enabled_desc'));
242 $this->form->addItem($item);
243
244 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_import_enabled'), 'import_enabled');
245 $item->setInfo($this->lng->txt('dcl_import_enabled_desc'));
246 $this->form->addItem($item);
247
248 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_limited'), 'limited');
249 $sitem1 = new ilDateTimeInputGUI($this->lng->txt('dcl_limit_start'), 'limit_start');
250 $sitem1->setShowTime(true);
251 $sitem2 = new ilDateTimeInputGUI($this->lng->txt('dcl_limit_end'), 'limit_end');
252 $sitem2->setShowTime(true);
253 $item->setInfo($this->lng->txt("dcl_limited_desc"));
254 $item->addSubItem($sitem1);
255 $item->addSubItem($sitem2);
256 $this->form->addItem($item);
257
258 if ($a_mode == "edit") {
259 $this->form->addCommandButton('update', $this->lng->txt('dcl_table_' . $a_mode));
260 } else {
261 $this->form->addCommandButton('save', $this->lng->txt('dcl_table_' . $a_mode));
262 }
263
264 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
265 $this->form->setFormAction($this->ctrl->getFormAction($this, $a_mode));
266 if ($a_mode == "edit") {
267 $this->form->setTitle($this->lng->txt('dcl_edit_table'));
268 } else {
269 $this->form->setTitle($this->lng->txt('dcl_new_table'));
270 }
271 }
272
273 public function doTableSwitch(): void
274 {
275 $table_id = $this->http->wrapper()->post()->retrieve('table_id', $this->refinery->kindlyTo()->int());
276 $this->ctrl->setParameter($this, "table_id", $table_id);
277 $this->ctrl->redirect($this, "edit");
278 }
279
280 public function save(string $a_mode = "create"): void
281 {
282 global $DIC;
283 $ilTabs = $DIC['ilTabs'];
284
285 if (!ilObjDataCollectionAccess::checkActionForObjId('write', $this->obj_id)) {
286 $this->accessDenied();
287
288 return;
289 }
290
291 $ilTabs->activateTab("id_fields");
292 $this->initForm($a_mode);
293
294 if ($this->checkInput($a_mode)) {
295 if ($a_mode != "update") {
296 $this->table = ilDclCache::getTableCache();
297 } elseif ($this->table_id) {
298 $this->table = ilDclCache::getTableCache($this->table_id);
299 } else {
300 $this->ctrl->redirectByClass("ildclfieldeditgui", "listFields");
301 }
302
303 $this->table->setTitle($this->form->getInput("title"));
304 $this->table->setObjId($this->obj_id);
305 $this->table->setSaveConfirmation((bool) $this->form->getInput('save_confirmation'));
306 $this->table->setAddPerm((bool) $this->form->getInput("add_perm"));
307 $this->table->setEditPerm((bool) $this->form->getInput("edit_perm"));
308 if ($this->table->getEditPerm()) {
309 $edit_by_owner = ($this->form->getInput('edit_perm_mode') == 'own');
310 $this->table->setEditByOwner($edit_by_owner);
311 }
312 $this->table->setDeletePerm((bool) $this->form->getInput("delete_perm"));
313 if ($this->table->getDeletePerm()) {
314 $delete_by_owner = ($this->form->getInput('delete_perm_mode') == 'own');
315 $this->table->setDeleteByOwner($delete_by_owner);
316 }
317 $this->table->setViewOwnRecordsPerm($this->form->getInput('view_own_records_perm'));
318 $this->table->setExportEnabled($this->form->getInput("export_enabled"));
319 $this->table->setImportEnabled($this->form->getInput("import_enabled"));
320 $this->table->setDefaultSortField($this->form->getInput("default_sort_field"));
321 $this->table->setDefaultSortFieldOrder($this->form->getInput("default_sort_field_order"));
322 $this->table->setLimited($this->form->getInput("limited"));
323 $this->table->setDescription($this->form->getInput('description'));
324 $limit_start = $this->form->getInput("limit_start");
325 $limit_end = $this->form->getInput("limit_end");
326 $this->table->setLimitStart($limit_start);
327 $this->table->setLimitEnd($limit_end);
328 if ($a_mode == "update") {
329 $this->table->doUpdate();
330 $this->tpl->setOnScreenMessage('success', $this->lng->txt("dcl_msg_table_edited"), true);
331 $this->ctrl->redirectByClass("ildcltableeditgui", "edit");
332 } else {
333 $this->table->doCreate();
334 $this->tpl->setOnScreenMessage('success', $this->lng->txt("dcl_msg_table_created"), true);
335 $this->ctrl->setParameterByClass("ildclfieldlistgui", "table_id", $this->table->getId());
336 $this->ctrl->redirectByClass("ildclfieldlistgui", "listFields");
337 }
338 } else {
339 $this->form->setValuesByPost();
340 $this->tpl->setContent($this->form->getHTML());
341 }
342 }
343
348 protected function checkInput(string $a_mode): bool
349 {
350 $return = $this->form->checkInput();
351
352 // Title of table must be unique in one DC
353 if ($a_mode == 'create') {
354 if ($title = $this->form->getInput('title')) {
355 if (ilObjDataCollection::_hasTableByTitle($title, $this->obj_id)) {
356 $inputObj = $this->form->getItemByPostVar('title');
357 $inputObj->setAlert($this->lng->txt("dcl_table_title_unique"));
358 $return = false;
359 }
360 }
361 }
362
363 if (!$return) {
364 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("form_input_not_valid"));
365 }
366
367 return $return;
368 }
369
370 public function accessDenied(): void
371 {
372 $this->tpl->setContent("Access denied.");
373 }
374
375 public function confirmDelete(): void
376 {
377 $conf = new ilConfirmationGUI();
378 $conf->setFormAction($this->ctrl->getFormAction($this));
379 $conf->setHeaderText($this->lng->txt('dcl_confirm_delete_table'));
380
381 $conf->addItem('table', $this->table->getId(), $this->table->getTitle());
382
383 $conf->setConfirm($this->lng->txt('delete'), 'delete');
384 $conf->setCancel($this->lng->txt('cancel'), 'cancelDelete');
385
386 $this->tpl->setContent($conf->getHTML());
387 }
388
389 public function cancelDelete(): void
390 {
391 $this->ctrl->redirectByClass("ilDclTableListGUI", "listTables");
392 }
393
394 public function delete(): void
395 {
396 if (count($this->table->getCollectionObject()->getTables()) < 2) {
397 $this->tpl->setOnScreenMessage(
398 'failure',
399 $this->lng->txt("dcl_cant_delete_last_table"),
400 true
401 ); //TODO change lng var
402 $this->table->doDelete(true);
403 } else {
404 $this->table->doDelete(false);
405 }
406 $this->ctrl->clearParameterByClass("ilobjdatacollectiongui", "table_id");
407 $this->ctrl->redirectByClass("ildcltablelistgui", "listtables");
408 }
409
410 protected function checkAccess(): bool
411 {
412 $ref_id = $this->parent_object->getDataCollectionObject()->getRefId();
413
415 $ref_id,
416 $this->table_id
418 }
419
423 protected function createTableSwitcher(): array
424 {
425 // Show tables
426 $tables = $this->parent_object->getDataCollectionObject()->getTables();
427
428 foreach ($tables as $table) {
429 $options[$table->getId()] = $table->getTitle();
430 }
431 $table_selection = new ilSelectInputGUI($this->lng->txt("dcl_select"), 'table_id');
432 $table_selection->setOptions($options);
433 $table_selection->setValue($this->table->getId());
434
435 $this->toolbar->setFormAction($this->ctrl->getFormActionByClass("ilDclTableEditGUI", "doTableSwitch"));
436 $this->toolbar->addText($this->lng->txt("dcl_select"));
437 $this->toolbar->addInputItem($table_selection);
438 $button = ilSubmitButton::getInstance();
439 $button->setCommand("doTableSwitch");
440 $button->setCaption('change');
441 $this->toolbar->addButtonInstance($button);
442
443 return $options;
444 }
445}
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
Builds data types.
Definition: Factory.php:21
Class Services.
Definition: Services.php:38
return true
This class represents a checkbox property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getRecordQuerySortObject(string $direction="asc", bool $sort_by_status=false)
Returns a query-object for building the record-loader-sql-query.
static getTableCache(int $table_id=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS Refinery Factory $refinery
initForm(string $a_mode="create")
initEditCustomForm
save(string $a_mode="create")
__construct(ilDclTableListGUI $a_parent_obj)
Constructor.
ilGlobalTemplateInterface $tpl
ILIAS HTTP Services $http
checkInput(string $a_mode)
Custom checks for the form input.
ilDclTableListGUI $parent_object
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...
getId()
Get table id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
static hasWriteAccess(int $ref, ?int $user_id=0)
static hasAccessToEditTable(int $ref_id, int $table_id)
static checkActionForObjId(string $action, int $obj_id)
static _hasTableByTitle(string $title, int $obj_id)
Checks if a DataCollection has a table with a given title.
This class represents a property form user interface.
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a selection list property in a property form.
This class represents a text area property in a property form.
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:67
static http()
Fetches the global http state from ILIAS.
form( $class_path, string $cmd)