ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilDclTableListGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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  $tableHelper = new ilDclTableHelper(
87  $this->getObjId(),
88  $ref_id,
89  $DIC->rbac()->review(),
90  $DIC->user(),
91  $DIC->database()
92  );
93  $role_titles = $tableHelper->getRoleTitlesWithoutReadRightOnAnyStandardView();
94 
95  if (count($role_titles) > 0) {
96  $this->tpl->setOnScreenMessage(
97  'info',
98  $this->lng->txt('dcl_rbac_roles_without_read_access_on_any_standard_view') . " " . implode(
99  ", ",
100  $role_titles
101  )
102  );
103  }
104 
105  switch ($next_class) {
106  case 'ildcltableeditgui':
107  $this->tabs->clearTargets();
108  if ($cmd != 'create') {
109  $this->setTabs('settings');
110  } else {
111  $this->tabs->setBackTarget(
112  $this->lng->txt('back'),
113  $this->ctrl->getLinkTarget($this, 'listTables')
114  );
115  }
116  $ilDclTableEditGUI = new ilDclTableEditGUI($this);
117  $this->ctrl->forwardCommand($ilDclTableEditGUI);
118  break;
119 
120  case 'ildclfieldlistgui':
121  $this->tabs->clearTargets();
122  $this->setTabs('fields');
123  $ilDclFieldListGUI = new ilDclFieldListGUI($this);
124  $this->ctrl->forwardCommand($ilDclFieldListGUI);
125  break;
126 
127  case "ildclfieldeditgui":
128  $this->tabs->clearTargets();
129  $this->setTabs("fields");
130  $ilDclFieldEditGUI = new ilDclFieldEditGUI($this);
131  $this->ctrl->forwardCommand($ilDclFieldEditGUI);
132  break;
133 
134  case 'ildcltableviewgui':
135  $this->tabs->clearTargets();
136  $this->setTabs('tableviews');
137  $ilDclTableViewGUI = new ilDclTableViewGUI($this);
138  $this->ctrl->forwardCommand($ilDclTableViewGUI);
139  break;
140 
141  default:
142  $this->ctrl->clearParameterByClass(ilObjDataCollectionGUI::class, 'table_id');
143  $this->$cmd();
144  }
145  }
146 
147  public function listTables(): void
148  {
149 
150  $add_new = $this->ui_factory->button()->primary(
151  $this->lng->txt("dcl_add_new_table"),
152  $this->ctrl->getLinkTargetByClass('ilDclTableEditGUI', 'create')
153  );
154  $this->toolbar->addStickyItem($add_new);
155 
156  $this->tpl->setContent(
157  $this->renderer->render(
158  $this->ui_factory->panel()->listing()->standard(
159  $this->lng->txt('dcl_tables'),
160  [$this->ui_factory->item()->group('', $this->getItems())]
161  )
162  )
163  );
164  }
165 
166  protected function getItems(): array
167  {
168  $items = [];
169  foreach ($this->parent_obj->getDataCollectionObject()->getTables() as $table) {
170 
171  $this->ctrl->setParameterByClass(ilObjDataCollectionGUI::class, 'table_id', $table->getId());
172  $item = $this->ui_factory->item()->standard(
173  $this->ui_factory->link()->standard(
174  $table->getTitle(),
175  $this->ctrl->getLinkTargetByClass(ilDclFieldListGUI::class, 'listFields')
176  )
177  )
178  ->withProperties([
179  $this->lng->txt('visible') => $this->lng->txt($table->getIsVisible() ? 'yes' : 'no'),
180  $this->lng->txt('comments') => $this->lng->txt($table->getPublicCommentsEnabled() ? 'active' : 'inactive')
181  ])
182  ->withActions(
183  $this->ui_factory->dropdown()->standard(
184  $this->getActions($table)
185  )
186  );
187 
188  if ($table->getOrder() === 10) {
189  $item = $item->withDescription($this->lng->txt('default'));
190  }
191  $items[] = $item;
192  }
193  return $items;
194  }
195 
196 
200  protected function getActions(ilDclTable $table): array
201  {
202  $this->ctrl->setParameterByClass(ilObjDataCollectionGUI::class, 'table_id', $table->getId());
203 
204  $actions = [];
205  $actions[] = $this->ui_factory->button()->shy(
206  $this->lng->txt('settings'),
207  $this->ctrl->getLinkTargetByClass(ilDclTableEditGUI::class, 'edit'),
208  );
209 
210  $actions[] = $this->ui_factory->button()->shy(
211  $this->lng->txt('dcl_list_fields'),
212  $this->ctrl->getLinkTargetByClass(ilDclFieldListGUI::class, 'listFields')
213  );
214 
215  $actions[] = $this->ui_factory->button()->shy(
216  $this->lng->txt('dcl_tableviews'),
217  $this->ctrl->getLinkTargetByClass(ilDclTableViewGUI::class, 'show')
218  );
219 
220  $actions[] = $this->ui_factory->button()->shy(
221  $this->lng->txt('delete'),
222  $this->ctrl->getLinkTargetByClass(ilDclTableEditGUI::class, 'confirmDelete')
223  );
224 
225  if ($table->getOrder() !== 10) {
226  $actions[] = $this->ui_factory->button()->shy(
227  $this->lng->txt('set_as_default'),
228  $this->ctrl->getLinkTargetByClass(ilDclTableEditGUI::class, 'setAsDefault')
229  );
230  }
231 
232  return $actions;
233  }
234 
235  protected function setTabs(string $active): void
236  {
237  $this->tabs->setBackTarget($this->lng->txt('dcl_tables'), $this->ctrl->getLinkTarget($this, 'listTables'));
238  $this->tabs->addTab(
239  'settings',
240  $this->lng->txt('settings'),
241  $this->ctrl->getLinkTargetByClass('ilDclTableEditGUI', 'edit')
242  );
243  $this->tabs->addTab(
244  'fields',
245  $this->lng->txt('dcl_list_fields'),
246  $this->ctrl->getLinkTargetByClass('ilDclFieldListGUI', 'listFields')
247  );
248  $this->tabs->addTab(
249  'tableviews',
250  $this->lng->txt('dcl_tableviews'),
251  $this->ctrl->getLinkTargetByClass('ilDclTableViewGUI')
252  );
253  $this->tabs->activateTab($active);
254  }
255 
256  protected function save(): void
257  {
258  if ($this->http->wrapper()->post()->has("comments")) {
259  $comments = $this->http->wrapper()->post()->retrieve(
260  'comments',
261  $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->string())
262  );
263  }
264  if ($this->http->wrapper()->post()->has("visible")) {
265  $visible = $this->http->wrapper()->post()->retrieve(
266  'visible',
267  $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->string())
268  );
269  }
270  $orders = $this->http->wrapper()->post()->retrieve(
271  'order',
272  $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->string())
273  );
274  asort($orders);
275  $order = 10;
276  foreach (array_keys($orders) as $table_id) {
277  $table = ilDclCache::getTableCache($table_id);
278  $table->setOrder($order);
279  $table->setPublicCommentsEnabled(isset($comments[$table_id]));
280  $table->setIsVisible(isset($visible[$table_id]));
281  $table->doUpdate();
282  $order += 10;
283  }
284  $this->ctrl->redirect($this);
285  }
286 
287  protected function checkAccess(): bool
288  {
289  $ref_id = $this->parent_obj->getRefId();
290 
292  }
293 
295  {
296  return $this->parent_obj->getDataCollectionObject();
297  }
298 }
ilObjDataCollectionGUI $parent_obj
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilDclTableViewGUI: ilDclTableViewEditGUI
ilDclTableListGUI: ilDclFieldListGUI, ilDclFieldEditGUI, ilDclTableViewGUI, ilDclTableEditGUI ...
getId()
Get table id.
getActions(ilDclTable $table)
ilObjDataCollectionGUI: ilInfoScreenGUI, ilNoteGUI, ilCommonActionDispatcherGUI ilObjDataCollectionG...
__construct(ilObjDataCollectionGUI $a_parent_obj)
$ref_id
Definition: ltiauth.php:66
static http()
Fetches the global http state from ILIAS.
executeCommand()
execute command
static getTableCache(int $table_id=null)
global $DIC
Definition: shib_login.php:25
$comments
static hasWriteAccess(int $ref, ?int $user_id=0)
ILIAS Refinery Factory $refinery
ILIAS HTTP Services $http
ilGlobalTemplateInterface $tpl
ILIAS UI Factory $ui_factory
ILIAS UI Renderer $renderer