ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDclTableListGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27{
28 protected \ILIAS\UI\Factory $ui_factory;
29 protected \ILIAS\UI\Renderer $renderer;
30 protected ilCtrl $ctrl;
31 protected ilLanguage $lng;
33 protected ilTabsGUI $tabs;
38
39 public function __construct(ilObjDataCollectionGUI $a_parent_obj)
40 {
41 global $DIC;
42 $main_tpl = $DIC->ui()->mainTemplate();
43 $this->ctrl = $DIC->ctrl();
44 $this->lng = $DIC->language();
45 $this->tpl = $DIC->ui()->mainTemplate();
46 $this->tabs = $DIC->tabs();
47 $this->toolbar = $DIC->toolbar();
48 $this->http = $DIC->http();
49 $this->refinery = $DIC->refinery();
50 $this->ui_factory = $DIC->ui()->factory();
51 $this->renderer = $DIC->ui()->renderer();
52
53 $this->tabs->setSetupMode(true);
54 $DIC->help()->setScreenId('dcl_tables');
55
56 $this->parent_obj = $a_parent_obj;
57
58 if (!$this->checkAccess()) {
59 $main_tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
60 $this->ctrl->redirectByClass(ilDclRecordListGUI::class, 'listRecords');
61 }
62 }
63
64 public function getObjId(): int
65 {
66 return $this->parent_obj->getObjectId();
67 }
68
69 public function getRefId(): int
70 {
71 return $this->parent_obj->getRefId();
72 }
73
77 public function executeCommand(): void
78 {
79 global $DIC;
80 $cmd = $this->ctrl->getCmd('listTables');
81
82 $next_class = $this->ctrl->getNextClass($this);
83
84 $ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
85
86 switch ($next_class) {
87 case 'ildcltableeditgui':
88 $this->tabs->clearTargets();
89 if ($cmd != 'create') {
90 $this->setTabs('settings');
91 } else {
92 $this->tabs->setBackTarget(
93 $this->lng->txt('back'),
94 $this->ctrl->getLinkTarget($this, 'listTables')
95 );
96 }
97 $ilDclTableEditGUI = new ilDclTableEditGUI($this);
98 $this->ctrl->forwardCommand($ilDclTableEditGUI);
99 break;
100
101 case 'ildclfieldlistgui':
102 $this->tabs->clearTargets();
103 $this->setTabs('fields');
104 $ilDclFieldListGUI = new ilDclFieldListGUI($this);
105 $this->ctrl->forwardCommand($ilDclFieldListGUI);
106 break;
107
108 case "ildclfieldeditgui":
109 $this->tabs->clearTargets();
110 $this->setTabs("fields");
111 $ilDclFieldEditGUI = new ilDclFieldEditGUI($this);
112 $this->ctrl->forwardCommand($ilDclFieldEditGUI);
113 break;
114
115 case 'ildcltableviewgui':
116 $this->tabs->clearTargets();
117 $this->setTabs('tableviews');
118 $ilDclTableViewGUI = new ilDclTableViewGUI($this);
119 $this->ctrl->forwardCommand($ilDclTableViewGUI);
120 break;
121
122 default:
123 $this->ctrl->clearParameterByClass(ilObjDataCollectionGUI::class, 'table_id');
124 $this->$cmd();
125 }
126 }
127
128 public function listTables(): void
129 {
130
131 $add_new = $this->ui_factory->button()->primary(
132 $this->lng->txt("dcl_add_new_table"),
133 $this->ctrl->getLinkTargetByClass('ilDclTableEditGUI', 'create')
134 );
135 $this->toolbar->addStickyItem($add_new);
136
137 $this->tpl->setContent(
138 $this->renderer->render(
139 $this->ui_factory->panel()->listing()->standard(
140 $this->lng->txt('dcl_tables'),
141 [$this->ui_factory->item()->group('', $this->getItems())]
142 )
143 )
144 );
145 }
146
147 protected function getItems(): array
148 {
149 $items = [];
150 foreach ($this->parent_obj->getDataCollectionObject()->getTables() as $table) {
151
152 $this->ctrl->setParameterByClass(ilObjDataCollectionGUI::class, 'table_id', $table->getId());
153 $item = $this->ui_factory->item()->standard(
154 $this->ui_factory->link()->standard(
155 $table->getTitle(),
156 $this->ctrl->getLinkTargetByClass(ilDclFieldListGUI::class, 'listFields')
157 )
158 )
159 ->withProperties([
160 $this->lng->txt('visible') => $this->lng->txt($table->getIsVisible() ? 'yes' : 'no'),
161 $this->lng->txt('comments') => $this->lng->txt($table->getPublicCommentsEnabled() ? 'active' : 'inactive')
162 ])
163 ->withActions(
164 $this->ui_factory->dropdown()->standard(
165 $this->getActions($table)
166 )
167 );
168
169 if ($table->getOrder() === 10) {
170 $item = $item->withDescription($this->lng->txt('default'));
171 }
172 $items[] = $item;
173 }
174 return $items;
175 }
176
177
181 protected function getActions(ilDclTable $table): array
182 {
183 $this->ctrl->setParameterByClass(ilObjDataCollectionGUI::class, 'table_id', $table->getId());
184
185 $actions = [];
186 $actions[] = $this->ui_factory->button()->shy(
187 $this->lng->txt('settings'),
188 $this->ctrl->getLinkTargetByClass(ilDclTableEditGUI::class, 'edit'),
189 );
190
191 $actions[] = $this->ui_factory->button()->shy(
192 $this->lng->txt('dcl_list_fields'),
193 $this->ctrl->getLinkTargetByClass(ilDclFieldListGUI::class, 'listFields')
194 );
195
196 $actions[] = $this->ui_factory->button()->shy(
197 $this->lng->txt('dcl_tableviews'),
198 $this->ctrl->getLinkTargetByClass(ilDclTableViewGUI::class, 'show')
199 );
200
201 $actions[] = $this->ui_factory->button()->shy(
202 $this->lng->txt('delete'),
203 $this->ctrl->getLinkTargetByClass(ilDclTableEditGUI::class, 'confirmDelete')
204 );
205
206 if ($table->getOrder() !== 10) {
207 $actions[] = $this->ui_factory->button()->shy(
208 $this->lng->txt('set_as_default'),
209 $this->ctrl->getLinkTargetByClass(ilDclTableEditGUI::class, 'setAsDefault')
210 );
211 }
212
213 return $actions;
214 }
215
216 protected function setTabs(string $active): void
217 {
218 $this->tabs->setBackTarget($this->lng->txt('dcl_tables'), $this->ctrl->getLinkTarget($this, 'listTables'));
219 $this->tabs->addTab(
220 'settings',
221 $this->lng->txt('settings'),
222 $this->ctrl->getLinkTargetByClass('ilDclTableEditGUI', 'edit')
223 );
224 $this->tabs->addTab(
225 'fields',
226 $this->lng->txt('dcl_list_fields'),
227 $this->ctrl->getLinkTargetByClass('ilDclFieldListGUI', 'listFields')
228 );
229 $this->tabs->addTab(
230 'tableviews',
231 $this->lng->txt('dcl_tableviews'),
232 $this->ctrl->getLinkTargetByClass('ilDclTableViewGUI')
233 );
234 $this->tabs->activateTab($active);
235 }
236
237 protected function save(): void
238 {
239 if ($this->http->wrapper()->post()->has("comments")) {
240 $comments = $this->http->wrapper()->post()->retrieve(
241 'comments',
242 $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->string())
243 );
244 }
245 if ($this->http->wrapper()->post()->has("visible")) {
246 $visible = $this->http->wrapper()->post()->retrieve(
247 'visible',
248 $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->string())
249 );
250 }
251 $orders = $this->http->wrapper()->post()->retrieve(
252 'order',
253 $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->string())
254 );
255 asort($orders);
256 $order = 10;
257 foreach (array_keys($orders) as $table_id) {
258 $table = ilDclCache::getTableCache($table_id);
259 $table->setOrder($order);
260 $table->setPublicCommentsEnabled(isset($comments[$table_id]));
261 $table->setIsVisible(isset($visible[$table_id]));
262 $table->doUpdate();
263 $order += 10;
264 }
265 $this->ctrl->redirect($this);
266 }
267
268 protected function checkAccess(): bool
269 {
270 $ref_id = $this->parent_obj->getRefId();
271
273 }
274
276 {
277 return $this->parent_obj->getDataCollectionObject();
278 }
279}
renderer()
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
Class ilCtrl provides processing control methods.
static getTableCache(?int $table_id=null)
@ilCtrl_Calls ilDclTableListGUI: ilDclFieldListGUI, ilDclFieldEditGUI, ilDclTableViewGUI,...
ILIAS UI Factory $ui_factory
executeCommand()
execute command
ILIAS UI Renderer $renderer
__construct(ilObjDataCollectionGUI $a_parent_obj)
ILIAS Refinery Factory $refinery
getActions(ilDclTable $table)
ilGlobalTemplateInterface $tpl
ilObjDataCollectionGUI $parent_obj
ILIAS HTTP Services $http
@ilCtrl_Calls ilDclTableViewGUI: ilDclTableViewEditGUI
getId()
Get table id.
language handling
static hasWriteAccess(int $ref, ?int $user_id=0)
@ilCtrl_Calls ilObjDataCollectionGUI: ilInfoScreenGUI, ilNoteGUI, ilCommonActionDispatcherGUI @ilCtrl...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:66
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26
$comments