ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilDclTableViewEditGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 {
29  protected ilCtrl $ctrl;
30  protected ilLanguage $lng;
35  protected ilTabsGUI $tabs_gui;
37  protected ilHelpGUI $help;
40 
41  public function __construct(ilDclTableViewGUI $parent_obj, ilDclTable $table, ilDclTableView $tableview)
42  {
43  global $DIC;
44  $lng = $DIC['lng'];
45  $ilCtrl = $DIC['ilCtrl'];
46  $tpl = $DIC['tpl'];
47  $ilTabs = $DIC['ilTabs'];
48  $locator = $DIC['ilLocator'];
49  $this->table = $table;
50  $this->tpl = $tpl;
51  $this->lng = $lng;
52  $this->ctrl = $ilCtrl;
53  $this->parent_obj = $parent_obj;
54  $this->tableview = $tableview;
55  $this->tabs_gui = $ilTabs;
56  $this->help = $DIC->help();
57  $this->http = $DIC->http();
58  $this->refinery = $DIC->refinery();
59 
60  $this->ctrl->saveParameterByClass('ilDclTableEditGUI', 'table_id');
61  $this->ctrl->saveParameter($this, 'tableview_id');
62  if ($this->tableview->getTitle()) {
63  $locator->addItem($this->tableview->getTitle(), $this->ctrl->getLinkTarget($this, 'show'));
64  }
65  $this->tpl->setLocator();
66  }
67 
68  public function executeCommand(): void
69  {
70  $cmd = $this->ctrl->getCmd('show');
71  $next_class = $this->ctrl->getNextClass($this);
72 
73  if (!$this->checkAccess($cmd)) {
74  $this->permissionDenied();
75  }
76 
77  $this->tabs_gui->clearTargets();
78  $this->tabs_gui->clearSubTabs();
79  $this->tabs_gui->setBackTarget(
80  $this->lng->txt('dcl_tableviews'),
81  $this->ctrl->getLinkTarget($this->parent_obj)
82  );
83  $this->tabs_gui->setBack2Target(
84  $this->lng->txt('dcl_tables'),
85  $this->ctrl->getLinkTarget($this->parent_obj->getParentObj())
86  );
87 
88  switch ($next_class) {
89  case 'ildcldetailedviewdefinitiongui':
90  $this->help->setSubScreenId('detailed_view');
91  $this->setTabs('detailed_view');
92  $recordedit_gui = new ilDclDetailedViewDefinitionGUI($this->tableview->getId());
93  $ret = $this->ctrl->forwardCommand($recordedit_gui);
94  if ($ret != "") {
95  $this->tpl->setContent($ret);
96  }
97  break;
98  case 'ildclcreateviewdefinitiongui':
99  $this->help->setSubScreenId('record_create');
100  $this->setTabs('create_view');
101  $creation_gui = new ilDclCreateViewDefinitionGUI($this->tableview->getId());
102  $this->ctrl->forwardCommand($creation_gui);
103  break;
104  case 'ildcleditviewdefinitiongui':
105  $this->help->setSubScreenId('record_edit');
106  $this->setTabs('edit_view');
107  $edit_gui = new ilDclEditViewDefinitionGUI($this->tableview->getId());
108  $this->ctrl->forwardCommand($edit_gui);
109  break;
110  default:
111  switch ($cmd) {
112  case 'show':
113  if ($this->tableview->getId()) {
114  $this->ctrl->redirect($this, 'editGeneralSettings');
115  } else {
116  $this->ctrl->redirect($this, 'add');
117  }
118  break;
119  case 'add':
120  $this->help->setSubScreenId('create');
121  $ilDclTableViewEditFormGUI = new ilDclTableViewEditFormGUI($this, $this->tableview);
122  $this->tpl->setContent($ilDclTableViewEditFormGUI->getHTML());
123  break;
124  case 'editGeneralSettings':
125  $this->help->setSubScreenId('edit');
126  $this->setTabs('general_settings');
127  $ilDclTableViewEditFormGUI = new ilDclTableViewEditFormGUI($this, $this->tableview);
128  $this->tpl->setContent($ilDclTableViewEditFormGUI->getHTML());
129  break;
130  case 'editFieldSettings':
131  $this->help->setSubScreenId('overview');
132  $this->setTabs('field_settings');
133  $this->initTableGUI();
134  $this->tpl->setContent($this->table_gui->getHTML());
135  break;
136  default:
137  $this->$cmd();
138  break;
139  }
140  break;
141  }
142  }
143 
144  protected function setTabs(string $active): void
145  {
146  $this->tabs_gui->addTab(
147  'general_settings',
148  $this->lng->txt('dcl_view_settings'),
149  $this->ctrl->getLinkTarget($this, 'editGeneralSettings')
150  );
151  $this->tabs_gui->addTab(
152  'create_view',
153  $this->lng->txt('dcl_create_entry_rules'),
154  $this->ctrl->getLinkTargetByClass('ilDclCreateViewDefinitionGUI', 'presentation')
155  );
156  $this->tabs_gui->addTab(
157  'edit_view',
158  $this->lng->txt('dcl_edit_entry_rules'),
159  $this->ctrl->getLinkTargetByClass('ilDclEditViewDefinitionGUI', 'presentation')
160  );
161  $this->tabs_gui->addTab(
162  'field_settings',
163  $this->lng->txt('dcl_list_visibility_and_filter'),
164  $this->ctrl->getLinkTarget($this, 'editFieldSettings')
165  );
166  $this->tabs_gui->addTab(
167  'detailed_view',
168  $this->lng->txt('dcl_detailed_view'),
169  $this->ctrl->getLinkTargetByClass('ilDclDetailedViewDefinitionGUI', 'edit')
170  );
171  $this->tabs_gui->setTabActive($active);
172  }
173 
174  public function update(): void
175  {
176  $ilDclTableViewEditFormGUI = new ilDclTableViewEditFormGUI($this, $this->tableview);
177  $ilDclTableViewEditFormGUI->setValuesByPost();
178  if ($ilDclTableViewEditFormGUI->checkInput()) {
179  $ilDclTableViewEditFormGUI->updateTableView();
180  $this->ctrl->redirect($this, 'editGeneralSettings');
181  } else {
182  $this->setTabs('general_settings');
183  $this->tpl->setContent($ilDclTableViewEditFormGUI->getHTML());
184  }
185  }
186 
187  public function create(): void
188  {
189  $ilDclTableViewEditFormGUI = new ilDclTableViewEditFormGUI($this, $this->tableview, $this->table);
190  $ilDclTableViewEditFormGUI->setValuesByPost();
191  if ($ilDclTableViewEditFormGUI->checkInput()) {
192  $ilDclTableViewEditFormGUI->createTableView();
193  $this->ctrl->redirect($this, 'editGeneralSettings');
194  } else {
195  $this->tpl->setContent($ilDclTableViewEditFormGUI->getHTML());
196  }
197  }
198 
199  public function saveTable(): void
200  {
204  foreach ($this->tableview->getFieldSettings() as $setting) {
205  //Checkboxes
206  foreach (["Visible", "InFilter", "FilterChangeable"] as $attribute) {
207  $key = $attribute . '_' . $setting->getField();
208  if ($this->http->wrapper()->post()->has($key)) {
209  $checkbox_value = $this->http->wrapper()->post()->retrieve(
210  $key,
211  $this->refinery->kindlyTo()->string()
212  );
213  $setting->{'set' . $attribute}($checkbox_value === 'on');
214  } else {
215  $setting->{'set' . $attribute}(false);
216  }
217  }
218 
219  //Filter Value
220  $key = 'filter_' . $setting->getField();
221  if ($this->http->wrapper()->post()->has($key)) {
222  $setting->setFilterValue($this->http->wrapper()->post()->retrieve(
223  $key,
224  $this->refinery->kindlyTo()->string()
225  ));
226  } elseif ($this->http->wrapper()->post()->has($key . '_from') && $this->http->wrapper()->post()->has($key . '_to')) {
227  $setting->setFilterValue(["from" => $this->http->wrapper()->post()->retrieve(
228  $key . '_from',
229  $this->refinery->kindlyTo()->string()
230  ),
231  "to" => $this->http->wrapper()->post()->retrieve(
232  $key . '_to',
233  $this->refinery->kindlyTo()->string()
234  )
235  ]);
236  } else {
237  $setting->setFilterValue(null);
238  }
239 
240  $setting->update();
241  }
242 
243 
244  $this->tpl->setOnScreenMessage('success', $this->lng->txt('dcl_msg_tableview_updated'), true);
245  $this->ctrl->saveParameter($this->parent_obj, 'tableview_id');
246  $this->ctrl->redirect($this, 'editFieldSettings');
247  }
248 
249  protected function initTableGUI(): void
250  {
252  $this->table_gui = $table;
253  }
254 
255  protected function cancel(): void
256  {
257  $this->ctrl->setParameter($this->parent_obj, 'table_id', $this->table->getId());
258  $this->ctrl->redirect($this->parent_obj);
259  }
260 
261  public function confirmDelete(): void
262  {
263  //at least one view must exist
264  $this->parent_obj->checkViewsLeft(1);
265 
266  $conf = new ilConfirmationGUI();
267  $conf->setFormAction($this->ctrl->getFormAction($this));
268  $conf->setHeaderText($this->lng->txt('dcl_tableview_confirm_delete'));
269 
270  $conf->addItem('tableview_id', (string) $this->tableview->getId(), $this->tableview->getTitle());
271 
272  $conf->setConfirm($this->lng->txt('delete'), 'delete');
273  $conf->setCancel($this->lng->txt('cancel'), 'cancel');
274 
275  $this->tpl->setContent($conf->getHTML());
276  }
277 
278  protected function delete(): void
279  {
280  $this->tableview->delete();
281  $this->table->sortTableViews();
282  $this->tpl->setOnScreenMessage('success', $this->lng->txt('dcl_msg_tableview_deleted'), true);
283  $this->cancel();
284  }
285 
286  public function permissionDenied(): void
287  {
288  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
289  $this->ctrl->redirectByClass(
290  [ilObjDataCollectionGUI::class, ilDclRecordListGUI::class],
292  );
293  }
294 
295  protected function checkAccess(string $cmd): bool
296  {
297  if (in_array($cmd, ['add', 'create', 'cancel'])) {
299  $this->parent_obj->getParentObj()->getDataCollectionObject()->getRefId(),
300  $this->table->getId()
301  );
302  } else {
303  return ilObjDataCollectionAccess::hasAccessTo(
304  $this->parent_obj->getParentObj()->getDataCollectionObject()->getRefId(),
305  $this->table->getId(),
306  $this->tableview->getId()
307  );
308  }
309  }
310 
311  public function copy(): void
312  {
313  $new_tableview = new ilDclTableView();
314  $new_tableview->setTableId($this->table->getId());
315  $new_tableview->cloneStructure($this->tableview, []);
316  $this->table->sortTableViews();
317  $this->tpl->setOnScreenMessage('success', $this->lng->txt("dcl_tableview_copy"), true);
318  $this->cancel();
319  }
320 }
ilDclTableViewEditGUI: ilDclDetailedViewDefinitionGUI ilDclTableViewEditGUI: ilDclCreateViewDefiniti...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilDclTableViewGUI $parent_obj, ilDclTable $table, ilDclTableView $tableview)
ilDclTableViewGUI: ilDclTableViewEditGUI
ilDclCreateViewDefinitionGUI: ilDclTableViewEditGUI
ilDclEditViewDefinitionGUI: ilDclTableViewEditGUI
Help GUI class.
ilDclDetailedViewDefinitionGUI: ilPageEditorGUI, ilEditClipboardGUI, ilMediaPoolTargetSelector ilDcl...
ilDclTableViewEditFieldsTableGUI $table_gui
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.
ILIAS Refinery Factory $refinery
string $key
Consumer key/client ID value.
Definition: System.php:193
static hasAccessToEditTable(int $ref_id, int $table_id)