ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilDclFieldListGUI.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/Fields/Base/class.ilDclBaseFieldModel.php");
5 require_once ("./Modules/DataCollection/classes/Table/class.ilDclTable.php");
6 require_once("./Modules/DataCollection/classes/Fields/Base/class.ilDclDatatype.php");
7 require_once ("./Modules/DataCollection/classes/Helpers/class.ilDclCache.php");
8 require_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
9 require_once('./Modules/DataCollection/classes/Fields/class.ilDclFieldListTableGUI.php');
10 
24 {
25 
29  protected $ctrl;
30 
31 
35  protected $lng;
36 
40  protected $toolbar;
41 
45  protected $tpl;
46 
50  protected $tabs;
51 
58  public function __construct(ilDclTableListGUI $a_parent_obj)
59  {
60  global $DIC;
61  $ilCtrl = $DIC['ilCtrl'];
62  $lng = $DIC['lng'];
63  $ilToolbar = $DIC['ilToolbar'];
64  $tpl = $DIC['tpl'];
65  $ilTabs = $DIC['ilTabs'];
66  $locator = $DIC['ilLocator'];
67 
68  $table_id = $_GET['table_id'];
69 
70  $this->table_id = $table_id;
71  $this->parent_obj = $a_parent_obj;
72  $this->obj_id = $a_parent_obj->obj_id;
73  $this->ctrl = $ilCtrl;
74  $this->lng = $lng;
75  $this->tpl = $tpl;
76  $this->tabs = $ilTabs;
77  $this->toolbar = $ilToolbar;
78 
79  $this->ctrl->saveParameter('ilDclTableEditGUI', 'table_id');
80  $locator->addItem(ilDclCache::getTableCache($this->table_id)->getTitle(), $this->ctrl->getLinkTargetByClass('ilDclTableEditGUI', 'edit'));
81  $this->tpl->setLocator();
82 
83  if ( ! $this->checkAccess()) {
84  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
85  $this->ctrl->redirectByClass('ildclrecordlistgui', 'listRecords');
86  }
87  }
88 
89 
93  public function executeCommand()
94  {
95  $cmd = $this->ctrl->getCmd('listFields');
96  switch($cmd) {
97  default:
98  $this->$cmd();
99  break;
100  }
101  }
102 
106  public function deleteFields()
107  {
108  $field_ids = isset($_POST['dcl_field_ids']) ? $_POST['dcl_field_ids'] : array();
109  $table = ilDclCache::getTableCache($this->table_id);
110  foreach ($field_ids as $field_id) {
111  $table->deleteField($field_id);
112  }
113  ilUtil::sendSuccess($this->lng->txt('dcl_msg_fields_deleted'), true);
114  $this->ctrl->redirect($this, 'listFields');
115  }
116 
120  public function confirmDeleteFields() {
121  $this->tabs->clearSubTabs();
122  $conf = new ilConfirmationGUI();
123  $conf->setFormAction($this->ctrl->getFormAction($this));
124  $conf->setHeaderText($this->lng->txt('dcl_confirm_delete_fields'));
125  $field_ids = isset($_POST['dcl_field_ids']) ? $_POST['dcl_field_ids'] : array();
126  foreach ($field_ids as $field_id) {
128  $field = ilDclCache::getFieldCache($field_id);
129  $conf->addItem('dcl_field_ids[]', $field_id, $field->getTitle());
130  }
131  $conf->setConfirm($this->lng->txt('delete'), 'deleteFields');
132  $conf->setCancel($this->lng->txt('cancel'), 'listFields');
133  $this->tpl->setContent($conf->getHTML());
134  }
135 
136  /*
137  * save
138  */
139  public function save()
140  {
141  $table = ilDclCache::getTableCache($_GET['table_id']);
142  $fields = $table->getFields();
143  $order = $_POST['order'];
144  asort($order);
145  $val = 10;
146  foreach (array_keys($order) as $field_id) {
147  $order[$field_id] = $val;
148  $val += 10;
149  }
150 
151 
152  foreach($fields as $field)
153  {
154  $field->setLocked($_POST['locked'][$field->getId()] == "on");
155  $field->setExportable($_POST['exportable'][$field->getId()] == "on");
156  $field->setOrder($order[$field->getId()]);
157  $field->doUpdate();
158  }
159 
160  $table->reloadFields();
161  ilUtil::sendSuccess($this->lng->txt("dcl_table_settings_saved"));
162  $this->listFields();
163  }
164 
168  public function listFields()
169  {
170  //add button
171  $add_new = ilLinkButton::getInstance();
172  $add_new->setPrimary(true);
173  $add_new->setCaption("dcl_add_new_field");
174  $add_new->setUrl($this->ctrl->getLinkTargetByClass('ildclfieldeditgui', 'create'));
175  $this->toolbar->addStickyItem($add_new);
176 
177  $this->toolbar->addSeparator();
178 
179  // Show tableswitcher
180  $tables = $this->parent_obj->getDataCollectionObject()->getTables();
181 
182  foreach($tables as $table)
183  {
184  $options[$table->getId()] = $table->getTitle();
185  }
186  include_once './Services/Form/classes/class.ilSelectInputGUI.php';
187  $table_selection = new ilSelectInputGUI('', 'table_id');
188  $table_selection->setOptions($options);
189  $table_selection->setValue($this->table_id);
190 
191  $this->toolbar->setFormAction($this->ctrl->getFormActionByClass("ilDclFieldListGUI", "doTableSwitch"));
192  $this->toolbar->addText($this->lng->txt("dcl_select"));
193  $this->toolbar->addInputItem($table_selection);
194  $this->toolbar->addFormButton($this->lng->txt('change'),'doTableSwitch');
195 
196  //table gui
197  $list = new ilDclFieldListTableGUI($this, $this->ctrl->getCmd(), $this->table_id);
198  $this->tpl->setContent($list->getHTML());
199  }
200 
201  /*
202  * doTableSwitch
203  */
204  public function doTableSwitch()
205  {
206  $this->ctrl->setParameterByClass("ilObjDataCollectionGUI", "table_id", $_POST['table_id']);
207  $this->ctrl->redirectByClass("ilDclFieldListGUI", "listFields");
208  }
209 
213  protected function checkAccess()
214  {
215  $ref_id = $this->getDataCollectionObject()->getRefId();
217  }
218 
219 
223  public function getDataCollectionObject() {
224  return $this->parent_obj->getDataCollectionObject();
225  }
226 
227 }
228 
229 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
This class represents a selection list property in a property form.
$_GET["client_id"]
static getFieldCache($field_id=0)
$cmd
Definition: sahs_server.php:35
static hasAccessToEditTable($ref_id, $table_id)
Class ilDclTableListGUI.
static getTableCache($table_id=0)
global $ilCtrl
Definition: ilias.php:18
if(!is_array($argv)) $options
deleteFields()
Delete multiple fields.
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
executeCommand()
execute command
Class ilDclFieldListTableGUI.
$ref_id
Definition: sahs_server.php:39
global $DIC
__construct(ilDclTableListGUI $a_parent_obj)
Constructor.
$_POST["username"]
Confirmation screen class.