ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjectLP.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once "Services/Tracking/classes/class.ilLPObjSettings.php";
6 
15 {
16  protected $obj_id; // [int]
17  protected $collection_instance; // [ilLPCollection]
18  protected $mode; // [int]
19 
20  protected function __construct($a_obj_id)
21  {
22  $this->obj_id = (int)$a_obj_id;
23  }
24 
25  public static function getInstance($a_obj_id)
26  {
27  global $objDefinition;
28 
29  static $instances = array();
30 
31  if(!isset($instances[$a_obj_id]))
32  {
33  $type = ilObject::_lookupType($a_obj_id);
34  switch($type)
35  {
36  // container
37 
38  case "crs":
39  include_once "Modules/Course/classes/class.ilCourseLP.php";
40  $instance = new ilCourseLP($a_obj_id);
41  break;
42 
43  case "grp":
44  include_once "Modules/Group/classes/class.ilGroupLP.php";
45  $instance = new ilGroupLP($a_obj_id);
46  break;
47 
48  case "fold":
49  include_once "Modules/Folder/classes/class.ilFolderLP.php";
50  $instance = new ilFolderLP($a_obj_id);
51  break;
52 
53 
54  // learning resources
55 
56  case "lm":
57  include_once "Modules/LearningModule/classes/class.ilLearningModuleLP.php";
58  $instance = new ilLearningModuleLP($a_obj_id);
59  break;
60 
61  case "htlm":
62  include_once "Modules/HTMLLearningModule/classes/class.ilHTMLLearningModuleLP.php";
63  $instance = new ilHTMLLearningModuleLP($a_obj_id);
64  break;
65 
66  case "sahs":
67  include_once "Modules/ScormAicc/classes/class.ilScormLP.php";
68  $instance = new ilScormLP($a_obj_id);
69  break;
70 
71 
72  // misc
73 
74  case "tst":
75  include_once "Modules/Test/classes/class.ilTestLP.php";
76  $instance = new ilTestLP($a_obj_id);
77  break;
78 
79  case "exc":
80  include_once "Modules/Exercise/classes/class.ilExerciseLP.php";
81  $instance = new ilExerciseLP($a_obj_id);
82  break;
83 
84  case "sess":
85  include_once "Modules/Session/classes/class.ilSessionLP.php";
86  $instance = new ilSessionLP($a_obj_id);
87  break;
88 
89  // plugin
90  case $objDefinition->isPluginTypeName($type):
91  include_once "Services/Component/classes/class.ilPluginLP.php";
92  $instance = new ilPluginLP($a_obj_id);
93  break;
94 
95  default:
96  // :TODO: should we return anything?
97  $instance = new self($a_obj_id);
98  break;
99  }
100 
101  $instances[$a_obj_id] = $instance;
102  }
103 
104  return $instances[$a_obj_id];
105  }
106 
107  public function resetCaches()
108  {
109  $this->mode = null;
110  $this->collection_instance = null;
111  }
112 
113  public function isAnonymized()
114  {
115  // see ilLPCollectionOfRepositoryObjects::validateEntry()
116  return false;
117  }
118 
119 
120  //
121  // MODE
122  //
123 
124  public function getDefaultMode()
125  {
127  }
128 
129  public function getValidModes()
130  {
131  return array();
132  }
133 
134  public function getCurrentMode()
135  {
136  if($this->mode === null)
137  {
138  $mode = ilLPObjSettings::_lookupDBMode($this->obj_id);
139  if($mode === null)
140  {
141  $mode = $this->getDefaultMode();
142  }
143  $this->mode = (int)$mode;
144  }
145 
146  return $this->mode;
147  }
148 
149  public function isActive()
150  {
151  // :TODO: check LP activation?
152 
153  $mode = $this->getCurrentMode();
156  {
157  return false;
158  }
159  return true;
160  }
161 
162  public function getModeText($a_mode)
163  {
164  return ilLPObjSettings::_mode2Text($a_mode);
165  }
166 
167  public function getModeInfoText($a_mode)
168  {
169  return ilLPObjSettings::_mode2InfoText($a_mode);
170  }
171 
172 
173  //
174  // COLLECTION
175  //
176 
177  public function getCollectionInstance()
178  {
179  // :TODO: factory if not plugin ?!
180  // => move to ilLPCollection::getInstance() ?!
181 
182  if($this->collection_instance === null)
183  {
184  $path = "Services/Tracking/classes/collection/";
185 
186  $mode = $this->getCurrentMode();
187  switch($mode)
188  {
191  include_once $path."class.ilLPCollectionOfRepositoryObjects.php";
192  $this->collection_instance = new ilLPCollectionOfRepositoryObjects($this->obj_id, $mode);
193  break;
194 
196  include_once $path."class.ilLPCollectionOfObjectives.php";
197  $this->collection_instance = new ilLPCollectionOfObjectives($this->obj_id, $mode);
198  break;
199 
201  include_once $path."class.ilLPCollectionOfSCOs.php";
202  $this->collection_instance = new ilLPCollectionOfSCOs($this->obj_id, $mode);
203  break;
204 
207  include_once $path."class.ilLPCollectionOfLMChapters.php";
208  $this->collection_instance = new ilLPCollectionOfLMChapters($this->obj_id, $mode);
209  break;
210 
211  default:
212  $this->collection_instance = false;
213  break;
214  }
215  }
216 
218  }
219 
220 
221  //
222  // MEMBERS
223  //
224 
225  public function getMembers($a_search = true)
226  {
227  global $tree;
228 
229  if(!$a_search)
230  {
231  return;
232  }
233 
234  $ref_ids = ilObject::_getAllReferences($this->obj_id);
235  $ref_id = current($ref_ids);
236 
237  // walk path to find parent with specific members
238  $path = $tree->getPathId($ref_id);
239  array_pop($path);
240  foreach(array_reverse($path) as $path_ref_id)
241  {
242  $olp = self::getInstance(ilObject::_lookupObjId($path_ref_id));
243  $all = $olp->getMembers(false);
244  if(is_array($all))
245  {
246  return $all;
247  }
248  }
249  }
250 
251 
252  //
253  // RESET
254  //
255 
256  final public function resetLPDataForCompleteObject($a_recursive = true)
257  {
258  $user_ids = $this->gatherLPUsers();
259  if(sizeof($user_ids))
260  {
261  $this->resetLPDataForUserIds(array_unique($user_ids), $a_recursive);
262  }
263  }
264 
265  final public function resetLPDataForUserIds(array $a_user_ids, $a_recursive = true)
266  {
267  if((bool)$a_recursive)
268  {
269  $subitems = $this->getPossibleCollectionItems();
270  if(is_array($subitems))
271  {
272  foreach($subitems as $sub_ref_id)
273  {
274  $olp = self::getInstance(ilObject::_lookupObjId($sub_ref_id));
275  $olp->resetLPDataForUserIds($a_user_ids, false);
276  }
277  }
278  }
279 
280  $this->resetCustomLPDataForUserIds($a_user_ids, (bool)$a_recursive);
281 
282  include_once "Services/Tracking/classes/class.ilLPMarks.php";
283  ilLPMarks::_deleteForUsers($this->obj_id, $a_user_ids);
284 
285  include_once "Services/Tracking/classes/class.ilChangeEvent.php";
286  ilChangeEvent::_deleteReadEventsForUsers($this->obj_id, $a_user_ids);
287 
288  // update LP status to get collections up-to-date
289  include_once "Services/Tracking/classes/class.ilLPStatusWrapper.php";
290  foreach($a_user_ids as $user_id)
291  {
292  ilLPStatusWrapper::_updateStatus($this->obj_id, $user_id);
293  }
294  }
295 
296  protected function resetCustomLPDataForUserIds(array $a_user_ids, $a_recursive = true)
297  {
298  // this should delete all data that is relevant for the supported LP modes
299  }
300 
301  protected function gatherLPUsers()
302  {
303  include_once "Services/Tracking/classes/class.ilLPMarks.php";
304  $user_ids = ilLPMarks::_getAllUserIds($this->obj_id);
305 
306  include_once "Services/Tracking/classes/class.ilChangeEvent.php";
307  $user_ids = array_merge($user_ids, ilChangeEvent::_getAllUserIds($this->obj_id));
308 
309  return $user_ids;
310  }
311 
312 
313  //
314  // EVENTS
315  //
316 
317  final static public function handleMove($a_source_ref_id)
318  {
319  global $tree, $ilDB;
320 
321  $ref_ids = $tree->getSubTreeIds($a_source_ref_id);
322  $ref_ids[] = $a_source_ref_id;
323 
324  // get "parent" path to source node (not including source node)
325  $new_path = $tree->getPathId($a_source_ref_id);
326  array_pop($new_path);
327  $new_path = implode("/", $new_path);
328 
329  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
330 
331  // find collections with ref_ids
332  $set = $ilDB->query("SELECT DISTINCT(ut_lp_collections.obj_id) obj_id".
333  " FROM object_reference".
334  " JOIN ut_lp_collections ON".
335  " (".$ilDB->in("object_reference.ref_id", $ref_ids, "", "integer").
336  " AND object_reference.ref_id = ut_lp_collections.item_id)");
337  while ($rec = $ilDB->fetchAssoc($set))
338  {
339  if (in_array(ilObject::_lookupType($rec["obj_id"]), array("crs", "grp", "fold")))
340  {
341  $coll_ref_id = ilObject::_getAllReferences($rec["obj_id"]);
342  $coll_ref_id = array_pop($coll_ref_id);
343 
344  // #13402
345  if($coll_ref_id == $a_source_ref_id)
346  {
347  continue;
348  }
349 
350  // #17703 - collection has also been moved - nothing todo
351  if($tree->isGrandChild($a_source_ref_id, $coll_ref_id))
352  {
353  continue;
354  }
355 
356  // get path to collection (including collection "parent")
357  $coll_path = $tree->getPathId($coll_ref_id);
358  $coll_path = implode("/", $coll_path);
359 
360  // collection path is not inside new path
361  if(!stristr($new_path, $coll_path))
362  {
363  // delete all items of moved (sub-)tree
364  $query = "DELETE FROM ut_lp_collections".
365  " WHERE obj_id = ".$ilDB->quote($rec["obj_id"], "integer").
366  " AND ".$ilDB->in("item_id", $ref_ids, "", "integer");
367  $ilDB->manipulate($query);
368 
369  ilLPStatusWrapper::_refreshStatus($rec["obj_id"]);
370  }
371  }
372  }
373  }
374 
375  final public function handleToTrash()
376  {
377  $this->updateParentCollections();
378  }
379 
380  final public function handleDelete()
381  {
382  include_once "Services/Tracking/classes/class.ilLPMarks.php";
383  ilLPMarks::deleteObject($this->obj_id);
384 
385  include_once "Services/Tracking/classes/class.ilChangeEvent.php";
386  ilChangeEvent::_delete($this->obj_id);
387 
388  $collection = $this->getCollectionInstance();
389  if($collection)
390  {
391  $collection->delete();
392  }
393 
394  $this->updateParentCollections();
395  }
396 
397  final protected function updateParentCollections()
398  {
399  global $ilDB;
400 
401  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
402 
403  // update parent collections?
404  $set = $ilDB->query("SELECT ut_lp_collections.obj_id obj_id FROM ".
405  "object_reference JOIN ut_lp_collections ON ".
406  "(object_reference.obj_id = ".$ilDB->quote($this->obj_id, "integer").
407  " AND object_reference.ref_id = ut_lp_collections.item_id)");
408  while ($rec = $ilDB->fetchAssoc($set))
409  {
410  if (in_array(ilObject::_lookupType($rec["obj_id"]), array("crs", "grp", "fold")))
411  {
412  // remove from parent collection
413  $query = "DELETE FROM ut_lp_collections".
414  " WHERE obj_id = ".$ilDB->quote($rec["obj_id"], "integer").
415  " AND item_id = ".$ilDB->quote($this->obj_id, "integer");
416  $ilDB->manipulate($query);
417 
418  ilLPStatusWrapper::_refreshStatus($rec["obj_id"]);
419  }
420  }
421  }
422 }
423 
424 ?>