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