ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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 $this->table->getId()
142 );
143
144 $this->tpl->setContent(
145 $this->renderer->render(
146 $this->ui_factory->panel()->listing()->standard(
147 sprintf($this->lng->txt('dcl_tableviews_of_X'), $this->table->getTitle()),
148 [$this->ui_factory->item()->group('', $this->getItems())]
149 )
150 )
151 );
152 }
153
154 protected function getItems(): array
155 {
156 $items = [];
157 foreach ($this->table->getTableViews() as $tableview) {
158
159 $this->ctrl->setParameterByClass(ilDclTableViewEditGUI::class, 'tableview_id', $tableview->getId());
160 $item = $this->ui_factory->item()->standard(
161 $this->ui_factory->link()->standard(
162 $tableview->getTitle(),
163 $this->ctrl->getLinkTargetByClass(ilDclTableViewEditGUI::class, 'show')
164 )
165 )
166 ->withDescription($tableview->getDescription())
167 ->withActions($this->ui_factory->dropdown()->standard($this->getActions($tableview)));
168
169 $items[] = $item;
170 }
171 return $items;
172 }
173
177 protected function getActions(ilDclTableView $tableview): array
178 {
179 $this->ctrl->setParameterByClass(ilDclTableViewEditGUI::class, 'tableview_id', $tableview->getId());
180
181 $actions = [];
182 $actions[] = $this->ui_factory->button()->shy(
183 $this->lng->txt('edit'),
184 $this->ctrl->getLinkTargetByClass(ilDclTableViewEditGUI::class, 'editGeneralSettings')
185 );
186 $actions[] = $this->ui_factory->button()->shy(
187 $this->lng->txt('copy'),
188 $this->ctrl->getLinkTargetByClass(ilDclTableViewEditGUI::class, 'copy')
189 );
190 $actions[] = $this->ui_factory->button()->shy(
191 $this->lng->txt('delete'),
192 $this->ctrl->getLinkTargetByClass(ilDclTableViewEditGUI::class, 'confirmDelete')
193 );
194 return $actions;
195 }
196
201 public function checkViewsLeft(int $delete_count): void
202 {
203 if ($delete_count >= count($this->table->getTableViews())) {
204 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_msg_tableviews_delete_all'), true);
205 $this->ctrl->redirect($this, 'show');
206 }
207 }
208}
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
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