ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilPluginsOverviewTable.php
Go to the documentation of this file.
1 <?php
2 
20 declare(strict_types=1);
21 
26 
28 {
29  public const F_PLUGIN_NAME = "plugin_name";
30  public const F_PLUGIN_ID = "plugin_id";
31  public const F_SLOT_NAME = "slot_name";
32  public const F_COMPONENT_NAME = "component_name";
33  public const F_PLUGIN_ACTIVE = "plugin_active";
34 
36  protected ilCtrl $ctrl;
37  protected Factory $ui;
38  protected Renderer $renderer;
39  protected ilLanguage $lng;
40  protected array $filter;
41  protected array $data = [];
42 
43  public function __construct(
44  ilObjComponentSettingsGUI $parent_gui,
45  ilCtrl $ctrl,
46  Factory $ui,
47  Renderer $renderer,
48  ilLanguage $lng,
49  array $filter
50  ) {
51  $this->parent_gui = $parent_gui;
52  $this->ctrl = $ctrl;
53  $this->ui = $ui;
54  $this->renderer = $renderer;
55  $this->lng = $lng;
56  $this->filter = $filter;
57  }
58 
59  public function getTable(): string
60  {
61  return $this->renderer->render($this->ui->table()->presentation(
62  'Plugins',
63  [],
64  function ($row, ilPluginInfo $record, $ui_factory) {
65  return $row
66  ->withHeadline($record->getName())
67  ->withSubHeadline($record->getPluginSlot()->getName())
68  ->withImportantFields($this->getImportantFields($record))
69  ->withContent(
70  $ui_factory->listing()->descriptive($this->getContent($record))
71  )
72  ->withAction($this->getActions($record))
73  ;
74  }
75  )->withData($this->filterData($this->getData())));
76  }
77 
78  protected function getImportantFields(ilPluginInfo $plugin_info): array
79  {
80  $fields = [];
81 
82  if ($plugin_info->isInstalled()) {
83  $fields[] = $this->lng->txt("installed");
84  } else {
85  $fields[] = $this->lng->txt("not_installed");
86  }
87 
88  if ($plugin_info->isActive()) {
89  $fields[] = $this->lng->txt("cmps_active");
90  } else {
91  $fields[] = $this->lng->txt("inactive");
92  }
93 
94  if ($plugin_info->isUpdateRequired()) {
95  $fields[] = $this->lng->txt("cmps_needs_update");
96  }
97 
98  return $fields;
99  }
100 
101  protected function getContent(ilPluginInfo $plugin_info): array
102  {
103  return [
104  $this->lng->txt("cmps_is_installed") => $this->boolToString($plugin_info->isInstalled()),
105  $this->lng->txt("cmps_is_active") => $this->boolToString($plugin_info->isActive()),
106  $this->lng->txt("cmps_needs_update") => $this->boolToString($plugin_info->isUpdateRequired()),
107  $this->lng->txt("cmps_id") => $plugin_info->getId(),
108  $this->lng->txt("cmps_plugin_slot") => $plugin_info->getPluginSlot()->getName(),
109  $this->lng->txt("cmps_current_version") => (string) $plugin_info->getCurrentVersion(),
110  $this->lng->txt("cmps_available_version") => (string) $plugin_info->getAvailableVersion(),
111  $this->lng->txt("cmps_current_db_version") => (string) $plugin_info->getCurrentDBVersion(),
112  $this->lng->txt("cmps_ilias_min_version") => (string) $plugin_info->getMinimumILIASVersion(),
113  $this->lng->txt("cmps_ilias_max_version") => (string) $plugin_info->getMaximumILIASVersion(),
114  $this->lng->txt("cmps_responsible") => $plugin_info->getResponsible(),
115  $this->lng->txt("cmps_responsible_mail") => $plugin_info->getResponsibleMail(),
116  $this->lng->txt("cmps_supports_learning_progress") => $this->boolToString($plugin_info->supportsLearningProgress()),
117  $this->lng->txt("cmps_supports_export") => $this->boolToString($plugin_info->supportsExport()),
118  $this->lng->txt("cmps_supports_cli_setup") => $this->boolToString($plugin_info->supportsCLISetup())
119  ];
120  }
121 
122  protected function boolToString(bool $value): string
123  {
124  if ($value) {
125  return $this->lng->txt("yes");
126  }
127  return $this->lng->txt("no");
128  }
129 
134  protected function filterData(array $data): array
135  {
136  $active_filters = array_filter($this->filter, static function ($value): bool {
137  return !empty($value);
138  });
139  $plugins = array_filter($data, static function (ilPluginInfo $plugin_info) use ($active_filters): bool {
140  $matches_filter = true;
141  if (isset($active_filters[self::F_PLUGIN_NAME])) {
142  $matches_filter = strpos($plugin_info->getName(), $active_filters[self::F_PLUGIN_NAME]) !== false;
143  }
144  if (isset($active_filters[self::F_PLUGIN_ID])) {
145  $matches_filter = strpos($plugin_info->getId(), $active_filters[self::F_PLUGIN_ID]) !== false;
146  }
147  if (isset($active_filters[self::F_PLUGIN_ACTIVE])) {
148  $v = (int) $active_filters[self::F_PLUGIN_ACTIVE] === 1;
149  $matches_filter = $plugin_info->isActive() === $v && $matches_filter;
150  }
151  if (isset($active_filters[self::F_SLOT_NAME])) {
152  $matches_filter = $matches_filter && in_array(
153  $plugin_info->getPluginSlot()->getName(),
154  $active_filters[self::F_SLOT_NAME],
155  true
156  );
157  }
158  if (isset($active_filters[self::F_COMPONENT_NAME])) {
159  $matches_filter = $matches_filter && in_array(
160  $plugin_info->getComponent()->getQualifiedName(),
161  $active_filters[self::F_COMPONENT_NAME],
162  true
163  );
164  }
165 
166  return $matches_filter;
167  });
168 
169  return $plugins;
170  }
171 
172  public function withData(array $data): ilPluginsOverviewTable
173  {
174  $clone = clone $this;
175  $clone->data = $data;
176  return $clone;
177  }
178 
179  protected function getData(): array
180  {
181  return $this->data;
182  }
183 
184  protected function getActions(ilPluginInfo $plugin_info): Dropdown
185  {
186  $this->setParameter($plugin_info);
187 
188  $items = [];
189 
190  if (!$plugin_info->isInstalled()) {
191  $items[] = $this->getDropdownButton("cmps_install", ilObjComponentSettingsGUI::CMD_INSTALL_PLUGIN);
192  $this->clearParameter();
193  return $this->ui->dropdown()->standard($items);
194  }
195 
196  if (class_exists($plugin_info->getConfigGUIClassName())) {
197  $items[] = $this->ui->button()->shy(
198  $this->lng->txt("cmps_configure"),
199  $this->ctrl->getLinkTargetByClass(
200  $plugin_info->getConfigGUIClassName(),
202  )
203  );
204  }
205 
206  if ($this->hasLang($plugin_info)) {
207  $items[] = $this->getDropdownButton("cmps_refresh", ilObjComponentSettingsGUI::CMD_REFRESH_LANGUAGES);
208  }
209 
210  if ($plugin_info->isActive()) {
211  $items[] = $this->getDropdownButton("cmps_deactivate", ilObjComponentSettingsGUI::CMD_DEACTIVATE_PLUGIN);
212  }
213 
214  if ($plugin_info->isActivationPossible() && !$plugin_info->isActive()) {
215  $items[] = $this->getDropdownButton("cmps_activate", ilObjComponentSettingsGUI::CMD_ACTIVATE_PLUGIN);
216  }
217 
218  if ($plugin_info->isUpdateRequired()) {
219  $items[] = $this->getDropdownButton("cmps_update", ilObjComponentSettingsGUI::CMD_UPDATE_PLUGIN);
220  }
221 
223 
224  $this->clearParameter();
225 
226  return $this->ui->dropdown()->standard($items);
227  }
228 
229  protected function setParameter(ilPluginInfo $plugin): void
230  {
231  $this->ctrl->setParameter($this->parent_gui, ilObjComponentSettingsGUI::P_PLUGIN_ID, $plugin->getId());
232  $this->ctrl->setParameter($this->parent_gui, ilObjComponentSettingsGUI::P_CTYPE, $plugin->getComponent()->getType());
233  $this->ctrl->setParameter($this->parent_gui, ilObjComponentSettingsGUI::P_CNAME, $plugin->getComponent()->getName());
234  $this->ctrl->setParameter($this->parent_gui, ilObjComponentSettingsGUI::P_SLOT_ID, $plugin->getPluginSlot()->getId());
235  $this->ctrl->setParameter($this->parent_gui, ilObjComponentSettingsGUI::P_PLUGIN_NAME, $plugin->getName());
236  }
237 
238  protected function clearParameter(): void
239  {
240  $this->ctrl->setParameter($this->parent_gui, ilObjComponentSettingsGUI::P_CTYPE, null);
241  $this->ctrl->setParameter($this->parent_gui, ilObjComponentSettingsGUI::P_CNAME, null);
242  $this->ctrl->setParameter($this->parent_gui, ilObjComponentSettingsGUI::P_SLOT_ID, null);
243  $this->ctrl->setParameter($this->parent_gui, ilObjComponentSettingsGUI::P_PLUGIN_NAME, null);
244  }
245 
246  protected function getDropdownButton(string $caption, string $command): Shy
247  {
248  return $this->ui->button()->shy(
249  $this->lng->txt($caption),
250  $this->ctrl->getLinkTarget($this->parent_gui, $command)
251  );
252  }
253 
254  protected function hasLang(ilPluginInfo $plugin_info): bool
255  {
256  $language_handler = new ilPluginLanguage($plugin_info);
257  return $language_handler->hasAvailableLangFiles();
258  }
259 }
getImportantFields(ilPluginInfo $plugin_info)
hasLang(ilPluginInfo $plugin_info)
ilObjComponentSettingsGUI $parent_gui
withAction(URI|Signal|string $action)
getActions(ilPluginInfo $plugin_info)
isActive()
Is this plugin active right now?
getContent(ilPluginInfo $plugin_info)
__construct(ilObjComponentSettingsGUI $parent_gui, ilCtrl $ctrl, Factory $ui, Renderer $renderer, ilLanguage $lng, array $filter)
isInstalled()
"Installed" tells if the plugin has some installed version.
isActivationPossible()
Can this plugin be activated right now.
This describes commonalities between all types of Dropdowns.
Definition: Dropdown.php:34
isUpdateRequired()
"Update required" tells if the plugin needs an update.
This is how the factory for UI elements looks.
Definition: Factory.php:37
Simple value class for information about a plugin.
ilObjComponentSettingsGUI: ilPermissionGUI
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
getDropdownButton(string $caption, string $command)