ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilObjRepositorySettings.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/Object/classes/class.ilObject.php");
5 
15 {
18 
25  public function __construct($a_id, $a_call_by_reference = true)
26  {
27  $this->type = "reps";
28  parent::__construct($a_id, $a_call_by_reference);
29  }
30 
31  public function delete()
32  {
33  // DISABLED
34  return false;
35  }
36 
37  public static function addNewItemGroupSeparator()
38  {
39  global $DIC;
40 
41  $ilDB = $DIC->database();
42 
43  // append
44  $pos = $ilDB->query("SELECT max(pos) mpos FROM il_new_item_grp");
45  $pos = $ilDB->fetchAssoc($pos);
46  $pos = (int) $pos["mpos"];
47  $pos += 10;
48 
49  $seq = $ilDB->nextID("il_new_item_grp");
50 
51  $ilDB->manipulate("INSERT INTO il_new_item_grp" .
52  " (id, pos, type) VALUES (" .
53  $ilDB->quote($seq, "integer") .
54  ", " . $ilDB->quote($pos, "integer") .
55  ", " . $ilDB->quote(self::NEW_ITEM_GROUP_TYPE_SEPARATOR, "integer") .
56  ")");
57  return true;
58  }
59 
60  public static function addNewItemGroup(array $a_titles)
61  {
62  global $DIC;
63 
64  $ilDB = $DIC->database();
65 
66  // append
67  $pos = $ilDB->query("SELECT max(pos) mpos FROM il_new_item_grp");
68  $pos = $ilDB->fetchAssoc($pos);
69  $pos = (int) $pos["mpos"];
70  $pos += 10;
71 
72  $seq = $ilDB->nextID("il_new_item_grp");
73 
74  $ilDB->manipulate("INSERT INTO il_new_item_grp" .
75  " (id, titles, pos, type) VALUES (" .
76  $ilDB->quote($seq, "integer") .
77  ", " . $ilDB->quote(serialize($a_titles), "text") .
78  ", " . $ilDB->quote($pos, "integer") .
79  ", " . $ilDB->quote(self::NEW_ITEM_GROUP_TYPE_GROUP, "integer") .
80  ")");
81  return true;
82  }
83 
84  public static function updateNewItemGroup($a_id, array $a_titles)
85  {
86  global $DIC;
87 
88  $ilDB = $DIC->database();
89 
90  $ilDB->manipulate("UPDATE il_new_item_grp" .
91  " SET titles = " . $ilDB->quote(serialize($a_titles), "text") .
92  " WHERE id = " . $ilDB->quote($a_id, "integer"));
93  return true;
94  }
95 
96  public static function deleteNewItemGroup($a_id)
97  {
98  global $DIC;
99 
100  $ilDB = $DIC->database();
101  $ilSetting = $DIC->settings();
102 
103  // move subitems to unassigned
104  $sub_items = self::getNewItemGroupSubItems();
105  $sub_items = $sub_items[$a_id];
106  if ($sub_items) {
107  foreach ($sub_items as $obj_type) {
108  $old_pos = $ilSetting->get("obj_add_new_pos_" . $obj_type);
109  if (strlen($old_pos) == 8) {
110  $new_pos = "9999" . substr($old_pos, 4);
111  $ilSetting->set("obj_add_new_pos_" . $obj_type, $new_pos);
112  $ilSetting->set("obj_add_new_pos_grp_" . $obj_type, 0);
113  }
114  }
115  }
116 
117  $ilDB->manipulate("DELETE FROM il_new_item_grp" .
118  " WHERE id = " . $ilDB->quote($a_id, "integer"));
119  return true;
120  }
121 
122  public static function getNewItemGroups()
123  {
124  global $DIC;
125 
126  $ilDB = $DIC->database();
127  $lng = $DIC->language();
128  $ilUser = $DIC->user();
129 
130  $def_lng = $lng->getDefaultLanguage();
131  $usr_lng = $ilUser->getLanguage();
132 
133  $res = array();
134 
135  $set = $ilDB->query("SELECT * FROM il_new_item_grp ORDER BY pos");
136  while ($row = $ilDB->fetchAssoc($set)) {
137  if ($row["type"] == self::NEW_ITEM_GROUP_TYPE_GROUP) {
138  $row["titles"] = unserialize($row["titles"]);
139 
140  $title = $row["titles"][$usr_lng];
141  if (!$title) {
142  $title = $row["titles"][$def_lng];
143  }
144  if (!$title) {
145  $title = array_shift($row["titles"]);
146  }
147  $row["title"] = $title;
148  } else {
149  $row["title"] = $lng->txt("rep_new_item_group_separator");
150  }
151 
152  $res[$row["id"]] = $row;
153  }
154 
155  return $res;
156  }
157 
158  public static function updateNewItemGroupOrder(array $a_order)
159  {
160  global $DIC;
161 
162  $ilDB = $DIC->database();
163 
164  asort($a_order);
165  $pos = 0;
166  foreach (array_keys($a_order) as $id) {
167  $pos += 10;
168 
169  $ilDB->manipulate("UPDATE il_new_item_grp" .
170  " SET pos = " . $ilDB->quote($pos, "integer") .
171  " WHERE id = " . $ilDB->quote($id, "integer"));
172  }
173  }
174 
175  protected static function getAllObjTypes()
176  {
177  global $DIC;
178 
179  $ilPluginAdmin = $DIC["ilPluginAdmin"];
180  $objDefinition = $DIC["objDefinition"];
181 
182  $res = array();
183 
184  // parse modules
185  include_once("./Services/Component/classes/class.ilModule.php");
186  foreach (ilModule::getAvailableCoreModules() as $mod) {
187  $has_repo = false;
188  $rep_types = $objDefinition->getRepositoryObjectTypesForComponent(IL_COMP_MODULE, $mod["subdir"]);
189  if (sizeof($rep_types) > 0) {
190  foreach ($rep_types as $ridx => $rt) {
191  // we only want to display repository modules
192  if ($rt["repository"]) {
193  $has_repo = true;
194  } else {
195  unset($rep_types[$ridx]);
196  }
197  }
198  }
199  if ($has_repo) {
200  foreach ($rep_types as $rt) {
201  $res[] = $rt["id"];
202  }
203  }
204  }
205 
206  // parse plugins
207  include_once("./Services/Component/classes/class.ilPlugin.php");
208  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "Repository", "robj");
209  foreach ($pl_names as $pl_name) {
210  $pl_id = ilPlugin::lookupIdForName(IL_COMP_SERVICE, "Repository", "robj", $pl_name);
211  if ($pl_id) {
212  $res[] = $pl_id;
213  }
214  }
215 
216  return $res;
217  }
218 
219  public static function getNewItemGroupSubItems()
220  {
221  global $DIC;
222 
223  $ilSetting = $DIC->settings();
224 
225  $res = array();
226 
227  foreach (self::getAllObjTypes() as $type) {
228  $pos_grp = $ilSetting->get("obj_add_new_pos_grp_" . $type, 0);
229  $res[$pos_grp][] = $type;
230  }
231 
232  return $res;
233  }
234 
235  public static function getDefaultNewItemGrouping()
236  {
237  global $DIC;
238 
239  $lng = $DIC->language();
240 
241  $res = array();
242 
243  $groups = array(
244  "organisation" => array("fold", "sess", "cat", "catr", "crs", "crsr", "grp", "grpr", "itgr", "book", "prg"),
245  "communication" => array("frm", "chtr"),
246  "breaker1" => null,
247  "content" => array("file", "webr", "feed", "wiki", "blog", "lm", "htlm", "sahs", "glo", "dcl", "bibl", "mcst", "mep"),
248  "breaker2" => null,
249  "assessment" => array("exc", "tst", "qpl", "iass"),
250  "feedback" => array("poll", "svy", "spl"),
251  "templates" => array("prtt")
252  );
253 
254  $pos = 0;
255  foreach ($groups as $group => $items) {
256  $pos += 10;
257  $grp_id = $pos/10;
258 
259  if (is_array($items)) {
260  $title = $lng->txt("rep_add_new_def_grp_" . $group);
261 
262  $res["groups"][$grp_id] = array("id" => $grp_id,
263  "titles" => array($lng->getUserLanguage() => $title),
264  "pos" => $pos,
265  "type" => self::NEW_ITEM_GROUP_TYPE_GROUP,
266  "title" => $title);
267 
268  foreach ($items as $idx => $item) {
269  $res["items"][$item] = $grp_id;
270  $res["sort"][$item] = str_pad($pos, 4, "0", STR_PAD_LEFT) .
271  str_pad($idx+1, 4, "0", STR_PAD_LEFT);
272  }
273  } else {
274  $title = "COL_SEP";
275 
276  $res["groups"][$grp_id] = array("id" => $grp_id,
277  "titles" => array($lng->getUserLanguage() => $title),
278  "pos" => $pos,
279  "type" => self::NEW_ITEM_GROUP_TYPE_SEPARATOR,
280  "title" => $title);
281  }
282  }
283 
284  return $res;
285  }
286 
287  public static function deleteObjectType($a_type)
288  {
289  global $DIC;
290 
291  $ilSetting = $DIC->settings();
292 
293  // see ilObjRepositorySettingsGUI::saveModules()
294  $ilSetting->delete("obj_dis_creation_" . $a_type);
295  $ilSetting->delete("obj_add_new_pos_" . $a_type);
296  $ilSetting->delete("obj_add_new_pos_grp_" . $a_type);
297  }
298 }
global $DIC
Definition: saml.php:7
__construct($a_id, $a_call_by_reference=true)
Constructor public.
static lookupIdForName($a_ctype, $a_cname, $a_slot_id, $a_plugin_name)
Lookup id for name.
$a_type
Definition: workflow.php:92
foreach($_POST as $key=> $value) $res
const IL_COMP_MODULE
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
static updateNewItemGroupOrder(array $a_order)
static addNewItemGroup(array $a_titles)
global $ilSetting
Definition: privfeed.php:17
global $ilDB
static updateNewItemGroup($a_id, array $a_titles)
const IL_COMP_SERVICE
Class ilObjRepositorySettings.
static getAvailableCoreModules()
Get all available core modules.