ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjComponentSettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
28{
29 private const TYPE = 'cmps';
30
31 private const TAB_PLUGINS = "plugins";
32 private const TAB_PERMISSION = "perm_settings";
33
34 public const CMD_DEFAULT = "listPlugins";
35 public const CMD_INSTALL_PLUGIN = "installPlugin";
36 public const CMD_CONFIGURE = "configure";
37 public const CMD_REFRESH_LANGUAGES = "refreshLanguages";
38 public const CMD_ACTIVATE_PLUGIN = "activatePlugin";
39 public const CMD_DEACTIVATE_PLUGIN = "deactivatePlugin";
40 public const CMD_UPDATE_PLUGIN = "updatePlugin";
41 public const CMD_JUMP_TO_PLUGIN_SLOT = "jumpToPluginSlot";
42 public const CMD_UNINSTALL_PLUGIN = "uninstallPlugin";
43 public const CMD_CONFIRM_UNINSTALL_PLUGIN = "confirmUninstallPlugin";
44
45 public const P_REF_ID = 'ref_id';
46 public const P_CTYPE = "ctype";
47 public const P_CNAME = "cname";
48 public const P_SLOT_ID = "slot_id";
49 public const P_PLUGIN_NAME = "pname";
50 public const P_PLUGIN_ID = "plugin_id";
51 public const P_ADMIN_MODE = 'admin_mode';
52
53 protected ilTabsGUI $tabs;
55 protected ilDBInterface $db;
61 protected Factory $ui;
63
64 public function __construct($data, int $id, bool $call_by_reference = true, bool $prepare_output = true)
65 {
67
68 global $DIC;
69
70 $this->tabs = $DIC->tabs();
71 $this->ctrl = $DIC->ctrl();
72 $this->rbac_system = $DIC->rbac()->system();
73 $this->db = $DIC->database();
74 $this->type = self::TYPE;
75 $this->component_repository = $DIC["component.repository"];
76 $this->component_factory = $DIC["component.factory"];
77 $this->error = $DIC["ilErr"];
78 $this->refinery = $DIC->refinery();
79 $this->request_wrapper = $DIC->http()->wrapper()->query();
80 $this->ui = $DIC->ui()->factory();
81 $this->renderer = $DIC->ui()->renderer();
82
83 $this->lng->loadLanguageModule(self::TYPE);
84 }
85
86 public function getUnsafeGetCommands(): array
87 {
88 return [
93 ];
94 }
95
96 public function getSafePostCommands(): array
97 {
98 return [];
99 }
100
101 public function executeCommand(): void
102 {
103 $next_class = $this->ctrl->getNextClass($this);
104 $cmd = $this->ctrl->getCmd();
105
106 $this->prepareOutput();
107
108 if (!$this->rbac_system->checkAccess('read', $this->object->getRefId())) {
109 $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
110 }
111
112 switch (true) {
113 case $next_class === 'ilpermissiongui':
114 $this->tabs->activateTab(self::TAB_PERMISSION);
115 $perm_gui = new ilPermissionGUI($this);
116 $this->ctrl->forwardCommand($perm_gui);
117 break;
118 case preg_match("/configgui$/i", $next_class):
119 $this->forwardConfigGUI($next_class);
120 break;
121 default:
122 switch ($cmd) {
124 $this->installPlugin();
125 break;
127 $this->refreshLanguages();
128 break;
130 $this->activatePlugin();
131 break;
133 $this->deactivatePlugin();
134 break;
136 $this->updatePlugin();
137 break;
139 $this->confirmUninstallPlugin();
140 break;
142 $this->uninstallPlugin();
143 break;
144 default:
145 $this->listPlugins();
146 }
147 }
148 }
149
150 protected function forwardConfigGUI(string $name): void
151 {
152 $name = $this->ctrl->lookupOriginalClassName($name);
153
154 if (!class_exists($name)) {
155 throw new Exception("class $name not found!");
156 }
157
158 $plugin = $this->getPlugin();
159 $gui = new $name();
160 $gui->setPluginObject($plugin);
161
162 $this->ctrl->forwardCommand($gui);
163 }
164
165 protected function installPlugin(): void
166 {
167 $pl = $this->getPlugin();
168
169 $pl->install();
170 $this->update($pl);
171 }
172
173 protected function update(ilPlugin $plugin): void
174 {
175 try {
176 $plugin->update();
177 $this->tpl->setOnScreenMessage("success", $this->lng->txt("cmps_plugin_updated"), true);
178 } catch (Exception $e) {
179 $this->tpl->setOnScreenMessage("failure", $e->getMessage(), true);
180 }
181
182 $this->ctrl->redirectByClass(ilAdministrationGUI::class, self::CMD_JUMP_TO_PLUGIN_SLOT);
183 }
184
185 protected function refreshLanguages(): void
186 {
187 try {
188 $plugin_name = $this->request_wrapper->retrieve(self::P_PLUGIN_NAME, $this->refinery->kindlyTo()->string());
189 $plugin = $this->component_repository->getPluginByName($plugin_name);
190 $language_handler = new ilPluginLanguage($plugin);
191 $language_handler->updateLanguages();
192 $this->tpl->setOnScreenMessage("success", $this->lng->txt("cmps_refresh_lng"), true);
193 } catch (Exception $e) {
194 $this->tpl->setOnScreenMessage("failure", $e->getMessage(), true);
195 }
196 $this->ctrl->redirect($this, self::CMD_DEFAULT);
197 }
198
199 protected function activatePlugin(): void
200 {
201 $pl = $this->getPlugin();
202
203 try {
204 $pl->activate();
205 $this->tpl->setOnScreenMessage("success", $this->lng->txt("cmps_plugin_activated"), true);
206 } catch (Exception $e) {
207 $this->tpl->setOnScreenMessage("failure", $e->getMessage(), true);
208 }
209
210 $this->ctrl->redirect($this, self::CMD_DEFAULT);
211 }
212
213 protected function deactivatePlugin(): void
214 {
215 $pl = $this->getPlugin();
216
217 try {
218 $pl->deactivate();
219 $this->tpl->setOnScreenMessage("success", $this->lng->txt("cmps_plugin_deactivated"), true);
220 } catch (InvalidArgumentException $e) {
221 $this->tpl->setOnScreenMessage("failure", $e->getMessage(), true);
222 }
223
224 $this->ctrl->redirect($this, self::CMD_DEFAULT);
225 }
226
227 protected function updatePlugin(): void
228 {
229 $pl = $this->getPlugin();
230 $this->update($pl);
231 }
232
233 protected function confirmUninstallPlugin(): void
234 {
235 $pl = $this->getPlugin();
236
237 $plugin_name = $this->request_wrapper->retrieve(self::P_PLUGIN_NAME, $this->refinery->kindlyTo()->string());
238
239 $pl_info = $this->component_repository->getPluginByName($plugin_name);
240
241 if ($pl_info->isActivated() || $pl_info->isActivationPossible()) {
242 $question = sprintf(
243 $this->lng->txt("cmps_uninstall_confirm"),
244 $pl->getPluginName()
245 );
246 } else {
247 $question = sprintf(
248 $this->lng->txt("cmps_uninstall_inactive_confirm"),
249 $pl->getPluginName(),
250 $pl_info->getReasonForInactivity()
251 );
252 }
253
254 $this->ctrl->setParameter($this, self::P_PLUGIN_NAME, $pl_info->getName());
255 $buttons = array(
256 $this->ui->button()->standard(
257 $this->lng->txt('confirm'),
258 $this->ctrl->getLinkTarget($this, self::CMD_UNINSTALL_PLUGIN)
259 ),
260 $this->ui->button()->standard(
261 $this->lng->txt('cancel'),
262 $this->ctrl->getLinkTarget($this, 'showQuestionList')
263 )
264 );
265
266 $this->tpl->setContent($this->renderer->render($this->ui->messageBox()->confirmation($question)->withButtons($buttons)));
267 }
268
269 protected function uninstallPlugin(): void
270 {
271 $pl = $this->getPlugin();
272
273 try {
274 $pl->uninstall();
275 $this->tpl->setOnScreenMessage("success", $this->lng->txt("cmps_plugin_deinstalled"), true);
276 } catch (Exception $e) {
277 $this->tpl->setOnScreenMessage("failure", $e->getMessage(), true);
278 }
279
280 $this->ctrl->redirect($this, self::CMD_DEFAULT);
281 }
282
283 protected function getPlugin(): ilPlugin
284 {
285 $plugin_name = $this->request_wrapper->retrieve(self::P_PLUGIN_NAME, $this->refinery->kindlyTo()->string());
286 return $this->component_factory->getPlugin(
287 $this->component_repository->getPluginByName($plugin_name)->getId()
288 );
289 }
290
291 protected function listPlugins(): void
292 {
293 $this->tabs->activateTab(self::TAB_PLUGINS);
294
295 $filters = new ilPluginsOverviewTableFilterGUI($this);
296
297 $plugins = [];
298 foreach ($this->component_repository->getPlugins() as $plugin) {
299 $plugins[] = $plugin;
300 }
301
302 $table = new ilPluginsOverviewTable(
303 $this,
304 $this->ctrl,
305 $this->ui,
306 $this->renderer,
307 $this->lng,
308 $filters->getData()
309 );
310
311 $table = $table->withData($plugins)->getTable();
312
313 $this->tpl->setContent($filters->getHTML() . $table);
314 }
315
316 public function getAdminTabs(): void
317 {
318 if ($this->rbac_system->checkAccess("visible,read", $this->object->getRefId())) {
319 $this->tabs_gui->addTab(
320 self::TAB_PLUGINS,
321 $this->lng->txt("cmps_plugins"),
322 $this->ctrl->getLinkTarget($this, self::CMD_DEFAULT)
323 );
324 }
325
326 if ($this->rbac_system->checkAccess('edit_permission', $this->object->getRefId())) {
327 $this->tabs_gui->addTab(
328 "perm_settings",
329 $this->lng->txt("perm_settings"),
330 $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm")
331 );
332 }
333
334 if (
335 $this->request_wrapper->has(self::P_CTYPE) &&
336 $this->request_wrapper->retrieve(self::P_CTYPE, $this->refinery->kindlyTo()->string()) === "components/ILIAS"
337 ) {
338 $this->tabs_gui->activateTab("services");
339 }
340 }
341}
renderer()
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
error(string $a_errmsg)
Error Handling & global info handling.
@ilCtrl_Calls ilObjComponentSettingsGUI: ilPermissionGUI
ILIAS HTTP Wrapper RequestWrapper $request_wrapper
getUnsafeGetCommands()
This method must return a list of unsafe GET commands.
getAdminTabs()
administration tabs show only permissions and trash folder
getSafePostCommands()
This method must return a list of safe POST commands.
__construct($data, int $id, bool $call_by_reference=true, bool $prepare_output=true)
Class ilObjectGUI Basic methods of all Output classes.
prepareOutput(bool $show_sub_objects=true)
Class ilPluginsOverviewTableFilterGUI.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface RequestWrapper.
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
Readable part of repository interface to ilComponentDataDB.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26