ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDclTableViewEditGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
31{
33 protected ilCtrl $ctrl;
34 protected ilLanguage $lng;
41 protected ilHelpGUI $help;
49 private array $available_roles = [];
50
52 {
53 global $DIC;
54 $lng = $DIC['lng'];
55 $ilCtrl = $DIC['ilCtrl'];
56 $tpl = $DIC['tpl'];
57 $ilTabs = $DIC['ilTabs'];
58 $locator = $DIC['ilLocator'];
59 $this->table = $table;
60 $this->tpl = $tpl;
61 $this->lng = $lng;
62 $this->ctrl = $ilCtrl;
63 $this->parent_obj = $parent_obj;
64 $this->tableview = $tableview;
65 $this->tabs_gui = $ilTabs;
66 $this->help = $DIC->help();
67 $this->http = $DIC->http();
68 $this->refinery = $DIC->refinery();
69 $this->ui_factory = $DIC->ui()->factory();
70 $this->ui_renderer = $DIC->ui()->renderer();
71 $ref_id = $this->table->getCollectionObject()->getRefId();
72 foreach ($DIC->rbac()->review()->getParentRoleIds($ref_id) as $role) {
73 if (
74 $role['obj_id'] !== SYSTEM_ROLE_ID &&
75 $DIC->rbac()->system()->checkPermission($ref_id, $role['obj_id'], 'visible')
76 ) {
77 $this->available_roles[$role['obj_id']] = ilObjRole::_getTranslation($role['title']);
78 }
79 }
80
81 $this->ctrl->saveParameterByClass('ilDclTableEditGUI', 'table_id');
82 $this->ctrl->saveParameter($this, 'tableview_id');
83 if ($this->tableview->getTitle()) {
84 $locator->addItem($this->tableview->getTitle(), $this->ctrl->getLinkTarget($this, 'show'));
85 }
86 $this->tpl->setLocator();
87 }
88
89 public function executeCommand(): void
90 {
91 $cmd = $this->ctrl->getCmd('show');
92 $next_class = $this->ctrl->getNextClass($this);
93
94 if (!$this->checkAccess($cmd)) {
95 $this->permissionDenied();
96 }
97
98 $this->tabs_gui->clearTargets();
99 $this->tabs_gui->clearSubTabs();
100 $this->tabs_gui->setBackTarget(
101 $this->lng->txt('dcl_tableviews'),
102 $this->ctrl->getLinkTarget($this->parent_obj)
103 );
104 $this->tabs_gui->setBack2Target(
105 $this->lng->txt('dcl_tables'),
106 $this->ctrl->getLinkTarget($this->parent_obj->getParentObj())
107 );
108
109 switch ($next_class) {
110 case 'ildcldetailedviewdefinitiongui':
111 $this->help->setSubScreenId('detailed_view');
112 $this->setTabs('detailed_view');
113 $recordedit_gui = new ilDclDetailedViewDefinitionGUI($this->tableview->getId());
114 $ret = $this->ctrl->forwardCommand($recordedit_gui);
115 if ($ret != "") {
116 $this->tpl->setContent($ret);
117 }
118 break;
119 case 'ildclcreateviewdefinitiongui':
120 $this->help->setSubScreenId('record_create');
121 $this->setTabs('create_view');
122 $creation_gui = new ilDclCreateViewDefinitionGUI($this->tableview->getId());
123 $this->ctrl->forwardCommand($creation_gui);
124 break;
125 case 'ildcleditviewdefinitiongui':
126 $this->help->setSubScreenId('record_edit');
127 $this->setTabs('edit_view');
128 $edit_gui = new ilDclEditViewDefinitionGUI($this->tableview->getId());
129 $this->ctrl->forwardCommand($edit_gui);
130 break;
131 default:
132 switch ($cmd) {
133 case 'show':
134 if ($this->tableview->getId()) {
135 $this->ctrl->redirect($this, 'editGeneralSettings');
136 } else {
137 $this->ctrl->redirect($this, 'add');
138 }
139 break;
140 case 'add':
141 $this->help->setSubScreenId('create');
142 $this->tpl->setContent(
143 $this->lng->txt('dcl_new_view') . $this->ui_renderer->render($this->initForm(true))
144 );
145 break;
146 case 'editGeneralSettings':
147 $this->help->setSubScreenId('edit');
148 $this->setTabs('general_settings');
149 $this->tpl->setContent(
150 sprintf($this->lng->txt('dcl_edit_view'), $this->tableview->getTitle()) .
151 $this->ui_renderer->render($this->initForm())
152 );
153 break;
154 case 'editFieldSettings':
155 $this->help->setSubScreenId('overview');
156 $this->setTabs('field_settings');
157 $this->initTableGUI();
158 $this->tpl->setContent($this->table_gui->getHTML());
159 break;
160 default:
161 if ($cmd === 'create' || $cmd === 'update') {
162 $this->save($cmd === 'create');
163 }
164 $this->$cmd();
165 break;
166 }
167 break;
168 }
169 }
170
171 protected function initForm(bool $create = false): Form
172 {
173 $settings['title'] = $this->ui_factory->input()->field()->text($this->lng->txt('title'))->withRequired(true);
174 $settings['description'] = $this->ui_factory->input()->field()->textarea($this->lng->txt('description'));
175 $roles = [];
176 $settings['role_limitation'] = $this->ui_factory->input()->field()->optionalGroup(
177 [
178 'roles' => $this->ui_factory->input()->field()->multiSelect(
179 $this->lng->txt('roles'),
180 $this->available_roles,
181 $this->lng->txt('roles_desc')
182 )
183 ],
184 $this->lng->txt('role_limitation')
185 );
186
187 $inputs['settings'] = $this->ui_factory->input()->field()->section($settings, $this->lng->txt('general_settings'));
188
189 if (!$create) {
190 $inputs = $this->setValues($inputs);
191 }
192
193 return $this->ui_factory->input()->container()->form()->standard(
194 $this->ctrl->getFormAction($this, $create ? 'create' : 'update'),
195 $inputs
196 );
197 }
198
199 protected function setValues(array $inputs): array
200 {
201 $roles = [];
202 foreach ($this->tableview->getRoles() as $role) {
203 $role = (int) $role;
204 if (in_array($role, array_keys($this->available_roles), true)) {
205 $roles[] = $role;
206 }
207 }
208 $inputs['settings'] = $inputs['settings']->withValue([
209 'title' => $this->tableview->getTitle(),
210 'description' => $this->tableview->getDescription(),
211 'role_limitation' => $this->tableview->getRoleLimitation() ? ['roles' => $roles] : null
212 ]);
213
214 return $inputs;
215 }
216
217 protected function setTabs(string $active): void
218 {
219 $this->tabs_gui->addTab(
220 'general_settings',
221 $this->lng->txt('settings'),
222 $this->ctrl->getLinkTarget($this, 'editGeneralSettings')
223 );
224 $this->tabs_gui->addTab(
225 'create_view',
226 $this->lng->txt('dcl_create_entry_rules'),
227 $this->ctrl->getLinkTargetByClass('ilDclCreateViewDefinitionGUI', 'presentation')
228 );
229 $this->tabs_gui->addTab(
230 'edit_view',
231 $this->lng->txt('dcl_edit_entry_rules'),
232 $this->ctrl->getLinkTargetByClass('ilDclEditViewDefinitionGUI', 'presentation')
233 );
234 $this->tabs_gui->addTab(
235 'field_settings',
236 $this->lng->txt('dcl_list_visibility_and_filter'),
237 $this->ctrl->getLinkTarget($this, 'editFieldSettings')
238 );
239 $this->tabs_gui->addTab(
240 'detailed_view',
241 $this->lng->txt('dcl_detailed_view'),
242 $this->ctrl->getLinkTargetByClass('ilDclDetailedViewDefinitionGUI', 'edit')
243 );
244 $this->tabs_gui->setTabActive($active);
245 }
246
247 public function save(bool $create = false): void
248 {
249 $data = $this->initForm()->withRequest($this->http->request())->getData();
250 if ($data !== null) {
251 $this->tableview->setTitle($data['settings']['title']);
252 $this->tableview->setDescription($data['settings']['description']);
253 $this->tableview->setRoleLimitation($data['settings']['role_limitation'] !== null);
254 $this->tableview->setRoles($data['settings']['role_limitation']['roles'] ?? []);
255 if ($create) {
256 $this->tableview->setTableId($this->table->getId());
257 $this->tableview->setOrder($this->table->getNewTableviewOrder());
258 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('dcl_msg_tableview_created'), true);
259 $this->tableview->create();
260 } else {
261 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('dcl_msg_tableview_updated'), true);
262 $this->tableview->update();
263 }
264 }
265 $this->ctrl->redirect($this, 'editGeneralSettings');
266 }
267
268 public function saveOverviewSettings(): void
269 {
273 foreach ($this->tableview->getFieldSettings() as $setting) {
274 //Checkboxes
275 foreach (["Visible", "InFilter", "FilterChangeable"] as $attribute) {
276 $key = $attribute . '_' . $setting->getField();
277 if ($this->http->wrapper()->post()->has($key)) {
278 $checkbox_value = $this->http->wrapper()->post()->retrieve(
279 $key,
280 $this->refinery->kindlyTo()->string()
281 );
282 $setting->{'set' . $attribute}($checkbox_value === 'on');
283 } else {
284 $setting->{'set' . $attribute}(false);
285 }
286 }
287
288 //Filter Value
289 $key = 'filter_' . $setting->getField();
290 if ($this->http->wrapper()->post()->has($key)) {
291 $setting->setFilterValue($this->http->wrapper()->post()->retrieve(
292 $key,
293 $this->refinery->kindlyTo()->string()
294 ));
295 } elseif ($this->http->wrapper()->post()->has($key . '_from') && $this->http->wrapper()->post()->has($key . '_to')) {
296 $setting->setFilterValue(["from" => $this->http->wrapper()->post()->retrieve(
297 $key . '_from',
298 $this->refinery->kindlyTo()->string()
299 ),
300 "to" => $this->http->wrapper()->post()->retrieve(
301 $key . '_to',
302 $this->refinery->kindlyTo()->string()
303 )
304 ]);
305 } else {
306 $setting->setFilterValue(null);
307 }
308
309 $setting->update();
310 }
311
312 $this->tpl->setOnScreenMessage('success', $this->lng->txt('dcl_msg_tableview_updated'), true);
313 $this->ctrl->saveParameter($this->parent_obj, 'tableview_id');
314 $this->ctrl->redirect($this, 'editFieldSettings');
315 }
316
317 protected function initTableGUI(): void
318 {
319 $table = new ilDclTableViewEditFieldsTableGUI($this);
320 $this->table_gui = $table;
321 }
322
323 protected function cancel(): void
324 {
325 $this->ctrl->setParameter($this->parent_obj, 'table_id', $this->table->getId());
326 $this->ctrl->redirect($this->parent_obj);
327 }
328
329 public function confirmDelete(): void
330 {
331 //at least one view must exist
332 $this->parent_obj->checkViewsLeft(1);
333
334 $conf = new ilConfirmationGUI();
335 $conf->setFormAction($this->ctrl->getFormAction($this));
336 $conf->setHeaderText($this->lng->txt('dcl_tableview_confirm_delete'));
337
338 $conf->addItem('tableview_id', (string) $this->tableview->getId(), $this->tableview->getTitle());
339
340 $conf->setConfirm($this->lng->txt('delete'), 'delete');
341 $conf->setCancel($this->lng->txt('cancel'), 'cancel');
342
343 $this->tpl->setContent($conf->getHTML());
344 }
345
346 protected function delete(): void
347 {
348 $this->tableview->delete();
349 $this->table->sortTableViews();
350 $this->tpl->setOnScreenMessage('success', $this->lng->txt('dcl_msg_tableview_deleted'), true);
351 $this->cancel();
352 }
353
354 public function permissionDenied(): void
355 {
356 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
357 $this->ctrl->redirectByClass(
358 [ilObjDataCollectionGUI::class, ilDclRecordListGUI::class],
360 );
361 }
362
363 protected function checkAccess(string $cmd): bool
364 {
365 if (in_array($cmd, ['add', 'create', 'cancel'])) {
367 $this->parent_obj->getParentObj()->getDataCollectionObject()->getRefId(),
368 $this->table->getId()
369 );
370 } else {
371 return ilObjDataCollectionAccess::hasAccessTo(
372 $this->parent_obj->getParentObj()->getDataCollectionObject()->getRefId(),
373 $this->table->getId(),
374 $this->tableview->getId()
375 );
376 }
377 }
378
379 public function copy(): void
380 {
381 $new_tableview = new ilDclTableView();
382 $new_tableview->setTableId($this->table->getId());
383 $new_tableview->cloneStructure($this->tableview, []);
384 $this->table->sortTableViews();
385 $this->tpl->setOnScreenMessage('success', $this->lng->txt("dcl_tableview_copy"), true);
386 $this->cancel();
387 }
388}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
@ilCtrl_IsCalledBy ilDclCreateViewDefinitionGUI: ilDclTableViewEditGUI
@ilCtrl_Calls ilDclDetailedViewDefinitionGUI: ilPageEditorGUI, ilEditClipboardGUI,...
@ilCtrl_IsCalledBy ilDclEditViewDefinitionGUI: ilDclTableViewEditGUI
@ilCtrl_Calls ilDclTableViewEditGUI: ilDclDetailedViewDefinitionGUI @ilCtrl_Calls ilDclTableViewEditG...
__construct(ilDclTableViewGUI $parent_obj, ilDclTable $table, ilDclTableView $tableview)
ilDclTableViewEditFieldsTableGUI $table_gui
ILIAS Refinery Factory $refinery
@ilCtrl_Calls ilDclTableViewGUI: ilDclTableViewEditGUI
Help GUI class.
language handling
static hasAccessToEditTable(int $ref_id, int $table_id)
static _getTranslation(string $a_role_title)
This class represents a property form user interface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const SYSTEM_ROLE_ID
Definition: constants.php:29
This describes commonalities between all forms.
Definition: Form.php:33
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
$ref_id
Definition: ltiauth.php:66
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26