ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilModulesTableGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("Services/Table/classes/class.ilTable2GUI.php");
5include_once("Services/Component/classes/class.ilComponent.php");
6require_once('./Services/Repository/classes/class.ilObjectPlugin.php');
7
17{
21 protected $ctrl;
22
26 protected $obj_definition;
27
31 protected $settings;
32
36 protected $plugin_admin;
37
38 protected $pos_group_options; // [array]
39 protected $old_grp_id; // [int]
40
41 public function __construct($a_parent_obj, $a_parent_cmd = "", $a_has_write = false)
42 {
43 global $DIC;
44
45 $this->ctrl = $DIC->ctrl();
46 $this->lng = $DIC->language();
47 $this->obj_definition = $DIC["objDefinition"];
48 $this->settings = $DIC->settings();
49 $this->plugin_admin = $DIC["ilPluginAdmin"];
50 $ilCtrl = $DIC->ctrl();
51 $lng = $DIC->language();
52
53 parent::__construct($a_parent_obj, $a_parent_cmd);
54
55 $this->setId("repmodtbl");
56
57 $this->setTitle($lng->txt("cmps_repository_object_types"));
58
59 $this->addColumn($lng->txt("cmps_add_new_rank"), "");
60 $this->addColumn($lng->txt("cmps_rep_object"), "");
61 $this->addColumn($lng->txt("cmps_module"), "");
62 $this->addColumn($lng->txt("cmps_group"), "");
63 $this->addColumn($lng->txt("cmps_enable_creation"), "");
64
65 if ((bool) $a_has_write) {
66 // save options command
67 $this->addCommandButton("saveModules", $lng->txt("cmps_save_options"));
68 }
69
70 $this->setEnableHeader(true);
71 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
72 $this->setRowTemplate("tpl.table_row_module.html", "Services/Repository");
73 $this->setLimit(10000);
74 $this->setExternalSorting(true);
75
76 $this->getComponents();
77
78 $this->old_grp_id = 0;
79 }
80
84 public function getComponents()
85 {
86 $objDefinition = $this->obj_definition;
89 $ilPluginAdmin = $this->plugin_admin;
90
91 // unassigned objects should be last
92 $this->pos_group_options = array(0 => $lng->txt("rep_new_item_group_unassigned"));
93 $pos_group_map[0] = "9999";
94
95 include_once("Services/Repository/classes/class.ilObjRepositorySettings.php");
97 // #12807
99 $this->pos_group_options[$item["id"]] = $item["title"];
100 $pos_group_map[$item["id"]] = $item["pos"];
101 }
102 }
103
104 $obj_types = array();
105
106 // parse modules
107 include_once("./Services/Component/classes/class.ilModule.php");
108 foreach (ilModule::getAvailableCoreModules() as $mod) {
109 $has_repo = false;
110 $rep_types =
111 $objDefinition->getRepositoryObjectTypesForComponent(IL_COMP_MODULE, $mod["subdir"]);
112 if (sizeof($rep_types) > 0) {
113 foreach ($rep_types as $ridx => $rt) {
114 // we only want to display repository modules
115 if ($rt["repository"]) {
116 $has_repo = true;
117 } else {
118 unset($rep_types[$ridx]);
119 }
120 }
121 }
122 if ($has_repo) {
123 foreach ($rep_types as $rt) {
124 $obj_types[$rt["id"]] = array(
125 "object" => $rt["class_name"],
126 "caption" => $lng->txt("obj_" . $rt["id"]),
127 "subdir" => $mod["subdir"],
128 "grp" => $rt["grp"],
129 "default_pos" => $rt["default_pos"]
130 );
131 }
132 }
133 }
134
135 // parse plugins
136 $obj_types = $this->getPluginComponents($obj_types, IL_COMP_SERVICE, "Repository", "robj");
137 $obj_types = $this->getPluginComponents($obj_types, IL_COMP_MODULE, "OrgUnit", "orguext");
138
139 // parse positions
140 $data = array();
141 foreach ($obj_types as $obj_type => $item) {
142 $org_pos = $ilSetting->get("obj_add_new_pos_" . $obj_type);
143 if (!(int) $org_pos) {
144 // no setting yet, use default
145 $org_pos = $item["default_pos"];
146 }
147 if (strlen($org_pos) < 8) {
148 // "old" setting without group part, add "unassigned" group
149 $org_pos = $pos_group_map[0] . str_pad($org_pos, 4, "0", STR_PAD_LEFT);
150 }
151
152 $pos_grp_id = $ilSetting->get("obj_add_new_pos_grp_" . $obj_type, 0);
153
154 $group = null;
155 if ($item["grp"] != "") {
156 $group = $objDefinition->getGroup($item["grp"]);
157 $group = $group["name"];
158 }
159
160 $data[] = array(
161 "id" => $obj_type,
162 "object" => $item["object"],
163 "caption" => $item["caption"],
164 "subdir" => $item["subdir"],
165 "pos" => (int) substr($org_pos, 4),
166 "pos_group" => $pos_grp_id,
167 "creation" => !(bool) $ilSetting->get("obj_dis_creation_" . $obj_type, false),
168 "group_id" => $item["grp"],
169 "group" => $group,
170 "sort_key" => (int) $org_pos
171 );
172 }
173
174 $data = ilUtil::sortArray($data, "sort_key", "asc", true);
175
176 $this->setData($data);
177 }
178
183 protected function fillRow($a_set)
184 {
185 if ($a_set["pos_group"] != $this->old_grp_id) {
186 $this->tpl->setCurrentBlock("pos_grp_bl");
187 $this->tpl->setVariable("TXT_POS_GRP", $this->pos_group_options[$a_set["pos_group"]]);
188 $this->tpl->parseCurrentBlock();
189
190 $this->tpl->setCurrentBlock("tbl_content");
191 $this->tpl->parseCurrentBlock();
192
193 $this->css_row = ($this->css_row != "tblrow1")
194 ? "tblrow1"
195 : "tblrow2";
196 $this->tpl->setVariable("CSS_ROW", $this->css_row);
197
198 $this->old_grp_id = $a_set["pos_group"];
199 }
200
201 // group
202 if ($a_set["group_id"] != "") {
203 $this->tpl->setCurrentBlock("group");
204 $this->tpl->setVariable("VAL_GROUP", $a_set["group"]);
205 $this->tpl->setVariable("VAL_GROUP_ID", $a_set["group_id"]);
206 $this->tpl->parseCurrentBlock();
207 }
208
209 $this->tpl->setCurrentBlock("rep_object");
210 // #11598 - using "caption" (from lng) instead of "object"
211 $this->tpl->setVariable("TXT_REP_OBJECT", $a_set["caption"]);
212 $this->tpl->setVariable("TXT_REP_OBJECT_ID", $a_set["id"]);
213 $this->tpl->setVariable(
214 "IMG_REP_OBJECT",
215 ilObject::_getIcon("", "tiny", $a_set["id"])
216 );
217
218 // grouping
219 $sel = ilUtil::formSelect(
220 $a_set["pos_group"],
221 "obj_grp[" . $a_set["id"] . "]",
222 $this->pos_group_options,
223 false,
224 true
225 );
226 $this->tpl->setVariable("GROUP_SEL", $sel);
227
228 // position
229 $this->tpl->setVariable("VAR_POS", "obj_pos[" . $a_set["id"] . "]");
230 $this->tpl->setVariable("VAL_POS", ilUtil::prepareFormOutput($a_set["pos"]));
231
232 // enable creation
233 $this->tpl->setVariable("VAR_DISABLE_CREATION", "obj_enbl_creation[" . $a_set["id"] . "]");
234 if ($a_set["creation"]) {
235 $this->tpl->setVariable(
236 "CHECKED_DISABLE_CREATION",
237 ' checked="checked" '
238 );
239 }
240
241 $this->tpl->setVariable("TXT_MODULE_NAME", $a_set["subdir"]);
242 }
243
251 protected function getPluginComponents($obj_types, $component, $slotName, $slotId)
252 {
253 $ilPluginAdmin = $this->plugin_admin;
255 include_once("./Services/Component/classes/class.ilPlugin.php");
256 $pl_names = $ilPluginAdmin->getActivePluginsForSlot($component, $slotName, $slotId);
257 foreach ($pl_names as $pl_name) {
258 $pl_id = ilPlugin::lookupIdForName($component, $slotName, $slotId, $pl_name);
259 if ($pl_id) {
260 $obj_types[$pl_id] = array(
261 "object" => $pl_name,
262 "caption" => ilObjectPlugin::lookupTxtById($pl_id, "obj_" . $pl_id),
263 "subdir" => $lng->txt("cmps_plugin"),
264 "grp" => "",
265 "default_pos" => 2000
266 );
267 }
268 }
269 return $obj_types;
270 }
271}
An exception for terminatinating execution or to throw for unit testing.
const IL_COMP_SERVICE
const IL_COMP_MODULE
static getAvailableCoreModules()
Get all available core modules.
TableGUI class for module listing.
fillRow($a_set)
Standard Version of Fill Row.
getPluginComponents($obj_types, $component, $slotName, $slotId)
__construct($a_parent_obj, $a_parent_cmd="", $a_has_write=false)
ilTable2GUI constructor.
getComponents()
Get pages for list.
static lookupTxtById($plugin_id, $lang_var)
static lookupIdForName(string $a_ctype, string $a_cname, string $a_slot_id, string $a_plugin_name)
Class ilTable2GUI.
setEnableHeader($a_enableheader)
Set Enable Header.
setExternalSorting($a_val)
Set external sorting.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
setData($a_data)
set table data @access public
setRowTemplate($a_template, $a_template_dir="")
Set row template.
setLimit($a_limit=0, $a_default_limit=0)
set max.
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.
setId($a_val)
Set id.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static formSelect( $selected, $varname, $options, $multiple=false, $direct_text=false, $size="0", $style_class="", $attribs="", $disabled=false)
Builds a select form field with options and shows the selected option first.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
global $ilCtrl
Definition: ilias.php:18
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilSetting
Definition: privfeed.php:17
settings()
Definition: settings.php:2
$DIC
Definition: xapitoken.php:46