ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
17 {
18 
22  protected $ctrl;
26  protected $lng;
30  protected $toolbar;
34  protected $tpl;
38  protected $tabs;
39 
40 
47  public function __construct(ilDclTableListGUI $a_parent_obj)
48  {
49  global $DIC;
50  $ilCtrl = $DIC['ilCtrl'];
51  $lng = $DIC['lng'];
52  $ilToolbar = $DIC['ilToolbar'];
53  $tpl = $DIC['tpl'];
54  $ilTabs = $DIC['ilTabs'];
55  $locator = $DIC['ilLocator'];
56 
57  $table_id = $_GET['table_id'];
58 
59  $this->table_id = $table_id;
60  $this->parent_obj = $a_parent_obj;
61  $this->obj_id = $a_parent_obj->obj_id;
62  $this->ctrl = $ilCtrl;
63  $this->lng = $lng;
64  $this->tpl = $tpl;
65  $this->tabs = $ilTabs;
66  $this->toolbar = $ilToolbar;
67 
68  $this->ctrl->saveParameter('ilDclTableEditGUI', 'table_id');
69  $locator->addItem(ilDclCache::getTableCache($this->table_id)->getTitle(), $this->ctrl->getLinkTargetByClass('ilDclTableEditGUI', 'edit'));
70  $this->tpl->setLocator();
71 
72  if (!$this->checkAccess()) {
73  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
74  $this->ctrl->redirectByClass('ildclrecordlistgui', 'listRecords');
75  }
76  }
77 
78 
82  public function executeCommand()
83  {
84  $cmd = $this->ctrl->getCmd('listFields');
85  switch ($cmd) {
86  default:
87  $this->$cmd();
88  break;
89  }
90  }
91 
92 
96  public function deleteFields()
97  {
98  $field_ids = isset($_POST['dcl_field_ids']) ? $_POST['dcl_field_ids'] : array();
99  $table = ilDclCache::getTableCache($this->table_id);
100  foreach ($field_ids as $field_id) {
101  $table->deleteField($field_id);
102  }
103  ilUtil::sendSuccess($this->lng->txt('dcl_msg_fields_deleted'), true);
104  $this->ctrl->redirect($this, 'listFields');
105  }
106 
107 
111  public function confirmDeleteFields()
112  {
113  $this->tabs->clearSubTabs();
114  $conf = new ilConfirmationGUI();
115  $conf->setFormAction($this->ctrl->getFormAction($this));
116  $conf->setHeaderText($this->lng->txt('dcl_confirm_delete_fields'));
117  $field_ids = isset($_POST['dcl_field_ids']) ? $_POST['dcl_field_ids'] : array();
118  foreach ($field_ids as $field_id) {
120  $field = ilDclCache::getFieldCache($field_id);
121  $conf->addItem('dcl_field_ids[]', $field_id, $field->getTitle());
122  }
123  $conf->setConfirm($this->lng->txt('delete'), 'deleteFields');
124  $conf->setCancel($this->lng->txt('cancel'), 'listFields');
125  $this->tpl->setContent($conf->getHTML());
126  }
127 
128 
129  /*
130  * save
131  */
132  public function save()
133  {
134  $table = ilDclCache::getTableCache($_GET['table_id']);
135  $fields = $table->getFields();
136  $order = $_POST['order'];
137  asort($order);
138  $val = 10;
139  foreach (array_keys($order) as $field_id) {
140  $order[$field_id] = $val;
141  $val += 10;
142  }
143 
144  foreach ($fields as $field) {
145  $field->setLocked($_POST['locked'][$field->getId()] == "on");
146  $field->setExportable($_POST['exportable'][$field->getId()] == "on");
147  $field->setOrder($order[$field->getId()]);
148  $field->doUpdate();
149  }
150 
151  $table->reloadFields();
152  ilUtil::sendSuccess($this->lng->txt("dcl_table_settings_saved"));
153  $this->listFields();
154  }
155 
156 
160  public function listFields()
161  {
162  //add button
163  $add_new = ilLinkButton::getInstance();
164  $add_new->setPrimary(true);
165  $add_new->setCaption("dcl_add_new_field");
166  $add_new->setUrl($this->ctrl->getLinkTargetByClass('ildclfieldeditgui', 'create'));
167  $this->toolbar->addStickyItem($add_new);
168 
169  $this->toolbar->addSeparator();
170 
171  // Show tableswitcher
172  $tables = $this->parent_obj->getDataCollectionObject()->getTables();
173 
174  foreach ($tables as $table) {
175  $options[$table->getId()] = $table->getTitle();
176  }
177  include_once './Services/Form/classes/class.ilSelectInputGUI.php';
178  $table_selection = new ilSelectInputGUI('', 'table_id');
179  $table_selection->setOptions($options);
180  $table_selection->setValue($this->table_id);
181 
182  $this->toolbar->setFormAction($this->ctrl->getFormActionByClass("ilDclFieldListGUI", "doTableSwitch"));
183  $this->toolbar->addText($this->lng->txt("dcl_select"));
184  $this->toolbar->addInputItem($table_selection);
185  $this->toolbar->addFormButton($this->lng->txt('change'), 'doTableSwitch');
186 
187  //table gui
188  $list = new ilDclFieldListTableGUI($this, $this->ctrl->getCmd(), $this->table_id);
189  $this->tpl->setContent($list->getHTML());
190  }
191 
192 
193  /*
194  * doTableSwitch
195  */
196  public function doTableSwitch()
197  {
198  $this->ctrl->setParameterByClass("ilObjDataCollectionGUI", "table_id", $_POST['table_id']);
199  $this->ctrl->redirectByClass("ilDclFieldListGUI", "listFields");
200  }
201 
205  protected function checkAccess()
206  {
207  $ref_id = $this->getDataCollectionObject()->getRefId();
208  return ilObjDataCollectionAccess::hasAccessToEditTable($ref_id, $this->table_id);
209  }
210 
211 
215  public function getDataCollectionObject()
216  {
217  return $this->parent_obj->getDataCollectionObject();
218  }
219 }
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
This class represents a selection list property in a property form.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
static getFieldCache($field_id=0)
static hasAccessToEditTable($ref_id, $table_id)
Class ilDclTableListGUI.
static getTableCache($table_id=0)
global $ilCtrl
Definition: ilias.php:18
deleteFields()
Delete multiple fields.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
executeCommand()
execute command
Class ilDclFieldListTableGUI.
if(empty($password)) $table
Definition: pwgen.php:24
__construct(ilDclTableListGUI $a_parent_obj)
Constructor.
$_POST["username"]
Confirmation screen class.