ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDclTableViewGUI.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;
34 protected ilTabsGUI $tabs;
35 protected ilDclTable $table;
39
45 public function __construct(ilDclTableListGUI $a_parent_obj, int $table_id = 0)
46 {
47 global $DIC;
48
49 $locator = $DIC['ilLocator'];
50 $this->parent_obj = $a_parent_obj;
51 $this->ctrl = $DIC->ctrl();
52 $this->lng = $DIC->language();
53 $this->tpl = $DIC->ui()->mainTemplate();
54 $this->tabs = $DIC->tabs();
55 $this->toolbar = $DIC->toolbar();
56 $this->http = $DIC->http();
57 $this->refinery = $DIC->refinery();
58 $this->ui_factory = $DIC->ui()->factory();
59 $this->renderer = $DIC->ui()->renderer();
60
61 $DIC->help()->setScreenId('dcl_views');
62
63 if ($table_id == 0) {
64 $table_id = $this->http->wrapper()->query()->retrieve('table_id', $this->refinery->kindlyTo()->int());
65 }
66
67 $this->table = ilDclCache::getTableCache($table_id);
68 $this->table->getCollectionObject()->setRefId(
69 $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int())
70 );
71
72 $this->ctrl->saveParameterByClass('ilDclTableEditGUI', 'table_id');
73 $locator->addItem($this->table->getTitle(), $this->ctrl->getLinkTargetByClass('ilDclTableEditGUI', 'edit'));
74 $this->tpl->setLocator();
75
76 if (!$this->checkAccess()) {
77 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
78 $this->ctrl->redirectByClass(ilDclRecordListGUI::class, 'listRecords');
79 }
80 }
81
82 public function executeCommand(): void
83 {
84 $this->ctrl->saveParameter($this, 'table_id');
85 $cmd = $this->ctrl->getCmd("show");
86 $next_class = $this->ctrl->getNextClass($this);
87
88 switch ($next_class) {
89 case strtolower(ilDclTableViewEditGUI::class):
90 if ($this->http->wrapper()->query()->has('tableview_id')) {
91 $tableview_id = $this->http->wrapper()->query()->retrieve(
92 'tableview_id',
93 $this->refinery->kindlyTo()->int()
94 );
95 } else {
96 $tableview_id = 0;
97 }
98
99 $edit_gui = new ilDclTableViewEditGUI(
100 $this,
101 $this->table,
103 );
104 $this->ctrl->saveParameter($edit_gui, 'tableview_id');
105 $this->ctrl->forwardCommand($edit_gui);
106 break;
107 default:
108 $this->$cmd();
109 break;
110 }
111 }
112
114 {
115 return $this->parent_obj;
116 }
117
118 protected function checkAccess(): bool
119 {
121 $this->parent_obj->getDataCollectionObject()->getRefId(),
122 $this->table->getId()
123 );
124 }
125
126 public function show(): void
127 {
128 $add_new = $this->ui_factory->button()->primary(
129 $this->lng->txt("dcl_add_new_view"),
130 $this->ctrl->getLinkTargetByClass(ilDclTableViewEditGUI::class, 'add')
131 );
132 $this->toolbar->addStickyItem($add_new);
133
134 $this->toolbar->addSeparator();
135
136 $switcher = new ilDclSwitcher($this->toolbar, $this->ui_factory, $this->ctrl, $this->lng);
137 $switcher->addTableSwitcherToToolbar(
138 $this->parent_obj->getDataCollectionObject()->getTables(),
139 self::class,
140 'show'
141 );
142
143 $this->tpl->setContent(
144 $this->renderer->render(
145 $this->ui_factory->panel()->listing()->standard(
146 sprintf($this->lng->txt('dcl_tableviews_of_X'), $this->table->getTitle()),
147 [$this->ui_factory->item()->group('', $this->getItems())]
148 )
149 )
150 );
151 }
152
153 protected function getItems(): array
154 {
155 $items = [];
156 foreach ($this->table->getTableViews() as $tableview) {
157
158 $this->ctrl->setParameterByClass(ilDclTableViewEditGUI::class, 'tableview_id', $tableview->getId());
159 $item = $this->ui_factory->item()->standard(
160 $this->ui_factory->link()->standard(
161 $tableview->getTitle(),
162 $this->ctrl->getLinkTargetByClass(ilDclTableViewEditGUI::class, 'show')
163 )
164 )
165 ->withDescription($tableview->getDescription())
166 ->withActions($this->ui_factory->dropdown()->standard($this->getActions($tableview)));
167
168 $items[] = $item;
169 }
170 return $items;
171 }
172
176 protected function getActions(ilDclTableView $tableview): array
177 {
178 $this->ctrl->setParameterByClass(ilDclTableViewEditGUI::class, 'tableview_id', $tableview->getId());
179
180 $actions = [];
181 $actions[] = $this->ui_factory->button()->shy(
182 $this->lng->txt('edit'),
183 $this->ctrl->getLinkTargetByClass(ilDclTableViewEditGUI::class, 'editGeneralSettings')
184 );
185 $actions[] = $this->ui_factory->button()->shy(
186 $this->lng->txt('copy'),
187 $this->ctrl->getLinkTargetByClass(ilDclTableViewEditGUI::class, 'copy')
188 );
189 $actions[] = $this->ui_factory->button()->shy(
190 $this->lng->txt('delete'),
191 $this->ctrl->getLinkTargetByClass(ilDclTableViewEditGUI::class, 'confirmDelete')
192 );
193 return $actions;
194 }
195
200 public function checkViewsLeft(int $delete_count): void
201 {
202 if ($delete_count >= count($this->table->getTableViews())) {
203 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_msg_tableviews_delete_all'), true);
204 $this->ctrl->redirect($this, 'show');
205 }
206 }
207
211 public function saveTableViewOrder(): void
212 {
213 $orders = $this->http->wrapper()->post()->retrieve(
214 'order',
215 $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->string())
216 );
217 asort($orders);
218 $tableviews = [];
219 foreach (array_keys($orders) as $tableview_id) {
220 $tableviews[] = ilDclTableView::find($tableview_id);
221 }
222 $this->table->sortTableViews($tableviews);
223 $this->tpl->setOnScreenMessage('success', $this->lng->txt('dcl_msg_tableviews_order_updated'));
224 $this->ctrl->redirect($this);
225 }
226}
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,...
@ilCtrl_Calls ilDclTableViewEditGUI: ilDclDetailedViewDefinitionGUI @ilCtrl_Calls ilDclTableViewEditG...
@ilCtrl_Calls ilDclTableViewGUI: ilDclTableViewEditGUI
ILIAS UI Renderer $renderer
ILIAS Refinery Factory $refinery
__construct(ilDclTableListGUI $a_parent_obj, int $table_id=0)
Constructor.
checkViewsLeft(int $delete_count)
redirects if there are no tableviews left after deletion of {$delete_count} tableviews
ILIAS UI Factory $ui_factory
getActions(ilDclTableView $tableview)
ILIAS HTTP Services $http
ilGlobalTemplateInterface $tpl
saveTableViewOrder()
invoked by ilDclTableViewTableGUI
ilDclTableListGUI $parent_obj
static findOrGetInstance($primary_key, array $add_constructor_args=[])
language handling
static hasAccessToEditTable(int $ref_id, int $table_id)
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...
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26