ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilPluginsOverviewTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2020 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
10 {
11  public const F_PLUGIN_NAME = "plugin_name";
12  public const F_PLUGIN_ID = "plugin_id";
13  public const F_SLOT_NAME = "slot_name";
14  public const F_COMPONENT_NAME = "component_name";
15  public const F_PLUGIN_ACTIVE = "plugin_active";
19  protected $filter_data;
20 
21  public function __construct(ilObjComponentSettingsGUI $a_parent_obj, array $filter_data, string $a_parent_cmd = "")
22  {
23  global $DIC;
24  $this->lng = $DIC->language();
25  $this->ctrl = $DIC->ctrl();
26  $this->filter_data = $filter_data;
27 
28  parent::__construct($a_parent_obj, $a_parent_cmd);
29 
30  $this->setId("cmpspl");
31 
32  $this->addColumn($this->lng->txt("cmps_plugin"), self::F_PLUGIN_NAME);
33  $this->addColumn($this->lng->txt("id"), self::F_PLUGIN_ID);
34  $this->addColumn($this->lng->txt("cmps_plugin_slot"), self::F_SLOT_NAME);
35  $this->addColumn($this->lng->txt("cmps_component"), self::F_COMPONENT_NAME);
36  $this->addColumn($this->lng->txt("active"), self::F_PLUGIN_ACTIVE);
37  $this->addColumn($this->lng->txt("action"));
38 
39  $this->setDefaultOrderField(self::F_PLUGIN_NAME);
40 
41  $this->setEnableHeader(true);
42  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
43  $this->setRowTemplate(
44  "tpl.plugin_overview_row.html",
45  "Services/Component"
46  );
47  $this->getComponents();
48  $this->setLimit(10000);
49  }
50 
51  protected function getComponents() : void
52  {
53  $plugins = [];
54  $modules = $this->getModulesCoreItems();
55  $this->addPluginData($plugins, $modules, IL_COMP_MODULE);
56 
57  $services = $this->getServicesCoreItems();
58  $this->addPluginData($plugins, $services, IL_COMP_SERVICE);
59 
60  // apply filters
61 
62  $active_filters = array_filter($this->filter_data, static function ($value) : bool {
63  return !empty($value);
64  });
65 
66  $plugins = array_filter($plugins, static function (array $plugin_data) use ($active_filters) : bool {
67  $matches_filter = true;
68  if (isset($active_filters[self::F_PLUGIN_NAME])) {
69  $matches_filter = strpos($plugin_data[self::F_PLUGIN_NAME], $active_filters[self::F_PLUGIN_NAME]) !== false;
70  }
71  if (isset($active_filters[self::F_PLUGIN_ID])) {
72  $matches_filter = strpos($plugin_data[self::F_PLUGIN_ID], $active_filters[self::F_PLUGIN_ID]) !== false;
73  }
74  if (isset($active_filters[self::F_PLUGIN_ACTIVE])) {
75  $v = (int)$active_filters[self::F_PLUGIN_ACTIVE] === 1;
76  $matches_filter = $plugin_data[self::F_PLUGIN_ACTIVE] === $v && $matches_filter;
77  }
78  if (isset($active_filters[self::F_SLOT_NAME])) {
79  $matches_filter = in_array($plugin_data[self::F_SLOT_NAME], $active_filters[self::F_SLOT_NAME], true) && $matches_filter;
80  }
81  if (isset($active_filters[self::F_COMPONENT_NAME])) {
82  $matches_filter = in_array($plugin_data['component_type'] . '/' . $plugin_data['component_name'], $active_filters[self::F_COMPONENT_NAME], true) && $matches_filter;
83  }
84 
85  return $matches_filter;
86  });
87 
88  $this->setData($plugins);
89  }
90 
91  protected function getModulesCoreItems() : array
92  {
94  }
95 
96  protected function getServicesCoreItems() : array
97  {
99  }
100 
106  protected function addPluginData(array &$plugins, array $core_items, string $core_type)
107  {
108  foreach ($core_items as $core_item) {
109  $plugin_slots = ilComponent::lookupPluginSlots($core_type, $core_item["subdir"]);
110  foreach ($plugin_slots as $plugin_slot) {
111  $slot = new ilPluginSlot($core_type, $core_item["subdir"], $plugin_slot["id"]);
112  foreach ($slot->getPluginsInformation() as $plugin) {
113  if ($core_type && $slot && $core_item["subdir"] && is_array($plugin) && count($plugin) > 0) {
114  $plugins[] = $this->gatherPluginData($core_type, $slot, $core_item["subdir"], $plugin);
115  }
116  }
117  }
118  }
119  }
120 
129  protected function gatherPluginData(string $a_type, ilPluginSlot $a_slot, string $a_slot_subdir, array $a_plugin) : array
130  {
131  if (!$a_plugin["component_type"]) {
132  return array();
133  }
134  $plugin_db_data = ilPlugin::getPluginRecord($a_plugin["component_type"], $a_plugin[self::F_COMPONENT_NAME], $a_plugin["slot_id"], $a_plugin["name"]);
135 
136  $config_class = null;
137  if (ilPlugin::hasConfigureClass($a_slot->getPluginsDirectory(), $a_plugin, $plugin_db_data)
138  && $this->ctrl->checkTargetClass(ilPlugin::getConfigureClassName($a_plugin))
139  ) {
140  $config_class = strtolower(ilPlugin::getConfigureClassName($a_plugin));
141  }
142 
143  return array(
144  self::F_SLOT_NAME => $a_slot->getSlotName(),
145  "component_type" => $a_type,
146  self::F_COMPONENT_NAME => $a_slot_subdir,
147  "slot_id" => $a_slot->getSlotId(),
148  self::F_PLUGIN_ID => $a_plugin["id"],
149  self::F_PLUGIN_NAME => $a_plugin["name"],
150  "must_install" => $a_plugin["must_install"],
151  self::F_PLUGIN_ACTIVE => $a_plugin["is_active"],
152  "activation_possible" => $a_plugin["activation_possible"],
153  "needs_update" => $a_plugin["needs_update"],
154  "config_class" => $config_class,
155  "has_lang" => (bool) sizeof(
157  $a_slot->getPluginsDirectory() . "/" . $a_plugin["name"] . "/lang"
158  )
159  )
160  );
161  }
162 
163  protected function fillRow($a_set) : void
164  {
165  global $DIC;
166  $rbacsystem = $DIC->rbac()->system();
167 
168  $this->tpl->setVariable("TXT_SLOT_NAME", $a_set[self::F_SLOT_NAME]);
169  $this->tpl->setVariable(
170  "TXT_COMP_NAME",
171  $a_set["component_type"] . "/" . $a_set[self::F_COMPONENT_NAME]
172  );
173 
174  if ($a_set[self::F_PLUGIN_ACTIVE]) {
175  $this->tpl->setCurrentBlock("active");
176  $this->tpl->setVariable("TXT_ACTIVE", $this->lng->txt("yes"));
177  $this->tpl->parseCurrentBlock();
178  } else {
179  $this->tpl->setCurrentBlock("inactive");
180  $this->tpl->setVariable("TXT_INACTIVE", $this->lng->txt("no"));
181  $this->tpl->parseCurrentBlock();
182  }
183 
184  $this->tpl->setVariable("TXT_PLUGIN_NAME", $a_set[self::F_PLUGIN_NAME]);
185  $this->tpl->setVariable("TXT_PLUGIN_ID", $a_set[self::F_PLUGIN_ID]);
186 
187  if ($rbacsystem->checkAccess('write', $_GET['ref_id'])) {
188  $actions = $this->getActionMenuEntries($a_set);
189  $this->tpl->setVariable("ACTION_SELECTOR", $this->getActionMenu($actions, $a_set[self::F_PLUGIN_ID]));
190  }
191  }
192 
198  protected function getActionMenu(array $actions, string $plugin_id) : string
199  {
200  $alist = new ilAdvancedSelectionListGUI();
201  $alist->setId($plugin_id);
202  $alist->setListTitle($this->lng->txt("actions"));
203 
204  foreach ($actions as $caption => $cmd) {
205  $alist->addItem($caption, "", $cmd);
206  }
207 
208  return $alist->getHTML();
209  }
210 
215  protected function getActionMenuEntries(array $a_set) : array
216  {
217  $this->setParameter($a_set);
218 
219  $actions = array();
220  $this->ctrl->setParameter($this->parent_obj, self::F_PLUGIN_ID, $a_set[self::F_PLUGIN_ID]);
221  $this->addCommandToActions($actions, "info", "showPlugin");
222  $this->ctrl->setParameter($this->parent_obj, self::F_PLUGIN_ID, null);
223 
224  if ($a_set["must_install"]) {
225  $this->addCommandToActions($actions, "cmps_install", ilObjComponentSettingsGUI::CMD_INSTALL_PLUGIN);
226  } else {
227  if ($a_set["config_class"]) {
228  $actions[$this->lng->txt("cmps_configure")]
229  = $this->ctrl->getLinkTargetByClass($a_set["config_class"], ilObjComponentSettingsGUI::CMD_CONFIGURE);
230  }
231 
232  if ($a_set["has_lang"]) {
234  }
235 
236  if ($a_set[self::F_PLUGIN_ACTIVE]) {
237  $this->addCommandToActions($actions, "cmps_deactivate", ilObjComponentSettingsGUI::CMD_DEACTIVATE_PLUGIN);
238  }
239 
240  if ($a_set["activation_possible"]) {
241  $this->addCommandToActions($actions, "cmps_activate", ilObjComponentSettingsGUI::CMD_ACTIVATE_PLUGIN);
242  }
243 
244  // update button
245  if ($a_set["needs_update"]) {
246  $this->addCommandToActions($actions, "cmps_update", ilObjComponentSettingsGUI::CMD_UPDATE_PLUGIN);
247  }
248 
249  // #17428
251  }
252 
253  $this->clearParameter();
254 
255  return $actions;
256  }
257 
258  protected function setParameter(array $a_set) : void
259  {
260  $this->ctrl->setParameter($this->parent_obj, ilObjComponentSettingsGUI::P_CTYPE, $a_set["component_type"]);
261  $this->ctrl->setParameter($this->parent_obj, ilObjComponentSettingsGUI::P_CNAME, $a_set[self::F_COMPONENT_NAME]);
262  $this->ctrl->setParameter($this->parent_obj, ilObjComponentSettingsGUI::P_SLOT_ID, $a_set["slot_id"]);
263  $this->ctrl->setParameter($this->parent_obj, ilObjComponentSettingsGUI::P_PLUGIN_NAME, $a_set[self::F_PLUGIN_NAME]);
264  }
265 
266  protected function clearParameter() : void
267  {
268  $this->ctrl->setParameter($this->parent_obj, ilObjComponentSettingsGUI::P_CTYPE, null);
269  $this->ctrl->setParameter($this->parent_obj, ilObjComponentSettingsGUI::P_CNAME, null);
270  $this->ctrl->setParameter($this->parent_obj, ilObjComponentSettingsGUI::P_SLOT_ID, null);
271  $this->ctrl->setParameter($this->parent_obj, ilObjComponentSettingsGUI::P_PLUGIN_NAME, null);
272  }
273 
274  protected function addCommandToActions(array &$actions, string $caption, string $command) : void
275  {
276  $actions[$this->lng->txt($caption)]
277  = $this->ctrl->getLinkTarget($this->parent_obj, $command);
278  }
279 }
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
__construct(ilObjComponentSettingsGUI $a_parent_obj, array $filter_data, string $a_parent_cmd="")
getSlotName()
Get Slot Name.
$_GET["client_id"]
static getAvailableLangFiles(string $a_lang_directory)
Get array of all language files in the plugin.
getActionMenu(array $actions, string $plugin_id)
static getPluginRecord(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
setId($a_val)
Set id.
gatherPluginData(string $a_type, ilPluginSlot $a_slot, string $a_slot_subdir, array $a_plugin)
static getAvailableCoreServices()
Get all available core services.
Plugin Slot.
static hasConfigureClass(string $a_slot_dir, array $plugin_data, array $plugin_db_data)
Has the plugin a configure class?
global $DIC
Definition: goto.php:24
getSlotId()
Get Slot ID.
const IL_COMP_MODULE
addPluginData(array &$plugins, array $core_items, string $core_type)
setRowTemplate($a_template, $a_template_dir="")
Set row template.
static getConfigureClassName(array $plugin_data)
Get plugin configure class name.
TableGUI class for components listing.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
Components (Modules, Services, Plugins) Settings.
__construct(Container $dic, ilPlugin $plugin)
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
getPluginsDirectory()
Get directory of.
setEnableHeader($a_enableheader)
Set Enable Header.
const IL_COMP_SERVICE
setLimit($a_limit=0, $a_default_limit=0)
static getAvailableCoreModules()
Get all available core modules.
static lookupPluginSlots($a_type, $a_name)
Lookup all plugin slots of a component.
addCommandToActions(array &$actions, string $caption, string $command)