ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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  "components/ILIAS/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  $this->pos_group_options[$item["id"]] = $item["title"];
90  $pos_group_map[$item["id"]] = $item["pos"];
91  }
92 
93  $obj_types = [];
94 
95  // parse modules
96  /* this does not work anymore since 10
97  foreach ($this->component_repository->getComponents() as $mod) {
98  if ($mod->getType() !== ilComponentInfo::TYPE_MODULES) {
99  //continue;
100  }
101  $has_repo = false;
102  $rep_types = $objDefinition::getRepositoryObjectTypesForComponent(
103  ilComponentInfo::TYPE_MODULES,
104  $mod->getName()
105  );
106  if (count($rep_types) > 0) {
107  foreach ($rep_types as $ridx => $rt) {
108  // we only want to display repository modules
109  if ($rt["repository"]) {
110  $has_repo = true;
111  } else {
112  unset($rep_types[$ridx]);
113  }
114  }
115  }
116  if ($has_repo) {
117  foreach ($rep_types as $rt) {
118  $obj_types[$rt["id"]] = [
119  "object" => $rt["class_name"],
120  "caption" => $lng->txt("obj_" . $rt["id"]),
121  "subdir" => $mod->getName(),
122  "grp" => $rt["grp"],
123  "default_pos" => $rt["default_pos"]
124  ];
125  }
126  }
127  }*/
128 
129  foreach ($this->obj_definition->getAllRepositoryTypes(false) as $id) {
130  if ($this->obj_definition->isAllowedInRepository($id)) {
131  if ($this->obj_definition->isSystemObject($id)) {
132  continue;
133  }
134  if (in_array($id, ["lng", "rolt", "sty", "tax", "usr"])) {
135  continue;
136  }
137  $obj_types[$id] = [
138  "object" => $this->obj_definition->getClassName($id),
139  "caption" => $lng->txt("obj_" . $id),
140  "subdir" => "",
141  "grp" => $this->obj_definition->getGroupOfObj($id),
142  "default_pos" => $this->obj_definition->getPositionByType($id),
143  ];
144  }
145  }
146 
147 
148 
149  // parse plugins
150  $obj_types = $this->getPluginComponents($obj_types, ilComponentInfo::TYPE_SERVICES, "Repository", "robj");
151  $obj_types = $this->getPluginComponents($obj_types, ilComponentInfo::TYPE_MODULES, "OrgUnit", "orguext");
152 
153  // parse positions
154  $data = [];
155  foreach ($obj_types as $obj_type => $item) {
156  $org_pos = $ilSetting->get("obj_add_new_pos_" . $obj_type);
157  if (!(int) $org_pos) {
158  // no setting yet, use default
159  $org_pos = $item["default_pos"];
160  }
161  if (strlen($org_pos) < 8) {
162  // "old" setting without group part, add "unassigned" group
163  $org_pos = $pos_group_map[0] . str_pad($org_pos, 4, "0", STR_PAD_LEFT);
164  }
165 
166  $pos_grp_id = $ilSetting->get("obj_add_new_pos_grp_" . $obj_type, '0');
167 
168  $group = null;
169  if ($item["grp"] != "") {
170  $group = $objDefinition->getGroup($item["grp"]);
171  $group = $group["name"];
172  }
173 
174  $data[] = [
175  "id" => $obj_type,
176  "object" => $item["object"],
177  "caption" => $item["caption"],
178  "subdir" => $item["subdir"],
179  "pos" => (int) substr($org_pos, 4),
180  "pos_group" => $pos_grp_id,
181  "creation" => !$ilSetting->get("obj_dis_creation_" . $obj_type, '0'),
182  "group_id" => $item["grp"],
183  "group" => $group,
184  "sort_key" => (int) $org_pos
185  ];
186  }
187 
188  $data = ilArrayUtil::sortArray($data, "sort_key", "asc", true);
189 
190  $this->setData($data);
191  }
192 
193  protected function fillRow(array $a_set): void
194  {
195  if ((int) $a_set["pos_group"] !== $this->old_grp_id) {
196  $this->tpl->setCurrentBlock("pos_grp_bl");
197  $this->tpl->setVariable("TXT_POS_GRP", $this->pos_group_options[$a_set["pos_group"]] ?? "");
198  $this->tpl->parseCurrentBlock();
199 
200  $this->tpl->setCurrentBlock("tbl_content");
201  $this->tpl->parseCurrentBlock();
202 
203  $this->css_row = ($this->css_row !== "tblrow1")
204  ? "tblrow1"
205  : "tblrow2";
206  $this->tpl->setVariable("CSS_ROW", $this->css_row);
207 
208  $this->old_grp_id = $a_set["pos_group"];
209  }
210 
211  // group
212  if ($a_set["group_id"] != "") {
213  $this->tpl->setCurrentBlock("group");
214  $this->tpl->setVariable("VAL_GROUP", $a_set["group"]);
215  $this->tpl->setVariable("VAL_GROUP_ID", $a_set["group_id"]);
216  $this->tpl->parseCurrentBlock();
217  }
218 
219  $this->tpl->setCurrentBlock("rep_object");
220  // #11598 - using "caption" (from lng) instead of "object"
221  $this->tpl->setVariable("TXT_REP_OBJECT", $a_set["caption"]);
222  $this->tpl->setVariable("TXT_REP_OBJECT_ID", $a_set["id"]);
223  $this->tpl->setVariable(
224  "IMG_REP_OBJECT",
225  ilObject::_getIcon(0, "tiny", $a_set["id"])
226  );
227 
228  // grouping
230  $a_set["pos_group"],
231  "obj_grp[" . $a_set["id"] . "]",
232  $this->pos_group_options,
233  false,
234  true
235  );
236  $this->tpl->setVariable("GROUP_SEL", $sel);
237 
238  // position
239  $this->tpl->setVariable("VAR_POS", "obj_pos[" . $a_set["id"] . "]");
240  $this->tpl->setVariable("VAL_POS", ilLegacyFormElementsUtil::prepareFormOutput($a_set["pos"]));
241 
242  // enable creation
243  $this->tpl->setVariable("VAR_DISABLE_CREATION", "obj_enbl_creation[" . $a_set["id"] . "]");
244  if ($a_set["creation"]) {
245  $this->tpl->setVariable(
246  "CHECKED_DISABLE_CREATION",
247  ' checked="checked" '
248  );
249  }
250 
251  $this->tpl->setVariable("TXT_MODULE_NAME", $a_set["subdir"]);
252  }
253 
254  protected function getPluginComponents(
255  array $obj_types,
256  string $component,
257  string $slotName,
258  string $slotId
259  ): array {
260  $lng = $this->lng;
261  $plugins = $this->component_repository->getPluginSlotById($slotId)->getActivePlugins();
262  foreach ($plugins as $plugin) {
263  $obj_types[$plugin->getId()] = [
264  "object" => $plugin->getName(),
265  "caption" => ilObjectPlugin::lookupTxtById($plugin->getId(), "obj_" . $plugin->getId()),
266  "subdir" => $lng->txt("cmps_plugin"),
267  "grp" => "",
268  "default_pos" => 2000
269  ];
270  }
271  return $obj_types;
272  }
273 }
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)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setExternalSorting(bool $a_val)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
global $DIC
Definition: shib_login.php:26
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:31
__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)