ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilDataCollectionFieldListGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once ("./Modules/DataCollection/classes/class.ilDataCollectionField.php");
5 require_once ("./Modules/DataCollection/classes/class.ilDataCollectionTable.php");
6 include_once("class.ilDataCollectionDatatype.php");
7 require_once "class.ilDataCollectionCache.php";
8 
9 
23 {
30  public function __construct(ilObjDataCollectionGUI $a_parent_obj, $table_id)
31  {
32  global $ilCtrl, $lng;
33 
34  $this->main_table_id = $a_parent_obj->object->getMainTableId();
35  $this->table_id = $table_id;
36  $this->parent_obj = $a_parent_obj;
37  $this->obj_id = $a_parent_obj->obj_id;
38  if ( ! $this->checkAccess()) {
39  ilUtil::sendFailure($lng->txt('permission_denied'), true);
40  $ilCtrl->redirectByClass('ildatacollectionrecordlistgui', 'listRecords');
41  }
42  }
43 
44 
48  public function executeCommand()
49  {
50  global $tpl, $ilCtrl;
51 
52  $cmd = $ilCtrl->getCmd();
53 
54  switch($cmd)
55  {
56  default:
57  $this->$cmd();
58  break;
59  }
60  }
61 
62  /*
63  * save
64  */
65  public function save()
66  {
67  global $lng;
68  $table = ilDataCollectionCache::getTableCache($_GET['table_id']);
69  $fields = &$table->getFields();
70 
71  foreach($fields as &$field)
72  {
73  $field->setVisible($_POST['visible'][$field->getId()] == "on");
74  $field->setEditable($_POST['editable'][$field->getId()] == "on");
75  $field->setFilterable($_POST['filterable'][$field->getId()] == "on");
76  $field->setLocked($_POST['locked'][$field->getId()] == "on");
77  $field->setOrder($_POST['order'][$field->getId()]);
78  $field->doUpdate();
79  }
80  $table->buildOrderFields();
81  ilUtil::sendSuccess($lng->txt("dcl_table_settings_saved"));
82  $this->listFields();
83  }
84 
88  public function listFields()
89  {
90  global $tpl, $lng, $ilCtrl, $ilToolbar;
91 
92  // Show tables
93  require_once("./Modules/DataCollection/classes/class.ilDataCollectionTable.php");
94  $tables = $this->parent_obj->object->getTables();
95 
96  foreach($tables as $table)
97  {
98  $options[$table->getId()] = $table->getTitle();
99  }
100  include_once './Services/Form/classes/class.ilSelectInputGUI.php';
101  $table_selection = new ilSelectInputGUI('', 'table_id');
102  $table_selection->setOptions($options);
103  $table_selection->setValue($this->table_id);
104 
105  $ilToolbar->setFormAction($ilCtrl->getFormActionByClass("ilDataCollectionFieldListGUI", "doTableSwitch"));
106  $ilToolbar->addText($lng->txt("dcl_table"));
107  $ilToolbar->addInputItem($table_selection);
108  $ilToolbar->addFormButton($lng->txt('change'),'doTableSwitch');
109  $ilToolbar->addSeparator();
110  $ilToolbar->addButton($lng->txt("dcl_add_new_table"), $ilCtrl->getLinkTargetByClass("ildatacollectiontableeditgui", "create"));
111  $ilToolbar->addSeparator();
112  $ilCtrl->setParameterByClass("ildatacollectiontableeditgui", "table_id", $this->table_id);
113  $ilToolbar->addButton($lng->txt("dcl_table_settings"), $ilCtrl->getLinkTargetByClass("ildatacollectiontableeditgui", "edit"));
114  $ilToolbar->addButton($lng->txt("dcl_delete_table"), $ilCtrl->getLinkTargetByClass("ildatacollectiontableeditgui", "confirmDelete"));
115  $ilToolbar->addButton($lng->txt("dcl_add_new_field"), $ilCtrl->getLinkTargetByClass("ildatacollectionfieldeditgui", "create"));
116 
117  // requested not to implement this way...
118 // $tpl->addJavaScript("Modules/DataCollection/js/fastTableSwitcher.js");
119 
120  require_once('./Modules/DataCollection/classes/class.ilDataCollectionFieldListTableGUI.php');
121  $list = new ilDataCollectionFieldListTableGUI($this, $ilCtrl->getCmd(), $this->table_id);
122 
123  $tpl->setContent($list->getHTML());
124 
125  }
126 
127  /*
128  * doTableSwitch
129  */
130  public function doTableSwitch()
131  {
132  global $ilCtrl;
133 
134  $ilCtrl->setParameterByClass("ilObjDataCollectionGUI", "table_id", $_POST['table_id']);
135  $ilCtrl->redirectByClass("ilDataCollectionFieldListGUI", "listFields");
136  }
137 
141  protected function checkAccess()
142  {
143  $ref_id = $this->parent_obj->getDataCollectionObject()->getRefId();
145  }
146 
147 }
148 
149 ?>