ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 = "")
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  // save options command
37  $this->addCommandButton("saveModules", $lng->txt("cmps_save_options"));
38 
39  $this->setEnableHeader(true);
40  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
41  $this->setRowTemplate("tpl.table_row_module.html", "Services/Repository");
42  $this->setLimit(10000);
43  $this->setExternalSorting(true);
44 
45  $this->getComponents();
46 
47  $this->old_grp_id = 0;
48  }
49 
53  function getComponents()
54  {
55  global $objDefinition, $ilSetting, $lng, $ilPluginAdmin;
56 
57  // unassigned objects should be last
58  $this->pos_group_options = array(0 => $lng->txt("rep_new_item_group_unassigned"));
59  $pos_group_map[0] = "9999";
60 
61  include_once("Services/Repository/classes/class.ilObjRepositorySettings.php");
63  {
64  // #12807
66  {
67  $this->pos_group_options[$item["id"]] = $item["title"];
68  $pos_group_map[$item["id"]] = $item["pos"];
69  }
70  }
71 
72  $obj_types = array();
73 
74  // parse modules
75  include_once("./Services/Component/classes/class.ilModule.php");
76  foreach(ilModule::getAvailableCoreModules() as $mod)
77  {
78  $has_repo = false;
79  $rep_types =
80  $objDefinition->getRepositoryObjectTypesForComponent(IL_COMP_MODULE, $mod["subdir"]);
81  if(sizeof($rep_types) > 0)
82  {
83  foreach($rep_types as $ridx => $rt)
84  {
85  // we only want to display repository modules
86  if($rt["repository"])
87  {
88  $has_repo = true;
89  }
90  else
91  {
92  unset($rep_types[$ridx]);
93  }
94  }
95  }
96  if($has_repo)
97  {
98  foreach($rep_types as $rt)
99  {
100  $obj_types[$rt["id"]] = array(
101  "object" => $rt["class_name"],
102  "caption" => $lng->txt("obj_".$rt["id"]),
103  "subdir" => $mod["subdir"],
104  "grp" => $rt["grp"],
105  "default_pos" => $rt["default_pos"]
106  );
107  }
108  }
109  }
110 
111  // parse plugins
112  include_once("./Services/Component/classes/class.ilPlugin.php");
113  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "Repository", "robj");
114  foreach ($pl_names as $pl_name)
115  {
116  $pl_id = ilPlugin::lookupIdForName(IL_COMP_SERVICE, "Repository", "robj", $pl_name);
117  if($pl_id)
118  {
119  $obj_types[$pl_id] = array(
120  "object" => $pl_name,
121  "caption" => ilPlugin::lookupTxt("rep_robj", $pl_id, "obj_".$pl_id),
122  "subdir" => $lng->txt("cmps_plugin"),
123  "grp" => "",
124  "default_pos" => 2000
125  );
126  }
127  }
128 
129  // parse positions
130  $data = array();
131  foreach($obj_types as $obj_type => $item)
132  {
133  $org_pos = $ilSetting->get("obj_add_new_pos_".$obj_type);
134  if(!(int)$org_pos)
135  {
136  // no setting yet, use default
137  $org_pos = $item["default_pos"];
138  }
139  if(strlen($org_pos) < 8)
140  {
141  // "old" setting without group part, add "unassigned" group
142  $org_pos = $pos_group_map[0].str_pad($org_pos, 4, "0", STR_PAD_LEFT);
143  }
144 
145  $pos_grp_id = $ilSetting->get("obj_add_new_pos_grp_".$obj_type, 0);
146 
147  $group = null;
148  if ($item["grp"] != "")
149  {
150  $group = $objDefinition->getGroup($item["grp"]);
151  $group = $group["name"];
152  }
153 
154  $data[] = array(
155  "id" => $obj_type,
156  "object" => $item["object"],
157  "caption" => $item["caption"],
158  "subdir" => $item["subdir"],
159  "pos" => (int)substr($org_pos, 4),
160  "pos_group" => $pos_grp_id,
161  "creation" => !(bool)$ilSetting->get("obj_dis_creation_".$obj_type, false),
162  "group_id" => $item["grp"],
163  "group" => $group,
164  "sort_key" => (int)$org_pos
165  );
166 
167  }
168 
169  $data = ilUtil::sortArray($data, "sort_key", "asc", true);
170 
171  $this->setData($data);
172  }
173 
178  protected function fillRow($a_set)
179  {
180  if($a_set["pos_group"] != $this->old_grp_id)
181  {
182  $this->tpl->setCurrentBlock("pos_grp_bl");
183  $this->tpl->setVariable("TXT_POS_GRP", $this->pos_group_options[$a_set["pos_group"]]);
184  $this->tpl->parseCurrentBlock();
185 
186  $this->tpl->setCurrentBlock("tbl_content");
187  $this->tpl->parseCurrentBlock();
188 
189  $this->css_row = ($this->css_row != "tblrow1")
190  ? "tblrow1"
191  : "tblrow2";
192  $this->tpl->setVariable("CSS_ROW", $this->css_row);
193 
194  $this->old_grp_id = $a_set["pos_group"];
195  }
196 
197  // group
198  if ($a_set["group_id"] != "")
199  {
200  $this->tpl->setCurrentBlock("group");
201  $this->tpl->setVariable("VAL_GROUP", $a_set["group"]);
202  $this->tpl->setVariable("VAL_GROUP_ID", $a_set["group_id"]);
203  $this->tpl->parseCurrentBlock();
204  }
205 
206  $this->tpl->setCurrentBlock("rep_object");
207  // #11598 - using "caption" (from lng) instead of "object"
208  $this->tpl->setVariable("TXT_REP_OBJECT", $a_set["caption"]);
209  $this->tpl->setVariable("TXT_REP_OBJECT_ID", $a_set["id"]);
210  $this->tpl->setVariable("IMG_REP_OBJECT",
211  ilObject::_getIcon("", "tiny", $a_set["id"]));
212 
213  // grouping
214  $sel = ilUtil::formSelect($a_set["pos_group"],
215  "obj_grp[".$a_set["id"]."]", $this->pos_group_options, false, true);
216  $this->tpl->setVariable("GROUP_SEL", $sel);
217 
218  // position
219  $this->tpl->setVariable("VAR_POS", "obj_pos[".$a_set["id"]."]");
220  $this->tpl->setVariable("VAL_POS", ilUtil::prepareFormOutput($a_set["pos"]));
221 
222  // enable creation
223  $this->tpl->setVariable("VAR_DISABLE_CREATION", "obj_enbl_creation[".$a_set["id"]."]");
224  if ($a_set["creation"])
225  {
226  $this->tpl->setVariable("CHECKED_DISABLE_CREATION",
227  ' checked="checked" ');
228  }
229 
230  $this->tpl->setVariable("TXT_MODULE_NAME", $a_set["subdir"]);
231  }
232 }
233 
234 ?>