ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
5
18{
19
23 private $table_id;
27 private $table;
31 protected $lng;
35 protected $ctrl;
39 protected $tpl;
43 protected $toolbar;
47 protected $form;
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 $locator->addItem($this->table->getTitle(), $this->ctrl->getLinkTarget($this, 'edit'));
74 $this->tpl->setLocator();
75
76 if (!$this->checkAccess()) {
77 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
78 $this->ctrl->redirectByClass('ildclrecordlistgui', 'listRecords');
79 }
80 }
81
82
86 public function executeCommand()
87 {
88 $cmd = $this->ctrl->getCmd();
89
90 switch ($cmd) {
91 case 'update':
92 $this->save("update");
93 break;
94 default:
95 $this->$cmd();
96 break;
97 }
98
99 return true;
100 }
101
102
106 public function create()
107 {
108 $this->initForm();
109 $this->getStandardValues();
110 $this->tpl->setContent($this->form->getHTML());
111 }
112
113
117 public function edit()
118 {
119 if (!$this->table_id) {
120 $this->ctrl->redirectByClass("ildclfieldeditgui", "listFields");
121
122 return;
123 } else {
124 $this->table = ilDclCache::getTableCache($this->table_id);
125 }
126 $this->initForm("edit");
127 $this->getValues();
128 $this->tpl->setContent($this->form->getHTML());
129 }
130
131
135 public function getValues()
136 {
137 $values = array(
138 'title' => $this->table->getTitle(),
139 'add_perm' => (int) $this->table->getAddPerm(),
140 'edit_perm' => (int) $this->table->getEditPerm(),
141 'edit_perm_mode' => $this->table->getEditByOwner() ? 'own' : 'all',
142 'delete_perm' => (int) $this->table->getDeletePerm(),
143 'delete_perm_mode' => $this->table->getDeleteByOwner() ? 'own' : 'all',
144 'export_enabled' => $this->table->getExportEnabled(),
145 'import_enabled' => $this->table->getImportEnabled(),
146 'limited' => $this->table->getLimited(),
147 'limit_start' => substr($this->table->getLimitStart(), 0, 10) . " " . substr($this->table->getLimitStart(), -8),
148 'limit_end' => substr($this->table->getLimitEnd(), 0, 10) . " " . substr($this->table->getLimitEnd(), -8),
149 'default_sort_field' => $this->table->getDefaultSortField(),
150 'default_sort_field_order' => $this->table->getDefaultSortFieldOrder(),
151 'description' => $this->table->getDescription(),
152 'view_own_records_perm' => $this->table->getViewOwnRecordsPerm(),
153 'save_confirmation' => $this->table->getSaveConfirmation(),
154 );
155 if (!$this->table->getLimitStart()) {
156 $values['limit_start'] = null;
157 }
158 if (!$this->table->getLimitEnd()) {
159 $values['limit_end'] = null;
160 }
161 $this->form->setValuesByArray($values);
162 }
163
164
168 public function getStandardValues()
169 {
170 $values = array(
171 'title' => "",
172 'add_perm' => 1,
173 'edit_perm' => 1,
174 'edit_perm_mode' => 'own',
175 'delete_perm_mode' => 'own',
176 'delete_perm' => 1,
177 'edit_by_owner' => 1,
178 'export_enabled' => 0,
179 'import_enabled' => 0,
180 'limited' => 0,
181 'limit_start' => null,
182 'limit_end' => null
183 );
184 $this->form->setValuesByArray($values);
185 }
186
187
188 /*
189 * cancel
190 */
191 public function cancel()
192 {
193 $this->ctrl->redirectByClass("ilDclTableListGUI", "listTables");
194 }
195
196
202 public function initForm($a_mode = "create")
203 {
204 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
205 $this->form = new ilPropertyFormGUI();
206
207 $item = new ilTextInputGUI($this->lng->txt('title'), 'title');
208 $item->setRequired(true);
209 $this->form->addItem($item);
210
211 // 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
212 if ($a_mode != 'create') {
213 $this->createTableSwitcher();
214
215 $item = new ilSelectInputGUI($this->lng->txt('dcl_default_sort_field'), 'default_sort_field');
216 $item->setInfo($this->lng->txt('dcl_default_sort_field_desc'));
217 $fields = $this->table->getFields();
218 $options = array( 0 => $this->lng->txt('dcl_please_select') );
219 foreach ($fields as $field) {
220 if ($field->getId() == 'comments') {
221 continue;
222 }
223 $options[$field->getId()] = $field->getTitle();
224 }
225 $item->setOptions($options);
226 $this->form->addItem($item);
227
228 $item = new ilSelectInputGUI($this->lng->txt('dcl_default_sort_field_order'), 'default_sort_field_order');
229 $options = array( 'asc' => $this->lng->txt('dcl_asc'), 'desc' => $this->lng->txt('dcl_desc') );
230 $item->setOptions($options);
231 $this->form->addItem($item);
232 }
233
234 $item = new ilTextAreaInputGUI($this->lng->txt('additional_info'), 'description');
235 $item->setUseRte(true);
236 $item->setInfo($this->lng->txt('dcl_additional_info_desc'));
237 // $item->setRTESupport($this->table->getId(), 'dcl', 'table_settings');
238 $item->setRteTagSet('mini');
239 $this->form->addItem($item);
240
242 $section->setTitle($this->lng->txt('dcl_permissions_form'));
243 $this->form->addItem($section);
244
245 $item = new ilCustomInputGUI();
246 $item->setHtml($this->lng->txt('dcl_table_info'));
247 $item->setTitle($this->lng->txt('dcl_table_info_title'));
248 $this->form->addItem($item);
249
250 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_add_perm'), 'add_perm');
251 $item->setInfo($this->lng->txt("dcl_add_perm_desc"));
252 $this->form->addItem($item);
253
254 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_save_confirmation'), 'save_confirmation');
255 $item->setInfo($this->lng->txt('dcl_save_confirmation_desc'));
256 $this->form->addItem($item);
257
258 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_edit_perm'), 'edit_perm');
259 // $item->setInfo($this->lng->txt("dcl_edit_perm_info"));
260 $this->form->addItem($item);
261
262 $radios = new ilRadioGroupInputGUI('', 'edit_perm_mode');
263 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_all_entries'), 'all'));
264 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_own_entries'), 'own'));
265 $item->addSubItem($radios);
266
267 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_delete_perm'), 'delete_perm');
268 // $item->setInfo($this->lng->txt("dcl_delete_perm_info"));
269 $this->form->addItem($item);
270
271 $radios = new ilRadioGroupInputGUI('', 'delete_perm_mode');
272 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_all_entries'), 'all'));
273 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_own_entries'), 'own'));
274 $item->addSubItem($radios);
275
276 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_view_own_records_perm'), 'view_own_records_perm');
277 // $item->setInfo($this->lng->txt("dcl_edit_by_owner_info"));
278 $this->form->addItem($item);
279
280 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_export_enabled'), 'export_enabled');
281 $item->setInfo($this->lng->txt('dcl_export_enabled_desc'));
282 $this->form->addItem($item);
283
284 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_import_enabled'), 'import_enabled');
285 $item->setInfo($this->lng->txt('dcl_import_enabled_desc'));
286 $this->form->addItem($item);
287
288 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_limited'), 'limited');
289 $sitem1 = new ilDateTimeInputGUI($this->lng->txt('dcl_limit_start'), 'limit_start');
290 $sitem1->setShowTime(true);
291 $sitem2 = new ilDateTimeInputGUI($this->lng->txt('dcl_limit_end'), 'limit_end');
292 $sitem2->setShowTime(true);
293 $item->setInfo($this->lng->txt("dcl_limited_desc"));
294 $item->addSubItem($sitem1);
295 $item->addSubItem($sitem2);
296 $this->form->addItem($item);
297
298 if ($a_mode == "edit") {
299 $this->form->addCommandButton('update', $this->lng->txt('dcl_table_' . $a_mode));
300 } else {
301 $this->form->addCommandButton('save', $this->lng->txt('dcl_table_' . $a_mode));
302 }
303
304 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
305 $this->form->setFormAction($this->ctrl->getFormAction($this, $a_mode));
306 if ($a_mode == "edit") {
307 $this->form->setTitle($this->lng->txt('dcl_edit_table'));
308 } else {
309 $this->form->setTitle($this->lng->txt('dcl_new_table'));
310 }
311 }
312
316 public function doTableSwitch()
317 {
318 $this->ctrl->setParameter($this, "table_id", $_POST['table_id']);
319 $this->ctrl->redirect($this, "edit");
320 }
321
327 public function save($a_mode = "create")
328 {
329 global $DIC;
330 $ilTabs = $DIC['ilTabs'];
331
332 if (!ilObjDataCollectionAccess::checkActionForObjId('write', $this->obj_id)) {
333 $this->accessDenied();
334 return;
335 }
336
337 $ilTabs->activateTab("id_fields");
338 $this->initForm($a_mode);
339
340 if ($this->checkInput($a_mode)) {
341 if ($a_mode != "update") {
342 $this->table = ilDclCache::getTableCache();
343 } elseif ($this->table_id) {
344 $this->table = ilDclCache::getTableCache($this->table_id);
345 } else {
346 $this->ctrl->redirectByClass("ildclfieldeditgui", "listFields");
347 }
348
349 $this->table->setTitle($this->form->getInput("title"));
350 $this->table->setObjId($this->obj_id);
351 $this->table->setSaveConfirmation((bool) $this->form->getInput('save_confirmation'));
352 $this->table->setAddPerm((bool) $this->form->getInput("add_perm"));
353 $this->table->setEditPerm((bool) $this->form->getInput("edit_perm"));
354 if ($this->table->getEditPerm()) {
355 $edit_by_owner = ($this->form->getInput('edit_perm_mode') == 'own');
356 $this->table->setEditByOwner($edit_by_owner);
357 }
358 $this->table->setDeletePerm((bool) $this->form->getInput("delete_perm"));
359 if ($this->table->getDeletePerm()) {
360 $delete_by_owner = ($this->form->getInput('delete_perm_mode') == 'own');
361 $this->table->setDeleteByOwner($delete_by_owner);
362 }
363 $this->table->setViewOwnRecordsPerm($this->form->getInput('view_own_records_perm'));
364 $this->table->setExportEnabled($this->form->getInput("export_enabled"));
365 $this->table->setImportEnabled($this->form->getInput("import_enabled"));
366 $this->table->setDefaultSortField($this->form->getInput("default_sort_field"));
367 $this->table->setDefaultSortFieldOrder($this->form->getInput("default_sort_field_order"));
368 $this->table->setLimited($this->form->getInput("limited"));
369 $this->table->setDescription($this->form->getInput('description'));
370 $limit_start = $this->form->getInput("limit_start");
371 $limit_end = $this->form->getInput("limit_end");
372 $this->table->setLimitStart($limit_start);
373 $this->table->setLimitEnd($limit_end);
374 if ($a_mode == "update") {
375 $this->table->doUpdate();
376 ilUtil::sendSuccess($this->lng->txt("dcl_msg_table_edited"), true);
377 $this->ctrl->redirectByClass("ildcltableeditgui", "edit");
378 } else {
379 $this->table->doCreate();
380 ilUtil::sendSuccess($this->lng->txt("dcl_msg_table_created"), true);
381 $this->ctrl->setParameterByClass("ildclfieldlistgui", "table_id", $this->table->getId());
382 $this->ctrl->redirectByClass("ildclfieldlistgui", "listFields");
383 }
384 } else {
385 $this->form->setValuesByPost();
386 $this->tpl->setContent($this->form->getHTML());
387 }
388 }
389
390
398 protected function checkInput($a_mode)
399 {
400 $return = $this->form->checkInput();
401
402 // Title of table must be unique in one DC
403 if ($a_mode == 'create') {
404 if ($title = $this->form->getInput('title')) {
405 if (ilObjDataCollection::_hasTableByTitle($title, $this->obj_id)) {
406 $inputObj = $this->form->getItemByPostVar('title');
407 $inputObj->setAlert($this->lng->txt("dcl_table_title_unique"));
408 $return = false;
409 }
410 }
411 }
412
413 if (!$return) {
414 ilUtil::sendFailure($this->lng->txt("form_input_not_valid"));
415 }
416
417 return $return;
418 }
419
420
421 /*
422 * accessDenied
423 */
424 public function accessDenied()
425 {
426 $this->tpl->setContent("Access denied.");
427 }
428
429
433 public function confirmDelete()
434 {
435 include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
436 $conf = new ilConfirmationGUI();
437 $conf->setFormAction($this->ctrl->getFormAction($this));
438 $conf->setHeaderText($this->lng->txt('dcl_confirm_delete_table'));
439
440 $conf->addItem('table', (int) $this->table->getId(), $this->table->getTitle());
441
442 $conf->setConfirm($this->lng->txt('delete'), 'delete');
443 $conf->setCancel($this->lng->txt('cancel'), 'cancelDelete');
444
445 $this->tpl->setContent($conf->getHTML());
446 }
447
448
452 public function cancelDelete()
453 {
454 $this->ctrl->redirectByClass("ilDclTableListGUI", "listTables");
455 }
456
457 /*
458 * delete
459 */
460 public function delete()
461 {
462 if (count($this->table->getCollectionObject()->getTables()) < 2) {
463 ilUtil::sendFailure($this->lng->txt("dcl_cant_delete_last_table"), true); //TODO change lng var
464 $this->table->doDelete(true);
465 } else {
466 $this->table->doDelete(false);
467 }
468
469 $this->ctrl->redirectByClass("ildcltablelistgui", "listtables");
470 }
471
472
476 protected function checkAccess()
477 {
478 $ref_id = $this->parent_object->getDataCollectionObject()->getRefId();
479 return $this->table_id ? ilObjDataCollectionAccess::hasAccessToEditTable($ref_id, $this->table_id) : ilObjDataCollectionAccess::hasWriteAccess($ref_id);
480 }
481
482
488 protected function createTableSwitcher()
489 {
490 // Show tables
491 $tables = $this->parent_object->getDataCollectionObject()->getTables();
492
493 foreach ($tables as $table) {
494 $options[$table->getId()] = $table->getTitle();
495 }
496 include_once './Services/Form/classes/class.ilSelectInputGUI.php';
497 $table_selection = new ilSelectInputGUI('', 'table_id');
498 $table_selection->setOptions($options);
499 $table_selection->setValue($this->table->getId());
500
501 $this->toolbar->setFormAction($this->ctrl->getFormActionByClass("ilDclTableEditGUI", "doTableSwitch"));
502 $this->toolbar->addText($this->lng->txt("dcl_select"));
503 $this->toolbar->addInputItem($table_selection);
504 $button = ilSubmitButton::getInstance();
505 $button->setCommand("doTableSwitch");
506 $button->setCaption('change');
507 $this->toolbar->addButtonInstance($button);
508
509 return $options;
510 }
511}
$section
Definition: Utf8Test.php:83
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
$_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.
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 sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $ilCtrl
Definition: ilias.php:18
global $DIC
Definition: saml.php:7