ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
4 include_once("Services/Table/classes/class.ilTable2GUI.php");
5 include_once("Services/Component/classes/class.ilComponent.php");
6 
16 {
17  protected $pos_group_options; // [array]
18  protected $old_grp_id; // [int]
19 
20  function __construct($a_parent_obj, $a_parent_cmd = "", $a_has_write = false)
21  {
22  global $ilCtrl, $lng;
23 
24  parent::__construct($a_parent_obj, $a_parent_cmd);
25 
26  $this->setId("repmodtbl");
27 
28  $this->setTitle($lng->txt("cmps_repository_object_types"));
29 
30  $this->addColumn($lng->txt("cmps_add_new_rank"), "");
31  $this->addColumn($lng->txt("cmps_rep_object"), "");
32  $this->addColumn($lng->txt("cmps_module"), "");
33  $this->addColumn($lng->txt("cmps_group"), "");
34  $this->addColumn($lng->txt("cmps_enable_creation"), "");
35 
36  if((bool)$a_has_write)
37  {
38  // save options command
39  $this->addCommandButton("saveModules", $lng->txt("cmps_save_options"));
40  }
41 
42  $this->setEnableHeader(true);
43  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
44  $this->setRowTemplate("tpl.table_row_module.html", "Services/Repository");
45  $this->setLimit(10000);
46  $this->setExternalSorting(true);
47 
48  $this->getComponents();
49 
50  $this->old_grp_id = 0;
51  }
52 
56  function getComponents()
57  {
58  global $objDefinition, $ilSetting, $lng, $ilPluginAdmin;
59 
60  // unassigned objects should be last
61  $this->pos_group_options = array(0 => $lng->txt("rep_new_item_group_unassigned"));
62  $pos_group_map[0] = "9999";
63 
64  include_once("Services/Repository/classes/class.ilObjRepositorySettings.php");
66  {
67  // #12807
69  {
70  $this->pos_group_options[$item["id"]] = $item["title"];
71  $pos_group_map[$item["id"]] = $item["pos"];
72  }
73  }
74 
75  $obj_types = array();
76 
77  // parse modules
78  include_once("./Services/Component/classes/class.ilModule.php");
79  foreach(ilModule::getAvailableCoreModules() as $mod)
80  {
81  $has_repo = false;
82  $rep_types =
83  $objDefinition->getRepositoryObjectTypesForComponent(IL_COMP_MODULE, $mod["subdir"]);
84  if(sizeof($rep_types) > 0)
85  {
86  foreach($rep_types as $ridx => $rt)
87  {
88  // we only want to display repository modules
89  if($rt["repository"])
90  {
91  $has_repo = true;
92  }
93  else
94  {
95  unset($rep_types[$ridx]);
96  }
97  }
98  }
99  if($has_repo)
100  {
101  foreach($rep_types as $rt)
102  {
103  $obj_types[$rt["id"]] = array(
104  "object" => $rt["class_name"],
105  "caption" => $lng->txt("obj_".$rt["id"]),
106  "subdir" => $mod["subdir"],
107  "grp" => $rt["grp"],
108  "default_pos" => $rt["default_pos"]
109  );
110  }
111  }
112  }
113 
114  // parse plugins
115  include_once("./Services/Component/classes/class.ilPlugin.php");
116  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "Repository", "robj");
117  foreach ($pl_names as $pl_name)
118  {
119  $pl_id = ilPlugin::lookupIdForName(IL_COMP_SERVICE, "Repository", "robj", $pl_name);
120  if($pl_id)
121  {
122  $obj_types[$pl_id] = array(
123  "object" => $pl_name,
124  "caption" => ilPlugin::lookupTxt("rep_robj", $pl_id, "obj_".$pl_id),
125  "subdir" => $lng->txt("cmps_plugin"),
126  "grp" => "",
127  "default_pos" => 2000
128  );
129  }
130  }
131 
132  // parse positions
133  $data = array();
134  foreach($obj_types as $obj_type => $item)
135  {
136  $org_pos = $ilSetting->get("obj_add_new_pos_".$obj_type);
137  if(!(int)$org_pos)
138  {
139  // no setting yet, use default
140  $org_pos = $item["default_pos"];
141  }
142  if(strlen($org_pos) < 8)
143  {
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  {
153  $group = $objDefinition->getGroup($item["grp"]);
154  $group = $group["name"];
155  }
156 
157  $data[] = array(
158  "id" => $obj_type,
159  "object" => $item["object"],
160  "caption" => $item["caption"],
161  "subdir" => $item["subdir"],
162  "pos" => (int)substr($org_pos, 4),
163  "pos_group" => $pos_grp_id,
164  "creation" => !(bool)$ilSetting->get("obj_dis_creation_".$obj_type, false),
165  "group_id" => $item["grp"],
166  "group" => $group,
167  "sort_key" => (int)$org_pos
168  );
169 
170  }
171 
172  $data = ilUtil::sortArray($data, "sort_key", "asc", true);
173 
174  $this->setData($data);
175  }
176 
181  protected function fillRow($a_set)
182  {
183  if($a_set["pos_group"] != $this->old_grp_id)
184  {
185  $this->tpl->setCurrentBlock("pos_grp_bl");
186  $this->tpl->setVariable("TXT_POS_GRP", $this->pos_group_options[$a_set["pos_group"]]);
187  $this->tpl->parseCurrentBlock();
188 
189  $this->tpl->setCurrentBlock("tbl_content");
190  $this->tpl->parseCurrentBlock();
191 
192  $this->css_row = ($this->css_row != "tblrow1")
193  ? "tblrow1"
194  : "tblrow2";
195  $this->tpl->setVariable("CSS_ROW", $this->css_row);
196 
197  $this->old_grp_id = $a_set["pos_group"];
198  }
199 
200  // group
201  if ($a_set["group_id"] != "")
202  {
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("IMG_REP_OBJECT",
214  ilObject::_getIcon("", "tiny", $a_set["id"]));
215 
216  // grouping
217  $sel = ilUtil::formSelect($a_set["pos_group"],
218  "obj_grp[".$a_set["id"]."]", $this->pos_group_options, false, true);
219  $this->tpl->setVariable("GROUP_SEL", $sel);
220 
221  // position
222  $this->tpl->setVariable("VAR_POS", "obj_pos[".$a_set["id"]."]");
223  $this->tpl->setVariable("VAL_POS", ilUtil::prepareFormOutput($a_set["pos"]));
224 
225  // enable creation
226  $this->tpl->setVariable("VAR_DISABLE_CREATION", "obj_enbl_creation[".$a_set["id"]."]");
227  if ($a_set["creation"])
228  {
229  $this->tpl->setVariable("CHECKED_DISABLE_CREATION",
230  ' checked="checked" ');
231  }
232 
233  $this->tpl->setVariable("TXT_MODULE_NAME", $a_set["subdir"]);
234  }
235 }
236 
237 ?>
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
setExternalSorting($a_val)
Set external sorting.
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
__construct($a_parent_obj, $a_parent_cmd="", $a_has_write=false)
fillRow($a_set)
Standard Version of Fill Row.
setId($a_val)
Set id.
global $ilCtrl
Definition: ilias.php:18
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
static lookupTxt($a_mod_prefix, $a_pl_id, $a_lang_var)
Lookup language text.
lookupIdForName($a_ctype, $a_cname, $a_slot_id, $a_plugin_name)
Lookup id for name.
Class ilTable2GUI.
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.
const IL_COMP_MODULE
getComponents()
Get pages for list.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
global $ilSetting
Definition: privfeed.php:40
global $lng
Definition: privfeed.php:40
setEnableHeader($a_enableheader)
Set Enable Header.
TableGUI class for module listing.
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.
const IL_COMP_SERVICE
setLimit($a_limit=0, $a_default_limit=0)
static getAvailableCoreModules()
Get all available core modules.