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