ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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{
18 protected $pos_group_options; // [array]
19 protected $old_grp_id; // [int]
20
21 function __construct($a_parent_obj, $a_parent_cmd = "", $a_has_write = false)
22 {
23 global $ilCtrl, $lng;
24
25 parent::__construct($a_parent_obj, $a_parent_cmd);
26
27 $this->setId("repmodtbl");
28
29 $this->setTitle($lng->txt("cmps_repository_object_types"));
30
31 $this->addColumn($lng->txt("cmps_add_new_rank"), "");
32 $this->addColumn($lng->txt("cmps_rep_object"), "");
33 $this->addColumn($lng->txt("cmps_module"), "");
34 $this->addColumn($lng->txt("cmps_group"), "");
35 $this->addColumn($lng->txt("cmps_enable_creation"), "");
36
37 if((bool)$a_has_write)
38 {
39 // save options command
40 $this->addCommandButton("saveModules", $lng->txt("cmps_save_options"));
41 }
42
43 $this->setEnableHeader(true);
44 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
45 $this->setRowTemplate("tpl.table_row_module.html", "Services/Repository");
46 $this->setLimit(10000);
47 $this->setExternalSorting(true);
48
49 $this->getComponents();
50
51 $this->old_grp_id = 0;
52 }
53
57 function getComponents()
58 {
59 global $objDefinition, $ilSetting, $lng, $ilPluginAdmin;
60
61 // unassigned objects should be last
62 $this->pos_group_options = array(0 => $lng->txt("rep_new_item_group_unassigned"));
63 $pos_group_map[0] = "9999";
64
65 include_once("Services/Repository/classes/class.ilObjRepositorySettings.php");
67 {
68 // #12807
70 {
71 $this->pos_group_options[$item["id"]] = $item["title"];
72 $pos_group_map[$item["id"]] = $item["pos"];
73 }
74 }
75
76 $obj_types = array();
77
78 // parse modules
79 include_once("./Services/Component/classes/class.ilModule.php");
80 foreach(ilModule::getAvailableCoreModules() as $mod)
81 {
82 $has_repo = false;
83 $rep_types =
84 $objDefinition->getRepositoryObjectTypesForComponent(IL_COMP_MODULE, $mod["subdir"]);
85 if(sizeof($rep_types) > 0)
86 {
87 foreach($rep_types as $ridx => $rt)
88 {
89 // we only want to display repository modules
90 if($rt["repository"])
91 {
92 $has_repo = true;
93 }
94 else
95 {
96 unset($rep_types[$ridx]);
97 }
98 }
99 }
100 if($has_repo)
101 {
102 foreach($rep_types as $rt)
103 {
104 $obj_types[$rt["id"]] = array(
105 "object" => $rt["class_name"],
106 "caption" => $lng->txt("obj_".$rt["id"]),
107 "subdir" => $mod["subdir"],
108 "grp" => $rt["grp"],
109 "default_pos" => $rt["default_pos"]
110 );
111 }
112 }
113 }
114
115 // parse plugins
116 $obj_types = $this->getPluginComponents($obj_types, IL_COMP_SERVICE, "Repository", "robj");
117 $obj_types = $this->getPluginComponents($obj_types, IL_COMP_MODULE, "OrgUnit", "orguext");
118
119 // parse positions
120 $data = array();
121 foreach($obj_types as $obj_type => $item)
122 {
123 $org_pos = $ilSetting->get("obj_add_new_pos_".$obj_type);
124 if(!(int)$org_pos)
125 {
126 // no setting yet, use default
127 $org_pos = $item["default_pos"];
128 }
129 if(strlen($org_pos) < 8)
130 {
131 // "old" setting without group part, add "unassigned" group
132 $org_pos = $pos_group_map[0].str_pad($org_pos, 4, "0", STR_PAD_LEFT);
133 }
134
135 $pos_grp_id = $ilSetting->get("obj_add_new_pos_grp_".$obj_type, 0);
136
137 $group = null;
138 if ($item["grp"] != "")
139 {
140 $group = $objDefinition->getGroup($item["grp"]);
141 $group = $group["name"];
142 }
143
144 $data[] = array(
145 "id" => $obj_type,
146 "object" => $item["object"],
147 "caption" => $item["caption"],
148 "subdir" => $item["subdir"],
149 "pos" => (int)substr($org_pos, 4),
150 "pos_group" => $pos_grp_id,
151 "creation" => !(bool)$ilSetting->get("obj_dis_creation_".$obj_type, false),
152 "group_id" => $item["grp"],
153 "group" => $group,
154 "sort_key" => (int)$org_pos
155 );
156
157 }
158
159 $data = ilUtil::sortArray($data, "sort_key", "asc", true);
160
161 $this->setData($data);
162 }
163
168 protected function fillRow($a_set)
169 {
170 if($a_set["pos_group"] != $this->old_grp_id)
171 {
172 $this->tpl->setCurrentBlock("pos_grp_bl");
173 $this->tpl->setVariable("TXT_POS_GRP", $this->pos_group_options[$a_set["pos_group"]]);
174 $this->tpl->parseCurrentBlock();
175
176 $this->tpl->setCurrentBlock("tbl_content");
177 $this->tpl->parseCurrentBlock();
178
179 $this->css_row = ($this->css_row != "tblrow1")
180 ? "tblrow1"
181 : "tblrow2";
182 $this->tpl->setVariable("CSS_ROW", $this->css_row);
183
184 $this->old_grp_id = $a_set["pos_group"];
185 }
186
187 // group
188 if ($a_set["group_id"] != "")
189 {
190 $this->tpl->setCurrentBlock("group");
191 $this->tpl->setVariable("VAL_GROUP", $a_set["group"]);
192 $this->tpl->setVariable("VAL_GROUP_ID", $a_set["group_id"]);
193 $this->tpl->parseCurrentBlock();
194 }
195
196 $this->tpl->setCurrentBlock("rep_object");
197 // #11598 - using "caption" (from lng) instead of "object"
198 $this->tpl->setVariable("TXT_REP_OBJECT", $a_set["caption"]);
199 $this->tpl->setVariable("TXT_REP_OBJECT_ID", $a_set["id"]);
200 $this->tpl->setVariable("IMG_REP_OBJECT",
201 ilObject::_getIcon("", "tiny", $a_set["id"]));
202
203 // grouping
204 $sel = ilUtil::formSelect($a_set["pos_group"],
205 "obj_grp[".$a_set["id"]."]", $this->pos_group_options, false, true);
206 $this->tpl->setVariable("GROUP_SEL", $sel);
207
208 // position
209 $this->tpl->setVariable("VAR_POS", "obj_pos[".$a_set["id"]."]");
210 $this->tpl->setVariable("VAL_POS", ilUtil::prepareFormOutput($a_set["pos"]));
211
212 // enable creation
213 $this->tpl->setVariable("VAR_DISABLE_CREATION", "obj_enbl_creation[".$a_set["id"]."]");
214 if ($a_set["creation"])
215 {
216 $this->tpl->setVariable("CHECKED_DISABLE_CREATION",
217 ' checked="checked" ');
218 }
219
220 $this->tpl->setVariable("TXT_MODULE_NAME", $a_set["subdir"]);
221 }
222
230 protected function getPluginComponents($obj_types, $component, $slotName, $slotId) {
231 global $ilPluginAdmin, $lng;
232 include_once("./Services/Component/classes/class.ilPlugin.php");
233 $pl_names = $ilPluginAdmin->getActivePluginsForSlot($component, $slotName, $slotId);
234 foreach ($pl_names as $pl_name) {
235 $pl_id = ilPlugin::lookupIdForName($component, $slotName, $slotId, $pl_name);
236 if ($pl_id) {
237 $obj_types[$pl_id] = array(
238 "object" => $pl_name,
239 "caption" => ilObjectPlugin::lookupTxtById($pl_id, "obj_" . $pl_id),
240 "subdir" => $lng->txt("cmps_plugin"),
241 "grp" => "",
242 "default_pos" => 2000
243 );
244 }
245 }
246 return $obj_types;
247 }
248}
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)
Constructor.
getComponents()
Get pages for list.
static lookupTxtById($plugin_id, $lang_var)
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static lookupIdForName($a_ctype, $a_cname, $a_slot_id, $a_plugin_name)
Lookup id for name.
Class ilTable2GUI.
setEnableHeader($a_enableheader)
Set Enable Header.
setExternalSorting($a_val)
Set external sorting.
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.
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.
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
global $lng
Definition: privfeed.php:17
global $ilSetting
Definition: privfeed.php:17