ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDclTableEditGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
17{
18
22 private $table_id;
26 private $table;
30 protected $lng;
34 protected $ctrl;
38 protected $tpl;
42 protected $toolbar;
46 protected $form;
47
48
54 public function __construct(ilDclTableListGUI $a_parent_obj)
55 {
56 global $DIC;
57 $ilCtrl = $DIC['ilCtrl'];
58 $lng = $DIC['lng'];
59 $tpl = $DIC['tpl'];
60 $toolbar = $DIC['ilToolbar'];
61 $locator = $DIC['ilLocator'];
62
63 $this->ctrl = $ilCtrl;
64 $this->lng = $lng;
65 $this->tpl = $tpl;
66 $this->toolbar = $toolbar;
67 $this->parent_object = $a_parent_obj;
68 $this->obj_id = $a_parent_obj->obj_id;
69 $this->table_id = $_GET['table_id'];
70 $this->table = ilDclCache::getTableCache($this->table_id);
71
72 $this->ctrl->saveParameter($this, 'table_id');
73 if ($this->table->getTitle()) {
74 $locator->addItem($this->table->getTitle(), $this->ctrl->getLinkTarget($this, 'edit'));
75 }
76 $this->tpl->setLocator();
77
78 if (!$this->checkAccess()) {
79 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
80 $this->ctrl->redirectByClass('ildclrecordlistgui', 'listRecords');
81 }
82 }
83
84
88 public function executeCommand()
89 {
90 $cmd = $this->ctrl->getCmd();
91
92 switch ($cmd) {
93 case 'update':
94 $this->save("update");
95 break;
96 default:
97 $this->$cmd();
98 break;
99 }
100
101 return true;
102 }
103
104
108 public function create()
109 {
110 $this->initForm();
111 $this->getStandardValues();
112 $this->tpl->setContent($this->form->getHTML());
113 }
114
115
119 public function edit()
120 {
121 if (!$this->table_id) {
122 $this->ctrl->redirectByClass("ildclfieldeditgui", "listFields");
123
124 return;
125 } else {
126 $this->table = ilDclCache::getTableCache($this->table_id);
127 }
128 $this->initForm("edit");
129 $this->getValues();
130 $this->tpl->setContent($this->form->getHTML());
131 }
132
133
137 public function getValues()
138 {
139 $values = array(
140 'title' => $this->table->getTitle(),
141 'add_perm' => (int) $this->table->getAddPerm(),
142 'edit_perm' => (int) $this->table->getEditPerm(),
143 'edit_perm_mode' => $this->table->getEditByOwner() ? 'own' : 'all',
144 'delete_perm' => (int) $this->table->getDeletePerm(),
145 'delete_perm_mode' => $this->table->getDeleteByOwner() ? 'own' : 'all',
146 'export_enabled' => $this->table->getExportEnabled(),
147 'import_enabled' => $this->table->getImportEnabled(),
148 'limited' => $this->table->getLimited(),
149 'limit_start' => substr($this->table->getLimitStart(), 0, 10) . " " . substr($this->table->getLimitStart(), -8),
150 'limit_end' => substr($this->table->getLimitEnd(), 0, 10) . " " . substr($this->table->getLimitEnd(), -8),
151 'default_sort_field' => $this->table->getDefaultSortField(),
152 'default_sort_field_order' => $this->table->getDefaultSortFieldOrder(),
153 'description' => $this->table->getDescription(),
154 'view_own_records_perm' => $this->table->getViewOwnRecordsPerm(),
155 'save_confirmation' => $this->table->getSaveConfirmation(),
156 );
157 if (!$this->table->getLimitStart()) {
158 $values['limit_start'] = null;
159 }
160 if (!$this->table->getLimitEnd()) {
161 $values['limit_end'] = null;
162 }
163 $this->form->setValuesByArray($values);
164 }
165
166
170 public function getStandardValues()
171 {
172 $values = array(
173 'title' => "",
174 'add_perm' => 1,
175 'edit_perm' => 1,
176 'edit_perm_mode' => 'own',
177 'delete_perm_mode' => 'own',
178 'delete_perm' => 1,
179 'edit_by_owner' => 1,
180 'export_enabled' => 0,
181 'import_enabled' => 0,
182 'limited' => 0,
183 'limit_start' => null,
184 'limit_end' => null,
185 );
186 $this->form->setValuesByArray($values);
187 }
188
189
190 /*
191 * cancel
192 */
193 public function cancel()
194 {
195 $this->ctrl->redirectByClass("ilDclTableListGUI", "listTables");
196 }
197
198
204 public function initForm($a_mode = "create")
205 {
206 $this->form = new ilPropertyFormGUI();
207
208 $item = new ilTextInputGUI($this->lng->txt('title'), 'title');
209 $item->setRequired(true);
210 $this->form->addItem($item);
211
212 // 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
213 if ($a_mode != 'create') {
214 $this->createTableSwitcher();
215
216 $item = new ilSelectInputGUI($this->lng->txt('dcl_default_sort_field'), 'default_sort_field');
217 $item->setInfo($this->lng->txt('dcl_default_sort_field_desc'));
218 $fields = array_filter($this->table->getFields(), function (ilDclBaseFieldModel $field) {
219 return !is_null($field->getRecordQuerySortObject());
220 });
221 $options = array(0 => $this->lng->txt('dcl_please_select'));
222 foreach ($fields as $field) {
223 if ($field->getId() == 'comments') {
224 continue;
225 }
226 $options[$field->getId()] = $field->getTitle();
227 }
228 $item->setOptions($options);
229 $this->form->addItem($item);
230
231 $item = new ilSelectInputGUI($this->lng->txt('dcl_default_sort_field_order'), 'default_sort_field_order');
232 $options = array('asc' => $this->lng->txt('dcl_asc'), 'desc' => $this->lng->txt('dcl_desc'));
233 $item->setOptions($options);
234 $this->form->addItem($item);
235 }
236
237 $item = new ilTextAreaInputGUI($this->lng->txt('additional_info'), 'description');
238 $item->setUseRte(true);
239 $item->setInfo($this->lng->txt('dcl_additional_info_desc'));
240 // $item->setRTESupport($this->table->getId(), 'dcl', 'table_settings');
241 $item->setRteTagSet('mini');
242 $this->form->addItem($item);
243
245 $section->setTitle($this->lng->txt('dcl_permissions_form'));
246 $this->form->addItem($section);
247
248 $item = new ilCustomInputGUI();
249 $item->setHtml($this->lng->txt('dcl_table_info'));
250 $item->setTitle($this->lng->txt('dcl_table_info_title'));
251 $this->form->addItem($item);
252
253 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_add_perm'), 'add_perm');
254 $item->setInfo($this->lng->txt("dcl_add_perm_desc"));
255 $this->form->addItem($item);
256
257 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_save_confirmation'), 'save_confirmation');
258 $item->setInfo($this->lng->txt('dcl_save_confirmation_desc'));
259 $this->form->addItem($item);
260
261 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_edit_perm'), 'edit_perm');
262 // $item->setInfo($this->lng->txt("dcl_edit_perm_info"));
263 $this->form->addItem($item);
264
265 $radios = new ilRadioGroupInputGUI('', 'edit_perm_mode');
266 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_all_entries'), 'all'));
267 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_own_entries'), 'own'));
268 $item->addSubItem($radios);
269
270 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_delete_perm'), 'delete_perm');
271 // $item->setInfo($this->lng->txt("dcl_delete_perm_info"));
272 $this->form->addItem($item);
273
274 $radios = new ilRadioGroupInputGUI('', 'delete_perm_mode');
275 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_all_entries'), 'all'));
276 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_own_entries'), 'own'));
277 $item->addSubItem($radios);
278
279 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_view_own_records_perm'), 'view_own_records_perm');
280 // $item->setInfo($this->lng->txt("dcl_edit_by_owner_info"));
281 $this->form->addItem($item);
282
283 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_export_enabled'), 'export_enabled');
284 $item->setInfo($this->lng->txt('dcl_export_enabled_desc'));
285 $this->form->addItem($item);
286
287 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_import_enabled'), 'import_enabled');
288 $item->setInfo($this->lng->txt('dcl_import_enabled_desc'));
289 $this->form->addItem($item);
290
291 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_limited'), 'limited');
292 $sitem1 = new ilDateTimeInputGUI($this->lng->txt('dcl_limit_start'), 'limit_start');
293 $sitem1->setShowTime(true);
294 $sitem2 = new ilDateTimeInputGUI($this->lng->txt('dcl_limit_end'), 'limit_end');
295 $sitem2->setShowTime(true);
296 $item->setInfo($this->lng->txt("dcl_limited_desc"));
297 $item->addSubItem($sitem1);
298 $item->addSubItem($sitem2);
299 $this->form->addItem($item);
300
301 if ($a_mode == "edit") {
302 $this->form->addCommandButton('update', $this->lng->txt('dcl_table_' . $a_mode));
303 } else {
304 $this->form->addCommandButton('save', $this->lng->txt('dcl_table_' . $a_mode));
305 }
306
307 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
308 $this->form->setFormAction($this->ctrl->getFormAction($this, $a_mode));
309 if ($a_mode == "edit") {
310 $this->form->setTitle($this->lng->txt('dcl_edit_table'));
311 } else {
312 $this->form->setTitle($this->lng->txt('dcl_new_table'));
313 }
314 }
315
316
320 public function doTableSwitch()
321 {
322 $this->ctrl->setParameter($this, "table_id", $_POST['table_id']);
323 $this->ctrl->redirect($this, "edit");
324 }
325
326
332 public function save($a_mode = "create")
333 {
334 global $DIC;
335 $ilTabs = $DIC['ilTabs'];
336
337 if (!ilObjDataCollectionAccess::checkActionForObjId('write', $this->obj_id)) {
338 $this->accessDenied();
339
340 return;
341 }
342
343 $ilTabs->activateTab("id_fields");
344 $this->initForm($a_mode);
345
346 if ($this->checkInput($a_mode)) {
347 if ($a_mode != "update") {
348 $this->table = ilDclCache::getTableCache();
349 } elseif ($this->table_id) {
350 $this->table = ilDclCache::getTableCache($this->table_id);
351 } else {
352 $this->ctrl->redirectByClass("ildclfieldeditgui", "listFields");
353 }
354
355 $this->table->setTitle($this->form->getInput("title"));
356 $this->table->setObjId($this->obj_id);
357 $this->table->setSaveConfirmation((bool) $this->form->getInput('save_confirmation'));
358 $this->table->setAddPerm((bool) $this->form->getInput("add_perm"));
359 $this->table->setEditPerm((bool) $this->form->getInput("edit_perm"));
360 if ($this->table->getEditPerm()) {
361 $edit_by_owner = ($this->form->getInput('edit_perm_mode') == 'own');
362 $this->table->setEditByOwner($edit_by_owner);
363 }
364 $this->table->setDeletePerm((bool) $this->form->getInput("delete_perm"));
365 if ($this->table->getDeletePerm()) {
366 $delete_by_owner = ($this->form->getInput('delete_perm_mode') == 'own');
367 $this->table->setDeleteByOwner($delete_by_owner);
368 }
369 $this->table->setViewOwnRecordsPerm($this->form->getInput('view_own_records_perm'));
370 $this->table->setExportEnabled($this->form->getInput("export_enabled"));
371 $this->table->setImportEnabled($this->form->getInput("import_enabled"));
372 $this->table->setDefaultSortField($this->form->getInput("default_sort_field"));
373 $this->table->setDefaultSortFieldOrder($this->form->getInput("default_sort_field_order"));
374 $this->table->setLimited($this->form->getInput("limited"));
375 $this->table->setDescription($this->form->getInput('description'));
376 $limit_start = $this->form->getInput("limit_start");
377 $limit_end = $this->form->getInput("limit_end");
378 $this->table->setLimitStart($limit_start);
379 $this->table->setLimitEnd($limit_end);
380 if ($a_mode == "update") {
381 $this->table->doUpdate();
382 ilUtil::sendSuccess($this->lng->txt("dcl_msg_table_edited"), true);
383 $this->ctrl->redirectByClass("ildcltableeditgui", "edit");
384 } else {
385 $this->table->doCreate();
386 ilUtil::sendSuccess($this->lng->txt("dcl_msg_table_created"), true);
387 $this->ctrl->setParameterByClass("ildclfieldlistgui", "table_id", $this->table->getId());
388 $this->ctrl->redirectByClass("ildclfieldlistgui", "listFields");
389 }
390 } else {
391 $this->form->setValuesByPost();
392 $this->tpl->setContent($this->form->getHTML());
393 }
394 }
395
396
404 protected function checkInput($a_mode)
405 {
406 $return = $this->form->checkInput();
407
408 // Title of table must be unique in one DC
409 if ($a_mode == 'create') {
410 if ($title = $this->form->getInput('title')) {
411 if (ilObjDataCollection::_hasTableByTitle($title, $this->obj_id)) {
412 $inputObj = $this->form->getItemByPostVar('title');
413 $inputObj->setAlert($this->lng->txt("dcl_table_title_unique"));
414 $return = false;
415 }
416 }
417 }
418
419 if (!$return) {
420 ilUtil::sendFailure($this->lng->txt("form_input_not_valid"));
421 }
422
423 return $return;
424 }
425
426
427 /*
428 * accessDenied
429 */
430 public function accessDenied()
431 {
432 $this->tpl->setContent("Access denied.");
433 }
434
435
439 public function confirmDelete()
440 {
441 $conf = new ilConfirmationGUI();
442 $conf->setFormAction($this->ctrl->getFormAction($this));
443 $conf->setHeaderText($this->lng->txt('dcl_confirm_delete_table'));
444
445 $conf->addItem('table', (int) $this->table->getId(), $this->table->getTitle());
446
447 $conf->setConfirm($this->lng->txt('delete'), 'delete');
448 $conf->setCancel($this->lng->txt('cancel'), 'cancelDelete');
449
450 $this->tpl->setContent($conf->getHTML());
451 }
452
453
457 public function cancelDelete()
458 {
459 $this->ctrl->redirectByClass("ilDclTableListGUI", "listTables");
460 }
461
462
463 /*
464 * delete
465 */
466 public function delete()
467 {
468 if (count($this->table->getCollectionObject()->getTables()) < 2) {
469 ilUtil::sendFailure($this->lng->txt("dcl_cant_delete_last_table"), true); //TODO change lng var
470 $this->table->doDelete(true);
471 } else {
472 $this->table->doDelete(false);
473 }
474
475 $this->ctrl->redirectByClass("ildcltablelistgui", "listtables");
476 }
477
478
482 protected function checkAccess()
483 {
484 $ref_id = $this->parent_object->getDataCollectionObject()->getRefId();
485
486 return $this->table_id ? ilObjDataCollectionAccess::hasAccessToEditTable($ref_id, $this->table_id) : ilObjDataCollectionAccess::hasWriteAccess($ref_id);
487 }
488
489
495 protected function createTableSwitcher()
496 {
497 // Show tables
498 $tables = $this->parent_object->getDataCollectionObject()->getTables();
499
500 foreach ($tables as $table) {
501 $options[$table->getId()] = $table->getTitle();
502 }
503 $table_selection = new ilSelectInputGUI('', 'table_id');
504 $table_selection->setOptions($options);
505 $table_selection->setValue($this->table->getId());
506
507 $this->toolbar->setFormAction($this->ctrl->getFormActionByClass("ilDclTableEditGUI", "doTableSwitch"));
508 $this->toolbar->addText($this->lng->txt("dcl_select"));
509 $this->toolbar->addInputItem($table_selection);
510 $button = ilSubmitButton::getInstance();
511 $button->setCommand("doTableSwitch");
512 $button->setCaption('change');
513 $this->toolbar->addButtonInstance($button);
514
515 return $options;
516 }
517}
$section
Definition: Utf8Test.php:83
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a checkbox property in a property form.
Confirmation screen class.
This class represents a custom property in a property form.
This class represents a date/time property in a property form.
Class ilDclBaseFieldModel.
getRecordQuerySortObject($direction="asc", $sort_by_status=false)
Returns a query-object for building the record-loader-sql-query.
static getTableCache($table_id=0)
Class ilDclBaseFieldModel.
getStandardValues()
getStandardValues
create()
create table add form
edit()
create field edit form
initForm($a_mode="create")
initEditCustomForm
__construct(ilDclTableListGUI $a_parent_obj)
Constructor.
checkInput($a_mode)
Custom checks for the form input.
save($a_mode="create")
save
executeCommand()
execute command
Class ilDclTableListGUI.
This class represents a section header in a property form.
static hasAccessToEditTable($ref_id, $table_id)
static checkActionForObjId($action, $obj_id)
static _hasTableByTitle($title, $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 class represents an option in a radio group.
This class represents a selection list property in a property form.
static getInstance()
Factory.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $DIC
Definition: goto.php:24