ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
5require_once("./Modules/DataCollection/classes/Table/class.ilDclTable.php");
6
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 global $DIC;
56 $ilCtrl = $DIC['ilCtrl'];
57 $lng = $DIC['lng'];
58 $tpl = $DIC['tpl'];
59 $toolbar = $DIC['ilToolbar'];
60 $locator = $DIC['ilLocator'];
61
62 $this->ctrl = $ilCtrl;
63 $this->lng = $lng;
64 $this->tpl = $tpl;
65 $this->toolbar = $toolbar;
66 $this->parent_object = $a_parent_obj;
67 $this->obj_id = $a_parent_obj->obj_id;
68 $this->table_id = $_GET['table_id'];
69 $this->table = ilDclCache::getTableCache($this->table_id);
70
71 $this->ctrl->saveParameter($this, 'table_id');
72 $locator->addItem($this->table->getTitle(), $this->ctrl->getLinkTarget($this, 'edit'));
73 $this->tpl->setLocator();
74
75 if (!$this->checkAccess()) {
76 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
77 $this->ctrl->redirectByClass('ildclrecordlistgui', 'listRecords');
78 }
79 }
80
81
85 public function executeCommand() {
86 $cmd = $this->ctrl->getCmd();
87
88 switch ($cmd) {
89 case 'update':
90 $this->save("update");
91 break;
92 default:
93 $this->$cmd();
94 break;
95 }
96
97 return true;
98 }
99
100
104 public function create() {
105 $this->initForm();
106 $this->getStandardValues();
107 $this->tpl->setContent($this->form->getHTML());
108 }
109
110
114 public function edit() {
115 if (!$this->table_id) {
116 $this->ctrl->redirectByClass("ildclfieldeditgui", "listFields");
117
118 return;
119 } else {
120 $this->table = ilDclCache::getTableCache($this->table_id);
121 }
122 $this->initForm("edit");
123 $this->getValues();
124 $this->tpl->setContent($this->form->getHTML());
125 }
126
127
131 public function getValues() {
132 $values = array(
133 'title' => $this->table->getTitle(),
134 'add_perm' => (int) $this->table->getAddPerm(),
135 'edit_perm' => (int) $this->table->getEditPerm(),
136 'edit_perm_mode' => $this->table->getEditByOwner() ? 'own' : 'all',
137 'delete_perm' => (int) $this->table->getDeletePerm(),
138 'delete_perm_mode' => $this->table->getDeleteByOwner() ? 'own' : 'all',
139 'export_enabled' => $this->table->getExportEnabled(),
140 'import_enabled' => $this->table->getImportEnabled(),
141 'limited' => $this->table->getLimited(),
142 'limit_start' => substr($this->table->getLimitStart(), 0, 10) . " " . substr($this->table->getLimitStart(), - 8),
143 'limit_end' => substr($this->table->getLimitEnd(), 0, 10) . " " . substr($this->table->getLimitEnd(), - 8),
144 'default_sort_field' => $this->table->getDefaultSortField(),
145 'default_sort_field_order' => $this->table->getDefaultSortFieldOrder(),
146 'description' => $this->table->getDescription(),
147 'view_own_records_perm' => $this->table->getViewOwnRecordsPerm(),
148 'save_confirmation' => $this->table->getSaveConfirmation(),
149 );
150 if (!$this->table->getLimitStart()) {
151 $values['limit_start'] = NULL;
152 }
153 if (!$this->table->getLimitEnd()) {
154 $values['limit_end'] = NULL;
155 }
156 $this->form->setValuesByArray($values);
157 }
158
159
163 public function getStandardValues() {
164 $values = array(
165 'title' => "",
166 'add_perm' => 1,
167 'edit_perm' => 1,
168 'edit_perm_mode' => 'own',
169 'delete_perm_mode' => 'own',
170 'delete_perm' => 1,
171 'edit_by_owner' => 1,
172 'export_enabled' => 0,
173 'import_enabled' => 0,
174 'limited' => 0,
175 'limit_start' => NULL,
176 'limit_end' => NULL
177 );
178 $this->form->setValuesByArray($values);
179 }
180
181
182 /*
183 * cancel
184 */
185 public function cancel() {
186 $this->ctrl->redirectByClass("ilDclTableListGUI", "listTables");
187 }
188
189
195 public function initForm($a_mode = "create") {
196 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
197 $this->form = new ilPropertyFormGUI();
198
199 $item = new ilTextInputGUI($this->lng->txt('title'), 'title');
200 $item->setRequired(true);
201 $this->form->addItem($item);
202
203 // 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
204 if ($a_mode != 'create') {
205 $this->createTableSwitcher();
206
207 $item = new ilSelectInputGUI($this->lng->txt('dcl_default_sort_field'), 'default_sort_field');
208 $item->setInfo($this->lng->txt('dcl_default_sort_field_desc'));
209 $fields = $this->table->getFields();
210 $options = array( 0 => $this->lng->txt('dcl_please_select') );
211 foreach ($fields as $field) {
212 if ($field->getId() == 'comments') {
213 continue;
214 }
215 $options[$field->getId()] = $field->getTitle();
216 }
217 $item->setOptions($options);
218 $this->form->addItem($item);
219
220 $item = new ilSelectInputGUI($this->lng->txt('dcl_default_sort_field_order'), 'default_sort_field_order');
221 $options = array( 'asc' => $this->lng->txt('dcl_asc'), 'desc' => $this->lng->txt('dcl_desc') );
222 $item->setOptions($options);
223 $this->form->addItem($item);
224 }
225
226 $item = new ilTextAreaInputGUI($this->lng->txt('additional_info'), 'description');
227 $item->setUseRte(true);
228 $item->setInfo($this->lng->txt('dcl_additional_info_desc'));
229 // $item->setRTESupport($this->table->getId(), 'dcl', 'table_settings');
230 $item->setRteTagSet('mini');
231 $this->form->addItem($item);
232
234 $section->setTitle($this->lng->txt('dcl_permissions_form'));
235 $this->form->addItem($section);
236
237 $item = new ilCustomInputGUI();
238 $item->setHtml($this->lng->txt('dcl_table_info'));
239 $item->setTitle($this->lng->txt('dcl_table_info_title'));
240 $this->form->addItem($item);
241
242 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_add_perm'), 'add_perm');
243 $item->setInfo($this->lng->txt("dcl_add_perm_desc"));
244 $this->form->addItem($item);
245
246 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_save_confirmation'), 'save_confirmation');
247 $item->setInfo($this->lng->txt('dcl_save_confirmation_desc'));
248 $this->form->addItem($item);
249
250 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_edit_perm'), 'edit_perm');
251 // $item->setInfo($this->lng->txt("dcl_edit_perm_info"));
252 $this->form->addItem($item);
253
254 $radios = new ilRadioGroupInputGUI('', 'edit_perm_mode');
255 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_all_entries'), 'all'));
256 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_own_entries'), 'own'));
257 $item->addSubItem($radios);
258
259 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_delete_perm'), 'delete_perm');
260 // $item->setInfo($this->lng->txt("dcl_delete_perm_info"));
261 $this->form->addItem($item);
262
263 $radios = new ilRadioGroupInputGUI('', 'delete_perm_mode');
264 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_all_entries'), 'all'));
265 $radios->addOption(new ilRadioOption($this->lng->txt('dcl_own_entries'), 'own'));
266 $item->addSubItem($radios);
267
268 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_view_own_records_perm'), 'view_own_records_perm');
269 // $item->setInfo($this->lng->txt("dcl_edit_by_owner_info"));
270 $this->form->addItem($item);
271
272 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_export_enabled'), 'export_enabled');
273 $item->setInfo($this->lng->txt('dcl_export_enabled_desc'));
274 $this->form->addItem($item);
275
276 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_import_enabled'), 'import_enabled');
277 $item->setInfo($this->lng->txt('dcl_import_enabled_desc'));
278 $this->form->addItem($item);
279
280 $item = new ilCheckboxInputGUI($this->lng->txt('dcl_limited'), 'limited');
281 $sitem1 = new ilDateTimeInputGUI($this->lng->txt('dcl_limit_start'), 'limit_start');
282 $sitem1->setShowTime(true);
283 $sitem2 = new ilDateTimeInputGUI($this->lng->txt('dcl_limit_end'), 'limit_end');
284 $sitem2->setShowTime(true);
285 $item->setInfo($this->lng->txt("dcl_limited_desc"));
286 $item->addSubItem($sitem1);
287 $item->addSubItem($sitem2);
288 $this->form->addItem($item);
289
290 if ($a_mode == "edit") {
291 $this->form->addCommandButton('update', $this->lng->txt('dcl_table_' . $a_mode));
292 } else {
293 $this->form->addCommandButton('save', $this->lng->txt('dcl_table_' . $a_mode));
294 }
295
296 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
297 $this->form->setFormAction($this->ctrl->getFormAction($this, $a_mode));
298 if ($a_mode == "edit") {
299 $this->form->setTitle($this->lng->txt('dcl_edit_table'));
300 } else {
301 $this->form->setTitle($this->lng->txt('dcl_new_table'));
302 }
303 }
304
308 public function doTableSwitch()
309 {
310 $this->ctrl->setParameter($this, "table_id", $_POST['table_id']);
311 $this->ctrl->redirect($this, "edit");
312 }
313
319 public function save($a_mode = "create") {
320 global $DIC;
321 $ilTabs = $DIC['ilTabs'];
322
323 if (!ilObjDataCollectionAccess::checkActionForObjId('write', $this->obj_id)) {
324 $this->accessDenied();
325 return;
326 }
327
328 $ilTabs->activateTab("id_fields");
329 $this->initForm($a_mode);
330
331 if ($this->checkInput($a_mode)) {
332 if ($a_mode != "update") {
333 $this->table = ilDclCache::getTableCache();
334 } elseif ($this->table_id) {
335 $this->table = ilDclCache::getTableCache($this->table_id);
336 } else {
337 $this->ctrl->redirectByClass("ildclfieldeditgui", "listFields");
338 }
339
340 $this->table->setTitle($this->form->getInput("title"));
341 $this->table->setObjId($this->obj_id);
342 $this->table->setSaveConfirmation((bool)$this->form->getInput('save_confirmation'));
343 $this->table->setAddPerm((bool)$this->form->getInput("add_perm"));
344 $this->table->setEditPerm((bool)$this->form->getInput("edit_perm"));
345 if ($this->table->getEditPerm()) {
346 $edit_by_owner = ($this->form->getInput('edit_perm_mode') == 'own');
347 $this->table->setEditByOwner($edit_by_owner);
348 }
349 $this->table->setDeletePerm((bool)$this->form->getInput("delete_perm"));
350 if ($this->table->getDeletePerm()) {
351 $delete_by_owner = ($this->form->getInput('delete_perm_mode') == 'own');
352 $this->table->setDeleteByOwner($delete_by_owner);
353 }
354 $this->table->setViewOwnRecordsPerm($this->form->getInput('view_own_records_perm'));
355 $this->table->setExportEnabled($this->form->getInput("export_enabled"));
356 $this->table->setImportEnabled($this->form->getInput("import_enabled"));
357 $this->table->setDefaultSortField($this->form->getInput("default_sort_field"));
358 $this->table->setDefaultSortFieldOrder($this->form->getInput("default_sort_field_order"));
359 $this->table->setLimited($this->form->getInput("limited"));
360 $this->table->setDescription($this->form->getInput('description'));
361 $limit_start = $this->form->getInput("limit_start");
362 $limit_end = $this->form->getInput("limit_end");
363 $this->table->setLimitStart($limit_start);
364 $this->table->setLimitEnd($limit_end);
365 if ($a_mode == "update") {
366 $this->table->doUpdate();
367 ilUtil::sendSuccess($this->lng->txt("dcl_msg_table_edited"), true);
368 $this->ctrl->redirectByClass("ildcltableeditgui", "edit");
369 } else {
370 $this->table->doCreate();
371 ilUtil::sendSuccess($this->lng->txt("dcl_msg_table_created"), true);
372 $this->ctrl->setParameterByClass("ildclfieldlistgui", "table_id", $this->table->getId());
373 $this->ctrl->redirectByClass("ildclfieldlistgui", "listFields");
374 }
375 } else {
376 $this->form->setValuesByPost();
377 $this->tpl->setContent($this->form->getHTML());
378 }
379 }
380
381
389 protected function checkInput($a_mode) {
390 $return = $this->form->checkInput();
391
392 // Title of table must be unique in one DC
393 if ($a_mode == 'create') {
394 if ($title = $this->form->getInput('title')) {
395 if (ilObjDataCollection::_hasTableByTitle($title, $this->obj_id)) {
396 $inputObj = $this->form->getItemByPostVar('title');
397 $inputObj->setAlert($this->lng->txt("dcl_table_title_unique"));
398 $return = false;
399 }
400 }
401 }
402
403 if (! $return) {
404 ilUtil::sendFailure($this->lng->txt("form_input_not_valid"));
405 }
406
407 return $return;
408 }
409
410
411 /*
412 * accessDenied
413 */
414 public function accessDenied() {
415 $this->tpl->setContent("Access denied.");
416 }
417
418
422 public function confirmDelete() {
423 include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
424 $conf = new ilConfirmationGUI();
425 $conf->setFormAction($this->ctrl->getFormAction($this));
426 $conf->setHeaderText($this->lng->txt('dcl_confirm_delete_table'));
427
428 $conf->addItem('table', (int)$this->table->getId(), $this->table->getTitle());
429
430 $conf->setConfirm($this->lng->txt('delete'), 'delete');
431 $conf->setCancel($this->lng->txt('cancel'), 'cancelDelete');
432
433 $this->tpl->setContent($conf->getHTML());
434 }
435
436
440 public function cancelDelete() {
441 $this->ctrl->redirectByClass("ilDclTableListGUI", "listTables");
442 }
443
444 /*
445 * delete
446 */
447 public function delete() {
448 if (count($this->table->getCollectionObject()->getTables()) < 2) {
449 ilUtil::sendFailure($this->lng->txt("dcl_cant_delete_last_table"), true); //TODO change lng var
450 $this->table->doDelete(true);
451 } else {
452 $this->table->doDelete(false);
453 }
454
455 $this->ctrl->redirectByClass("ildcltablelistgui", "listtables");
456 }
457
458
462 protected function checkAccess() {
463 $ref_id = $this->parent_object->getDataCollectionObject()->getRefId();
465 }
466
467
473 protected function createTableSwitcher() {
474 // Show tables
475 $tables = $this->parent_object->getDataCollectionObject()->getTables();
476
477 foreach ($tables as $table) {
478 $options[$table->getId()] = $table->getTitle();
479 }
480 include_once './Services/Form/classes/class.ilSelectInputGUI.php';
481 $table_selection = new ilSelectInputGUI('', 'table_id');
482 $table_selection->setOptions($options);
483 $table_selection->setValue($this->table->getId());
484
485 $this->toolbar->setFormAction($this->ctrl->getFormActionByClass("ilDclTableEditGUI", "doTableSwitch"));
486 $this->toolbar->addText($this->lng->txt("dcl_select"));
487 $this->toolbar->addInputItem($table_selection);
488 $button = ilSubmitButton::getInstance();
489 $button->setCommand("doTableSwitch");
490 $button->setCaption('change');
491 $this->toolbar->addButtonInstance($button);
492
493 return $options;
494 }
495}
$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.
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
$cmd
Definition: sahs_server.php:35
$ref_id
Definition: sahs_server.php:39
if(!is_array($argv)) $options
global $DIC