ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  $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 
313 
317  public function doTableSwitch()
318  {
319  $this->ctrl->setParameter($this, "table_id", $_POST['table_id']);
320  $this->ctrl->redirect($this, "edit");
321  }
322 
323 
329  public function save($a_mode = "create")
330  {
331  global $DIC;
332  $ilTabs = $DIC['ilTabs'];
333 
334  if (!ilObjDataCollectionAccess::checkActionForObjId('write', $this->obj_id)) {
335  $this->accessDenied();
336 
337  return;
338  }
339 
340  $ilTabs->activateTab("id_fields");
341  $this->initForm($a_mode);
342 
343  if ($this->checkInput($a_mode)) {
344  if ($a_mode != "update") {
345  $this->table = ilDclCache::getTableCache();
346  } elseif ($this->table_id) {
347  $this->table = ilDclCache::getTableCache($this->table_id);
348  } else {
349  $this->ctrl->redirectByClass("ildclfieldeditgui", "listFields");
350  }
351 
352  $this->table->setTitle($this->form->getInput("title"));
353  $this->table->setObjId($this->obj_id);
354  $this->table->setSaveConfirmation((bool) $this->form->getInput('save_confirmation'));
355  $this->table->setAddPerm((bool) $this->form->getInput("add_perm"));
356  $this->table->setEditPerm((bool) $this->form->getInput("edit_perm"));
357  if ($this->table->getEditPerm()) {
358  $edit_by_owner = ($this->form->getInput('edit_perm_mode') == 'own');
359  $this->table->setEditByOwner($edit_by_owner);
360  }
361  $this->table->setDeletePerm((bool) $this->form->getInput("delete_perm"));
362  if ($this->table->getDeletePerm()) {
363  $delete_by_owner = ($this->form->getInput('delete_perm_mode') == 'own');
364  $this->table->setDeleteByOwner($delete_by_owner);
365  }
366  $this->table->setViewOwnRecordsPerm($this->form->getInput('view_own_records_perm'));
367  $this->table->setExportEnabled($this->form->getInput("export_enabled"));
368  $this->table->setImportEnabled($this->form->getInput("import_enabled"));
369  $this->table->setDefaultSortField($this->form->getInput("default_sort_field"));
370  $this->table->setDefaultSortFieldOrder($this->form->getInput("default_sort_field_order"));
371  $this->table->setLimited($this->form->getInput("limited"));
372  $this->table->setDescription($this->form->getInput('description'));
373  $limit_start = $this->form->getInput("limit_start");
374  $limit_end = $this->form->getInput("limit_end");
375  $this->table->setLimitStart($limit_start);
376  $this->table->setLimitEnd($limit_end);
377  if ($a_mode == "update") {
378  $this->table->doUpdate();
379  ilUtil::sendSuccess($this->lng->txt("dcl_msg_table_edited"), true);
380  $this->ctrl->redirectByClass("ildcltableeditgui", "edit");
381  } else {
382  $this->table->doCreate();
383  ilUtil::sendSuccess($this->lng->txt("dcl_msg_table_created"), true);
384  $this->ctrl->setParameterByClass("ildclfieldlistgui", "table_id", $this->table->getId());
385  $this->ctrl->redirectByClass("ildclfieldlistgui", "listFields");
386  }
387  } else {
388  $this->form->setValuesByPost();
389  $this->tpl->setContent($this->form->getHTML());
390  }
391  }
392 
393 
401  protected function checkInput($a_mode)
402  {
403  $return = $this->form->checkInput();
404 
405  // Title of table must be unique in one DC
406  if ($a_mode == 'create') {
407  if ($title = $this->form->getInput('title')) {
408  if (ilObjDataCollection::_hasTableByTitle($title, $this->obj_id)) {
409  $inputObj = $this->form->getItemByPostVar('title');
410  $inputObj->setAlert($this->lng->txt("dcl_table_title_unique"));
411  $return = false;
412  }
413  }
414  }
415 
416  if (!$return) {
417  ilUtil::sendFailure($this->lng->txt("form_input_not_valid"));
418  }
419 
420  return $return;
421  }
422 
423 
424  /*
425  * accessDenied
426  */
427  public function accessDenied()
428  {
429  $this->tpl->setContent("Access denied.");
430  }
431 
432 
436  public function confirmDelete()
437  {
438  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
439  $conf = new ilConfirmationGUI();
440  $conf->setFormAction($this->ctrl->getFormAction($this));
441  $conf->setHeaderText($this->lng->txt('dcl_confirm_delete_table'));
442 
443  $conf->addItem('table', (int) $this->table->getId(), $this->table->getTitle());
444 
445  $conf->setConfirm($this->lng->txt('delete'), 'delete');
446  $conf->setCancel($this->lng->txt('cancel'), 'cancelDelete');
447 
448  $this->tpl->setContent($conf->getHTML());
449  }
450 
451 
455  public function cancelDelete()
456  {
457  $this->ctrl->redirectByClass("ilDclTableListGUI", "listTables");
458  }
459 
460 
461  /*
462  * delete
463  */
464  public function delete()
465  {
466  if (count($this->table->getCollectionObject()->getTables()) < 2) {
467  ilUtil::sendFailure($this->lng->txt("dcl_cant_delete_last_table"), true); //TODO change lng var
468  $this->table->doDelete(true);
469  } else {
470  $this->table->doDelete(false);
471  }
472 
473  $this->ctrl->redirectByClass("ildcltablelistgui", "listtables");
474  }
475 
476 
480  protected function checkAccess()
481  {
482  $ref_id = $this->parent_object->getDataCollectionObject()->getRefId();
483  return $this->table_id ? ilObjDataCollectionAccess::hasAccessToEditTable($ref_id, $this->table_id) : ilObjDataCollectionAccess::hasWriteAccess($ref_id);
484  }
485 
486 
492  protected function createTableSwitcher()
493  {
494  // Show tables
495  $tables = $this->parent_object->getDataCollectionObject()->getTables();
496 
497  foreach ($tables as $table) {
498  $options[$table->getId()] = $table->getTitle();
499  }
500  include_once './Services/Form/classes/class.ilSelectInputGUI.php';
501  $table_selection = new ilSelectInputGUI('', 'table_id');
502  $table_selection->setOptions($options);
503  $table_selection->setValue($this->table->getId());
504 
505  $this->toolbar->setFormAction($this->ctrl->getFormActionByClass("ilDclTableEditGUI", "doTableSwitch"));
506  $this->toolbar->addText($this->lng->txt("dcl_select"));
507  $this->toolbar->addInputItem($table_selection);
508  $button = ilSubmitButton::getInstance();
509  $button->setCommand("doTableSwitch");
510  $button->setCaption('change');
511  $this->toolbar->addButtonInstance($button);
512 
513  return $options;
514  }
515 }
initForm($a_mode="create")
initEditCustomForm
This class represents an option in a radio group.
This class represents a selection list property in a property form.
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
create()
create table add form
This class represents a section header in a property form.
setUseRte($a_usert, $version='')
Set Use Rich Text Editing.
getStandardValues()
getStandardValues
checkInput($a_mode)
Custom checks for the form input.
This class represents a checkbox property in a property form.
static hasAccessToEditTable($ref_id, $table_id)
Class ilDclTableListGUI.
static getTableCache($table_id=0)
This class represents a date/time property in a property form.
global $ilCtrl
Definition: ilias.php:18
setInfo($a_info)
Set Information Text.
$section
Definition: Utf8Test.php:83
This class represents a property in a property form.
executeCommand()
execute command
save($a_mode="create")
save
$values
This class represents a text property in a property form.
static _hasTableByTitle($title, $obj_id)
Checks if a DataCollection has a table with a given title.
__construct(ilDclTableListGUI $a_parent_obj)
Constructor.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
This class represents a custom property in a property form.
This class represents a text area property in a property form.
edit()
create field edit form
static checkActionForObjId($action, $obj_id)
$_POST["username"]
setRequired($a_required)
Set Required.
setShowTime($a_showtime)
Set Show Time Information.
Class ilDclBaseFieldModel.
Confirmation screen class.