ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilModulesTableGUI.php
Go to the documentation of this file.
1 <?php
2 
25 {
27  protected ilSetting $settings;
28  protected array $pos_group_options;
29  protected int $old_grp_id;
31 
32  public function __construct(
33  ilObjRepositorySettingsGUI $a_parent_obj,
34  string $a_parent_cmd = "",
35  bool $a_has_write = false
36  ) {
37  global $DIC;
38 
39  $this->ctrl = $DIC->ctrl();
40  $this->lng = $DIC->language();
41  $this->obj_definition = $DIC["objDefinition"];
42  $this->settings = $DIC->settings();
43  $this->component_repository = $DIC["component.repository"];
44  $ilCtrl = $DIC->ctrl();
45  $lng = $DIC->language();
46 
47  parent::__construct($a_parent_obj, $a_parent_cmd);
48 
49  $this->setId("repmodtbl");
50 
51  $this->setTitle($lng->txt("cmps_repository_object_types"));
52 
53  $this->addColumn($lng->txt("cmps_add_new_rank"), "");
54  $this->addColumn($lng->txt("cmps_rep_object"), "");
55  $this->addColumn($lng->txt("cmps_module"), "");
56  $this->addColumn($lng->txt("cmps_group"), "");
57  $this->addColumn($lng->txt("cmps_enable_creation"), "");
58 
59  if ($a_has_write) {
60  // save options command
61  $this->addCommandButton("saveModules", $lng->txt("cmps_save_options"));
62  }
63 
64  $this->setEnableHeader(true);
65  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
66  $this->setRowTemplate(
67  "tpl.table_row_module.html",
68  "Services/Repository/Administration"
69  );
70  $this->setLimit(9999);
71  $this->setExternalSorting(true);
72 
73  $this->getComponents();
74 
75  $this->old_grp_id = 0;
76  }
77 
78  public function getComponents(): void
79  {
80  $objDefinition = $this->obj_definition;
82  $lng = $this->lng;
83 
84  // unassigned objects should be last
85  $this->pos_group_options = [0 => $lng->txt("rep_new_item_group_unassigned")];
86  $pos_group_map[0] = "9999";
87 
88  foreach (ilObjRepositorySettings::getNewItemGroups() as $item) {
89  // #12807
90  if ((int) $item["type"] === ilObjRepositorySettings::NEW_ITEM_GROUP_TYPE_GROUP) {
91  $this->pos_group_options[$item["id"]] = $item["title"];
92  $pos_group_map[$item["id"]] = $item["pos"];
93  }
94  }
95 
96  $obj_types = [];
97 
98  // parse modules
99  foreach ($this->component_repository->getComponents() as $mod) {
100  if ($mod->getType() !== ilComponentInfo::TYPE_MODULES) {
101  continue;
102  }
103  $has_repo = false;
104  $rep_types = $objDefinition::getRepositoryObjectTypesForComponent(
106  $mod->getName()
107  );
108  if (count($rep_types) > 0) {
109  foreach ($rep_types as $ridx => $rt) {
110  // we only want to display repository modules
111  if ($rt["repository"]) {
112  $has_repo = true;
113  } else {
114  unset($rep_types[$ridx]);
115  }
116  }
117  }
118  if ($has_repo) {
119  foreach ($rep_types as $rt) {
120  $obj_types[$rt["id"]] = [
121  "object" => $rt["class_name"],
122  "caption" => $lng->txt("obj_" . $rt["id"]),
123  "subdir" => $mod->getName(),
124  "grp" => $rt["grp"],
125  "default_pos" => $rt["default_pos"]
126  ];
127  }
128  }
129  }
130 
131  // parse plugins
132  $obj_types = $this->getPluginComponents($obj_types, ilComponentInfo::TYPE_SERVICES, "Repository", "robj");
133  $obj_types = $this->getPluginComponents($obj_types, ilComponentInfo::TYPE_MODULES, "OrgUnit", "orguext");
134 
135  // parse positions
136  $data = [];
137  foreach ($obj_types as $obj_type => $item) {
138  $org_pos = $ilSetting->get("obj_add_new_pos_" . $obj_type);
139  if (!(int) $org_pos) {
140  // no setting yet, use default
141  $org_pos = $item["default_pos"];
142  }
143  if (strlen($org_pos) < 8) {
144  // "old" setting without group part, add "unassigned" group
145  $org_pos = $pos_group_map[0] . str_pad($org_pos, 4, "0", STR_PAD_LEFT);
146  }
147 
148  $pos_grp_id = $ilSetting->get("obj_add_new_pos_grp_" . $obj_type, '0');
149 
150  $group = null;
151  if ($item["grp"] != "") {
152  $group = $objDefinition->getGroup($item["grp"]);
153  $group = $group["name"];
154  }
155 
156  $data[] = [
157  "id" => $obj_type,
158  "object" => $item["object"],
159  "caption" => $item["caption"],
160  "subdir" => $item["subdir"],
161  "pos" => (int) substr($org_pos, 4),
162  "pos_group" => $pos_grp_id,
163  "creation" => !$ilSetting->get("obj_dis_creation_" . $obj_type, '0'),
164  "group_id" => $item["grp"],
165  "group" => $group,
166  "sort_key" => (int) $org_pos
167  ];
168  }
169 
170  $data = ilArrayUtil::sortArray($data, "sort_key", "asc", true);
171 
172  $this->setData($data);
173  }
174 
175  protected function fillRow(array $a_set): void
176  {
177  if ((int) $a_set["pos_group"] !== $this->old_grp_id) {
178  $this->tpl->setCurrentBlock("pos_grp_bl");
179  $this->tpl->setVariable("TXT_POS_GRP", $this->pos_group_options[$a_set["pos_group"]]);
180  $this->tpl->parseCurrentBlock();
181 
182  $this->tpl->setCurrentBlock("tbl_content");
183  $this->tpl->parseCurrentBlock();
184 
185  $this->css_row = ($this->css_row !== "tblrow1")
186  ? "tblrow1"
187  : "tblrow2";
188  $this->tpl->setVariable("CSS_ROW", $this->css_row);
189 
190  $this->old_grp_id = $a_set["pos_group"];
191  }
192 
193  // group
194  if ($a_set["group_id"] != "") {
195  $this->tpl->setCurrentBlock("group");
196  $this->tpl->setVariable("VAL_GROUP", $a_set["group"]);
197  $this->tpl->setVariable("VAL_GROUP_ID", $a_set["group_id"]);
198  $this->tpl->parseCurrentBlock();
199  }
200 
201  $this->tpl->setCurrentBlock("rep_object");
202  // #11598 - using "caption" (from lng) instead of "object"
203  $this->tpl->setVariable("TXT_REP_OBJECT", $a_set["caption"]);
204  $this->tpl->setVariable("TXT_REP_OBJECT_ID", $a_set["id"]);
205  $this->tpl->setVariable(
206  "IMG_REP_OBJECT",
207  ilObject::_getIcon(0, "tiny", $a_set["id"])
208  );
209 
210  // grouping
212  $a_set["pos_group"],
213  "obj_grp[" . $a_set["id"] . "]",
214  $this->pos_group_options,
215  false,
216  true
217  );
218  $this->tpl->setVariable("GROUP_SEL", $sel);
219 
220  // position
221  $this->tpl->setVariable("VAR_POS", "obj_pos[" . $a_set["id"] . "]");
222  $this->tpl->setVariable("VAL_POS", ilLegacyFormElementsUtil::prepareFormOutput($a_set["pos"]));
223 
224  // enable creation
225  $this->tpl->setVariable("VAR_DISABLE_CREATION", "obj_enbl_creation[" . $a_set["id"] . "]");
226  if ($a_set["creation"]) {
227  $this->tpl->setVariable(
228  "CHECKED_DISABLE_CREATION",
229  ' checked="checked" '
230  );
231  }
232 
233  $this->tpl->setVariable("TXT_MODULE_NAME", $a_set["subdir"]);
234  }
235 
236  protected function getPluginComponents(
237  array $obj_types,
238  string $component,
239  string $slotName,
240  string $slotId
241  ): array {
242  $lng = $this->lng;
243  $plugins = $this->component_repository->getPluginSlotById($slotId)->getActivePlugins();
244  foreach ($plugins as $plugin) {
245  $obj_types[$plugin->getId()] = [
246  "object" => $plugin->getName(),
247  "caption" => ilObjectPlugin::lookupTxtById($plugin->getId(), "obj_" . $plugin->getId()),
248  "subdir" => $lng->txt("cmps_plugin"),
249  "grp" => "",
250  "default_pos" => 2000
251  ];
252  }
253  return $obj_types;
254  }
255 }
setData(array $a_data)
Readable part of repository interface to ilComponentDataDB.
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setFormAction(string $a_form_action, bool $a_multipart=false)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
static formSelect( $selected, string $varname, array $options, bool $multiple=false, bool $direct_text=false, int $size=0, string $style_class="", array $attribs=[], bool $disabled=false)
Builds a select form field with options and shows the selected option first.
static prepareFormOutput($a_str, bool $a_strip=false)
ilLanguage $lng
__construct(ilObjRepositorySettingsGUI $a_parent_obj, string $a_parent_cmd="", bool $a_has_write=false)
setId(string $a_val)
global $DIC
Definition: feed.php:28
parses the objects.xml it handles the xml-description of all ilias objects
setExternalSorting(bool $a_val)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
static lookupTxtById(string $plugin_id, string $lang_var)
getPluginComponents(array $obj_types, string $component, string $slotName, string $slotId)
global $ilSetting
Definition: privfeed.php:17
__construct(Container $dic, ilPlugin $plugin)
setLimit(int $a_limit=0, int $a_default_limit=0)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilComponentRepository $component_repository
ilObjectDefinition $obj_definition
setEnableHeader(bool $a_enableheader)
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)