ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilDclTableViewEditGUI.php
Go to the documentation of this file.
1 <?php
2 
12 {
16  protected $parent_obj;
17 
21  protected $ctrl;
22 
26  protected $lng;
27 
31  protected $tpl;
32 
36  public $tableview;
37 
41  protected $form;
42 
46  protected $table_gui;
47 
51  protected $tabs_gui;
52 
56  public $table;
57 
58 
65  {
66  global $DIC;
67  $lng = $DIC['lng'];
68  $ilCtrl = $DIC['ilCtrl'];
69  $tpl = $DIC['tpl'];
70  $ilTabs = $DIC['ilTabs'];
71  $locator = $DIC['ilLocator'];
72  $this->table = $table;
73  $this->tpl = $tpl;
74  $this->lng = $lng;
75  $this->ctrl = $ilCtrl;
76  $this->parent_obj = $parent_obj;
77  $this->tableview = $tableview;
78  $this->tabs_gui = $ilTabs;
79 
80  $this->ctrl->saveParameterByClass('ilDclTableEditGUI', 'table_id');
81  $this->ctrl->saveParameter($this, 'tableview_id');
82  $locator->addItem($this->tableview->getTitle(), $this->ctrl->getLinkTarget($this, 'show'));
83  $this->tpl->setLocator();
84  }
85 
86 
90  public function executeCommand()
91  {
92  $cmd = $this->ctrl->getCmd('show');
93  $next_class = $this->ctrl->getNextClass($this);
94 
95  if (!$this->checkAccess($cmd)) {
96  $this->permissionDenied();
97  }
98 
99  $this->tabs_gui->clearTargets();
100  $this->tabs_gui->clearSubTabs();
101  $this->tabs_gui->setBackTarget($this->lng->txt('dcl_tableviews'), $this->ctrl->getLinkTarget($this->parent_obj));
102  $this->tabs_gui->setBack2Target($this->lng->txt('dcl_tables'), $this->ctrl->getLinkTarget($this->parent_obj->parent_obj));
103 
104 
105 
106  switch ($next_class) {
107  case 'ildcldetailedviewdefinitiongui':
108  $this->setTabs('detailed_view');
109  $recordedit_gui = new ilDclDetailedViewDefinitionGUI($this->tableview->getId());
110  $ret = $this->ctrl->forwardCommand($recordedit_gui);
111  if ($ret != "") {
112  $this->tpl->setContent($ret);
113  }
114  global $DIC;
115  $ilTabs = $DIC['ilTabs'];
116  $ilTabs->removeTab('edit');
117  $ilTabs->removeTab('history');
118  $ilTabs->removeTab('clipboard'); // Fixme
119  $ilTabs->removeTab('pg');
120  break;
121  default:
122  switch ($cmd) {
123  case 'show':
124  if ($this->tableview->getId()) {
125  $this->ctrl->redirect($this, 'editGeneralSettings');
126  } else {
127  $this->ctrl->redirect($this, 'add');
128  }
129  break;
130  case 'add':
131  $ilDclTableViewEditFormGUI = new ilDclTableViewEditFormGUI($this, $this->tableview);
132  $this->tpl->setContent($ilDclTableViewEditFormGUI->getHTML());
133  break;
134  case 'editGeneralSettings':
135  $this->setTabs('general_settings');
136  $ilDclTableViewEditFormGUI = new ilDclTableViewEditFormGUI($this, $this->tableview);
137  $this->tpl->setContent($ilDclTableViewEditFormGUI->getHTML());
138  break;
139  case 'editFieldSettings':
140  $this->setTabs('field_settings');
141  $this->initTableGUI();
142  $this->tpl->setContent($this->table_gui->getHTML());
143  break;
144  default:
145  $this->$cmd();
146  break;
147  }
148  break;
149  }
150  }
151 
152  protected function setTabs($active)
153  {
154  $this->tabs_gui->addTab('general_settings', $this->lng->txt('settings'), $this->ctrl->getLinkTarget($this, 'editGeneralSettings'));
155  $this->tabs_gui->addTab('field_settings', $this->lng->txt('dcl_list_visibility_and_filter'), $this->ctrl->getLinkTarget($this, 'editFieldSettings'));
156  $this->tabs_gui->addTab('detailed_view', $this->lng->txt('dcl_detailed_view'), $this->ctrl->getLinkTargetByClass('ilDclDetailedViewDefinitionGUI', 'edit'));
157  $this->tabs_gui->setTabActive($active);
158  }
159 
163  public function update()
164  {
165  $ilDclTableViewEditFormGUI = new ilDclTableViewEditFormGUI($this, $this->tableview);
166  $ilDclTableViewEditFormGUI->setValuesByPost();
167  if ($ilDclTableViewEditFormGUI->checkInput()) {
168  $ilDclTableViewEditFormGUI->updateTableView();
169  $this->ctrl->redirect($this, 'editGeneralSettings');
170  } else {
171  $this->setTabs('general_settings');
172  $this->tpl->setContent($ilDclTableViewEditFormGUI->getHTML());
173  }
174  }
175 
179  public function create()
180  {
181  $ilDclTableViewEditFormGUI = new ilDclTableViewEditFormGUI($this, $this->tableview, $this->table);
182  $ilDclTableViewEditFormGUI->setValuesByPost();
183  if ($ilDclTableViewEditFormGUI->checkInput()) {
184  $ilDclTableViewEditFormGUI->createTableView();
185  $this->ctrl->redirect($this, 'editGeneralSettings');
186  } else {
187  $this->tpl->setContent($ilDclTableViewEditFormGUI->getHTML());
188  }
189  }
190 
194  public function saveTable()
195  {
199  foreach ($this->tableview->getFieldSettings() as $setting) {
200  //Checkboxes
201  foreach (array("Visible", "InFilter", "FilterChangeable") as $attribute) {
202  $key = $attribute . '_' . $setting->getField();
203  $setting->{'set' . $attribute}($_POST[$key] == 'on');
204  }
205 
206  //Filter Value
207  $key = 'filter_' . $setting->getField();
208  if ($_POST[$key] != null) {
209  $setting->setFilterValue($_POST[$key]);
210  } elseif ($_POST[$key . '_from'] != null && $_POST[$key . '_to'] != null) {
211  $setting->setFilterValue(array( "from" => $_POST[$key . '_from'], "to" => $_POST[$key . '_to'] ));
212  } else {
213  $setting->setFilterValue(null);
214  }
215 
216  $setting->update();
217  }
218  ilUtil::sendSuccess($this->lng->txt('dcl_msg_tableview_updated'), true);
219  $this->ctrl->saveParameter($this->parent_obj, 'tableview_id');
220  $this->ctrl->redirect($this, 'editFieldSettings');
221  }
222 
226  protected function initTableGUI()
227  {
229  $this->table_gui = $table;
230  }
231 
235  protected function cancel()
236  {
237  $this->ctrl->setParameter($this->parent_obj, 'table_id', $this->table->getId());
238  $this->ctrl->redirect($this->parent_obj);
239  }
240 
244  public function confirmDelete()
245  {
246  //at least one view must exist
247  $this->parent_obj->checkViewsLeft(1);
248 
249  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
250  $conf = new ilConfirmationGUI();
251  $conf->setFormAction($this->ctrl->getFormAction($this));
252  $conf->setHeaderText($this->lng->txt('dcl_tableview_confirm_delete'));
253 
254  $conf->addItem('tableview_id', (int) $this->tableview->getId(), $this->tableview->getTitle());
255 
256  $conf->setConfirm($this->lng->txt('delete'), 'delete');
257  $conf->setCancel($this->lng->txt('cancel'), 'cancel');
258 
259  $this->tpl->setContent($conf->getHTML());
260  }
261 
262  protected function delete()
263  {
264  $this->tableview->delete();
265  $this->table->sortTableViews();
266  ilUtil::sendSuccess($this->lng->txt('dcl_msg_tableview_deleted'), true);
267  $this->cancel();
268  }
269 
270 
274  public function permissionDenied()
275  {
276  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
277  $this->ctrl->redirectByClass([ilObjDataCollectionGUI::class, ilDclRecordListGUI::class], ilDclRecordListGUI::CMD_LIST_RECORDS);
278  }
279 
280 
286  protected function checkAccess($cmd)
287  {
288  if (in_array($cmd, ['add', 'create'])) {
290  $this->parent_obj->parent_obj->getDataCollectionObject()->getRefId(),
291  $this->table->getId()
292  );
293  } else {
294  return ilObjDataCollectionAccess::hasAccessTo(
295  $this->parent_obj->parent_obj->getDataCollectionObject()->getRefId(),
296  $this->table->getId(),
297  $this->tableview->getId()
298  );
299  }
300  }
301 }
Class ilDclTableViewEditGUI.
__construct(ilDclTableViewGUI $parent_obj, ilDclTable $table, ilDclTableView $tableview)
ilDclTableViewEditGUI constructor.
Class ilDclTableViewGUI.
global $DIC
Definition: saml.php:7
Class ilDclTableViewEditFormGUI.
Class ilDclDetailedViewDefinitionGUI.
static hasAccessToEditTable($ref_id, $table_id)
Class ilDclTableViewEditFieldsTableGUI.
Class ilDclBaseFieldModel.
global $ilCtrl
Definition: ilias.php:18
Class ilDclTableView.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$ret
Definition: parser.php:6
$key
Definition: croninfo.php:18
$_POST["username"]
Confirmation screen class.