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