ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDclTableViewEditGUI.php
Go to the documentation of this file.
1 <?php
2 
14 {
15 
19  protected $parent_obj;
23  protected $ctrl;
27  protected $lng;
31  protected $tpl;
35  public $tableview;
39  protected $form;
43  protected $table_gui;
47  protected $tabs_gui;
51  public $table;
52 
53 
61  {
62  global $DIC;
63  $lng = $DIC['lng'];
64  $ilCtrl = $DIC['ilCtrl'];
65  $tpl = $DIC['tpl'];
66  $ilTabs = $DIC['ilTabs'];
67  $locator = $DIC['ilLocator'];
68  $this->table = $table;
69  $this->tpl = $tpl;
70  $this->lng = $lng;
71  $this->ctrl = $ilCtrl;
72  $this->parent_obj = $parent_obj;
73  $this->tableview = $tableview;
74  $this->tabs_gui = $ilTabs;
75 
76  $this->ctrl->saveParameterByClass('ilDclTableEditGUI', 'table_id');
77  $this->ctrl->saveParameter($this, 'tableview_id');
78  if ($this->tableview->getTitle()) {
79  $locator->addItem($this->tableview->getTitle(), $this->ctrl->getLinkTarget($this, 'show'));
80  }
81  $this->tpl->setLocator();
82  }
83 
84 
88  public function executeCommand()
89  {
90  $cmd = $this->ctrl->getCmd('show');
91  $next_class = $this->ctrl->getNextClass($this);
92 
93  if (!$this->checkAccess($cmd)) {
94  $this->permissionDenied();
95  }
96 
97  $this->tabs_gui->clearTargets();
98  $this->tabs_gui->clearSubTabs();
99  $this->tabs_gui->setBackTarget($this->lng->txt('dcl_tableviews'), $this->ctrl->getLinkTarget($this->parent_obj));
100  $this->tabs_gui->setBack2Target($this->lng->txt('dcl_tables'), $this->ctrl->getLinkTarget($this->parent_obj->parent_obj));
101 
102  switch ($next_class) {
103  case 'ildcldetailedviewdefinitiongui':
104  $this->setTabs('detailed_view');
105  $recordedit_gui = new ilDclDetailedViewDefinitionGUI($this->tableview->getId());
106  $ret = $this->ctrl->forwardCommand($recordedit_gui);
107  if ($ret != "") {
108  $this->tpl->setContent($ret);
109  }
110  global $DIC;
111  $ilTabs = $DIC['ilTabs'];
112  $ilTabs->removeTab('edit');
113  $ilTabs->removeTab('history');
114  $ilTabs->removeTab('clipboard'); // Fixme
115  $ilTabs->removeTab('pg');
116  break;
117  case 'ildclcreateviewdefinitiongui':
118  $this->setTabs('create_view');
119  $creation_gui = new ilDclCreateViewDefinitionGUI($this->tableview->getId());
120  $this->ctrl->forwardCommand($creation_gui);
121  global $DIC;
122  $ilTabs = $DIC['ilTabs'];
123  $ilTabs->removeTab('edit');
124  $ilTabs->removeTab('history');
125  $ilTabs->removeTab('clipboard'); // Fixme
126  $ilTabs->removeTab('pg');
127  break;
128  case 'ildcleditviewdefinitiongui':
129  $this->setTabs('edit_view');
130  $edit_gui = new ilDclEditViewDefinitionGUI($this->tableview->getId());
131  $this->ctrl->forwardCommand($edit_gui);
132  global $DIC;
133  $ilTabs = $DIC['ilTabs'];
134  $ilTabs->removeTab('edit');
135  $ilTabs->removeTab('history');
136  $ilTabs->removeTab('clipboard'); // Fixme
137  $ilTabs->removeTab('pg');
138  break;
139  default:
140  switch ($cmd) {
141  case 'show':
142  if ($this->tableview->getId()) {
143  $this->ctrl->redirect($this, 'editGeneralSettings');
144  } else {
145  $this->ctrl->redirect($this, 'add');
146  }
147  break;
148  case 'add':
149  $ilDclTableViewEditFormGUI = new ilDclTableViewEditFormGUI($this, $this->tableview);
150  $this->tpl->setContent($ilDclTableViewEditFormGUI->getHTML());
151  break;
152  case 'editGeneralSettings':
153  $settings_tpl = new ilTemplate("tpl.dcl_settings.html", true, true, 'Modules/DataCollection');
154 
155  $this->setTabs('general_settings');
156  $ilDclTableViewEditFormGUI = new ilDclTableViewEditFormGUI($this, $this->tableview);
157 
158  global $DIC;
159  $f = $DIC->ui()->factory()->listing()->workflow();
160  $renderer = $DIC->ui()->renderer();
161 
162  // Set Workflow flag to true
163  $view = ilDclTableView::getCollection()->where(array("id" => filter_input(INPUT_GET, "tableview_id")))->first();
164  if (!is_null($view)) {
165  //setup steps
166  $step = $f->step('', '');
167  $steps = [
168  $f->step($this->lng->txt('dcl_view_settings'))
169  ->withAvailability($step::AVAILABLE)->withStatus($view->getStepVs() ? 3 : 4),
170  $f->step($this->lng->txt('dcl_create_entry_rules'))
171  ->withAvailability($step::AVAILABLE)->withStatus($view->getStepC() ? 3 : 4),
172  $f->step($this->lng->txt('dcl_edit_entry_rules'))
173  ->withAvailability($step::AVAILABLE)->withStatus($view->getStepE() ? 3 : 4),
174  $f->step($this->lng->txt('dcl_list_visibility_and_filter'))
175  ->withAvailability($step::AVAILABLE)->withStatus($view->getStepO() ? 3 : 4),
176  $f->step($this->lng->txt('dcl_detailed_view'))
177  ->withAvailability($step::AVAILABLE)->withStatus($view->getStepS() ? 3 : 1),
178  ];
179 
180  //setup linear workflow
181  $wf = $f->linear($this->lng->txt('dcl_view_configuration'), $steps);
182  $settings_tpl->setVariable("WORKFLOW", $renderer->render($wf));
183  }
184 
185 
186 
187  $settings_tpl->setVariable("SETTINGS", $ilDclTableViewEditFormGUI->getHTML());
188 
189  $this->tpl->setContent($settings_tpl->get());
190  break;
191  case 'editFieldSettings':
192  $this->setTabs('field_settings');
193  $this->initTableGUI();
194  $this->tpl->setContent($this->table_gui->getHTML());
195  break;
196  default:
197  $this->$cmd();
198  break;
199  }
200  break;
201  }
202  }
203 
204 
205  protected function setTabs($active)
206  {
207  $this->tabs_gui->addTab('general_settings', $this->lng->txt('dcl_view_settings'), $this->ctrl->getLinkTarget($this, 'editGeneralSettings'));
208  $this->tabs_gui->addTab('create_view', $this->lng->txt('dcl_create_entry_rules'), $this->ctrl->getLinkTargetByClass('ilDclCreateViewDefinitionGUI', 'presentation'));
209  $this->tabs_gui->addTab('edit_view', $this->lng->txt('dcl_edit_entry_rules'), $this->ctrl->getLinkTargetByClass('ilDclEditViewDefinitionGUI', 'presentation'));
210  $this->tabs_gui->addTab('field_settings', $this->lng->txt('dcl_list_visibility_and_filter'), $this->ctrl->getLinkTarget($this, 'editFieldSettings'));
211  $this->tabs_gui->addTab('detailed_view', $this->lng->txt('dcl_detailed_view'), $this->ctrl->getLinkTargetByClass('ilDclDetailedViewDefinitionGUI', 'edit'));
212  $this->tabs_gui->setTabActive($active);
213  }
214 
215 
219  public function update()
220  {
221  $ilDclTableViewEditFormGUI = new ilDclTableViewEditFormGUI($this, $this->tableview);
222  $ilDclTableViewEditFormGUI->setValuesByPost();
223  if ($ilDclTableViewEditFormGUI->checkInput()) {
224  $ilDclTableViewEditFormGUI->updateTableView();
225  $this->ctrl->redirect($this, 'editGeneralSettings');
226  } else {
227  $this->setTabs('general_settings');
228  $this->tpl->setContent($ilDclTableViewEditFormGUI->getHTML());
229  }
230  }
231 
232 
236  public function create()
237  {
238  $ilDclTableViewEditFormGUI = new ilDclTableViewEditFormGUI($this, $this->tableview, $this->table);
239  $ilDclTableViewEditFormGUI->setValuesByPost();
240  if ($ilDclTableViewEditFormGUI->checkInput()) {
241  $ilDclTableViewEditFormGUI->createTableView();
242  $this->ctrl->redirect($this, 'editGeneralSettings');
243  } else {
244  $this->tpl->setContent($ilDclTableViewEditFormGUI->getHTML());
245  }
246  }
247 
248 
252  public function saveTable()
253  {
257  foreach ($this->tableview->getFieldSettings() as $setting) {
258  //Checkboxes
259  foreach (array("Visible", "InFilter", "FilterChangeable") as $attribute) {
260  $key = $attribute . '_' . $setting->getField();
261  $setting->{'set' . $attribute}($_POST[$key] == 'on');
262  }
263 
264  //Filter Value
265  $key = 'filter_' . $setting->getField();
266  if ($_POST[$key] != null) {
267  $setting->setFilterValue($_POST[$key]);
268  } elseif ($_POST[$key . '_from'] != null && $_POST[$key . '_to'] != null) {
269  $setting->setFilterValue(array("from" => $_POST[$key . '_from'], "to" => $_POST[$key . '_to']));
270  } else {
271  $setting->setFilterValue(null);
272  }
273 
274  $setting->update();
275  }
276 
277  // Set Workflow flag to true
278  $view = ilDclTableView::getCollection()->where(array("id" => filter_input(INPUT_GET, "tableview_id")))->first();
279  if (!is_null($view)) {
280  $view->setStepO(true);
281  $view->save();
282  }
283 
284  ilUtil::sendSuccess($this->lng->txt('dcl_msg_tableview_updated'), true);
285  $this->ctrl->saveParameter($this->parent_obj, 'tableview_id');
286  $this->ctrl->redirect($this, 'editFieldSettings');
287  }
288 
289 
293  protected function initTableGUI()
294  {
296  $this->table_gui = $table;
297  }
298 
299 
303  protected function cancel()
304  {
305  $this->ctrl->setParameter($this->parent_obj, 'table_id', $this->table->getId());
306  $this->ctrl->redirect($this->parent_obj);
307  }
308 
309 
313  public function confirmDelete()
314  {
315  //at least one view must exist
316  $this->parent_obj->checkViewsLeft(1);
317 
318  $conf = new ilConfirmationGUI();
319  $conf->setFormAction($this->ctrl->getFormAction($this));
320  $conf->setHeaderText($this->lng->txt('dcl_tableview_confirm_delete'));
321 
322  $conf->addItem('tableview_id', (int) $this->tableview->getId(), $this->tableview->getTitle());
323 
324  $conf->setConfirm($this->lng->txt('delete'), 'delete');
325  $conf->setCancel($this->lng->txt('cancel'), 'cancel');
326 
327  $this->tpl->setContent($conf->getHTML());
328  }
329 
330 
331  protected function delete()
332  {
333  $this->tableview->delete();
334  $this->table->sortTableViews();
335  ilUtil::sendSuccess($this->lng->txt('dcl_msg_tableview_deleted'), true);
336  $this->cancel();
337  }
338 
339 
343  public function permissionDenied()
344  {
345  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
346  $this->ctrl->redirectByClass([ilObjDataCollectionGUI::class, ilDclRecordListGUI::class], ilDclRecordListGUI::CMD_LIST_RECORDS);
347  }
348 
349 
355  protected function checkAccess($cmd)
356  {
357  if (in_array($cmd, ['add', 'create'])) {
359  $this->parent_obj->parent_obj->getDataCollectionObject()->getRefId(),
360  $this->table->getId()
361  );
362  } else {
363  return ilObjDataCollectionAccess::hasAccessTo(
364  $this->parent_obj->parent_obj->getDataCollectionObject()->getRefId(),
365  $this->table->getId(),
366  $this->tableview->getId()
367  );
368  }
369  }
370 
371 
372  public function copy()
373  {
374  $new_tableview = new ilDclTableView();
375  $new_tableview->setTableId($this->table->getId());
376  $new_tableview->cloneStructure($this->tableview, array());
377  $this->table->sortTableViews();
378  ilUtil::sendSuccess($this->lng->txt("dcl_tableview_copy"), true);
379  $this->cancel();
380  }
381 }
Class ilDclTableViewEditGUI.
__construct(ilDclTableViewGUI $parent_obj, ilDclTable $table, ilDclTableView $tableview)
ilDclTableViewEditGUI constructor.
Class ilDclTableViewGUI.
Class ilDclCreateViewDefinitionGUI.
Class ilDclEditViewDefinitionGUI.
Class ilDclTableViewEditFormGUI.
Class ilDclDetailedViewDefinitionGUI.
static hasAccessToEditTable($ref_id, $table_id)
Class ilDclTableViewEditFieldsTableGUI.
Class ilDclBaseFieldModel.
global $DIC
Definition: goto.php:24
Class ilDclTableView.
$steps
Definition: latex.php:3
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$ret
Definition: parser.php:6
$_POST["username"]
Confirmation screen class.