ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilLPStatusSCORM.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once './Services/Tracking/classes/class.ilLPStatus.php';
6
16{
17
18 function ilLPStatusSCORM($a_obj_id)
19 {
20 global $ilDB;
21
22 parent::ilLPStatus($a_obj_id);
23 $this->db =& $ilDB;
24 }
25
26
27 function _getInProgress($a_obj_id)
28 {
29 $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
30 $users = array();
31 foreach($status_info['in_progress'] as $in_progress)
32 {
33 $users = array_merge($users,$in_progress);
34 }
35 $users = array_unique($users);
36 $users = array_diff($users,ilLPStatusWrapper::_getCompleted($a_obj_id));
37 $users = array_diff($users,ilLPStatusWrapper::_getFailed($a_obj_id));
38
39 return $users;
40 }
41
42 function _getCompleted($a_obj_id)
43 {
44 global $ilDB;
45
46 include_once './Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php';
47
48 $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
49
50 $items = $status_info['scos'];
51
52 $counter = 0;
53 $users = array();
54 foreach($items as $sco_id)
55 {
56 $tmp_users = $status_info['completed'][$sco_id];
57
58 if(!$counter++)
59 {
60 $users = $tmp_users;
61 }
62 else
63 {
64 $users = array_intersect($users,$tmp_users);
65 }
66 }
67
68 $users = array_diff($users,ilLPStatusWrapper::_getFailed($a_obj_id));
69 return $users;
70 }
71
72 function _getFailed($a_obj_id)
73 {
74 $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
75
76 if(!count($status_info['scos']))
77 {
78 return array();
79 }
80 $users = array();
81 foreach($status_info['scos'] as $sco_id)
82 {
83 /* #17913 - max attempts were removed in 5.1
84 // max attempts vs. failed
85 if(sizeof($status_info['in_progress'][$sco_id]))
86 {
87 foreach($status_info['in_progress'][$sco_id] as $user_id)
88 {
89 if(!in_array($user_id, $status_info['failed'][$sco_id]))
90 {
91 switch($status_info["subtype"])
92 {
93 case 'hacp':
94 case 'aicc':
95 case 'scorm':
96 include_once './Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php';
97 $has_max_attempts = ilObjSCORMTracking::_hasMaxAttempts($a_obj_id, $user_id);
98 break;
99
100 case 'scorm2004':
101 include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Tracking.php");
102 $has_max_attempts = ilSCORM2004Tracking::_hasMaxAttempts($a_obj_id, $user_id);
103 break;
104 }
105
106 if($has_max_attempts)
107 {
108 $status_info['failed'][$sco_id][] = $user_id;
109 }
110 }
111 }
112 }
113 */
114
115 $users = array_merge($users,(array) $status_info['failed'][$sco_id]);
116 }
117 return array_unique($users);
118 }
119
120
121 function _getStatusInfo($a_obj_id)
122 {
123 // Which sco's determine the status
124 include_once './Services/Object/classes/class.ilObjectLP.php';
125 $olp = ilObjectLP::getInstance($a_obj_id);
126 $collection = $olp->getCollectionInstance();
127 if($collection)
128 {
129 $status_info['scos'] = $collection->getItems();
130 }
131 else
132 {
133 $status_info['scos'] = array();
134 }
135 $status_info['num_scos'] = count($status_info['scos']);
136
137 // Get subtype
138 include_once './Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php';
139 $status_info['subtype'] = ilObjSAHSLearningModule::_lookupSubType($a_obj_id);
140
141 switch($status_info['subtype'])
142 {
143 case 'hacp':
144 case 'aicc':
145 include_once './Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php';
146 $status_info['num_completed'] = ilObjSCORMTracking::_getCountCompletedPerUser($status_info['scos'],$a_obj_id);
147
148 include_once './Modules/ScormAicc/classes/class.ilObjAICCLearningModule.php';
149 foreach(ilObjAICCLearningModule::_getTrackingItems($a_obj_id) as $item)
150 {
151 if(in_array($item['obj_id'],$status_info['scos']))
152 {
153 $status_info['scos_title']["$item[obj_id]"] = $item['title'];
154 }
155 }
156 $info = ilObjSCORMTracking::_getProgressInfo($status_info['scos'],$a_obj_id);
157 break;
158
159 case 'scorm':
160 include_once './Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php';
161 $status_info['num_completed'] = ilObjSCORMTracking::_getCountCompletedPerUser($status_info['scos'],$a_obj_id);
162
163 include_once './Modules/ScormAicc/classes/SCORM/class.ilSCORMItem.php';
164 foreach($status_info['scos'] as $sco_id)
165 {
166 $status_info['scos_title'][$sco_id] = ilSCORMItem::_lookupTitle($sco_id);
167 }
168 $info = ilObjSCORMTracking::_getProgressInfo($status_info['scos'],$a_obj_id);
169 break;
170
171 case "scorm2004":
172 include_once './Modules/Scorm2004/classes/class.ilSCORM2004Tracking.php';
173 $status_info['num_completed'] = ilSCORM2004Tracking::_getCountCompletedPerUser($status_info['scos'],$a_obj_id,true);
174 include_once './Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php';
175 foreach($status_info['scos'] as $sco_id)
176 {
177 $status_info['scos_title'][$sco_id] = ilObjSCORM2004LearningModule::_lookupItemTitle($sco_id);
178 }
179
180 $info = ilSCORM2004Tracking::_getItemProgressInfo($status_info['scos'],$a_obj_id,true);
181 break;
182 }
183
184 $status_info['completed'] = array();
185 $status_info['failed'] = array();
186 $status_info['in_progress'] = array();
187 foreach($status_info['scos'] as $sco_id)
188 {
189 $status_info['completed'][$sco_id] = $info['completed'][$sco_id] ? $info['completed'][$sco_id] : array();
190 $status_info['failed'][$sco_id] = $info['failed'][$sco_id] ? $info['failed'][$sco_id] : array();
191 $status_info['in_progress'][$sco_id] = $info['in_progress'][$sco_id] ? $info['in_progress'][$sco_id] : array();
192 }
193//var_dump($status_info["completed"]);
194 return $status_info;
195 }
196
205 function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
206 {
207 global $ilObjDataCache, $ilDB, $ilLog;
208
210
211 // if the user has accessed the scorm object
212 // the status is at least "in progress"
213 include_once("./Services/Tracking/classes/class.ilChangeEvent.php");
214 if (ilChangeEvent::hasAccessed($a_obj_id, $a_user_id))
215 {
217 }
218//$ilLog->write("-".$status."-");
219
220 // Which sco's determine the status
221 include_once './Services/Object/classes/class.ilObjectLP.php';
222 $olp = ilObjectLP::getInstance($a_obj_id);
223 $collection = $olp->getCollectionInstance();
224 if($collection)
225 {
226 $scos = $collection->getItems();
227 if(sizeof($scos)) // #15462 (#11513 - empty collections cannot be completed)
228 {
229 include_once './Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php';
230 $subtype = ilObjSAHSLearningModule::_lookupSubType($a_obj_id);
231 switch($subtype)
232 {
233 case 'hacp':
234 case 'aicc':
235 case 'scorm':
236 include_once("./Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php");
237 $scorm_status = ilObjSCORMTracking::_getCollectionStatus($scos, $a_obj_id, $a_user_id);
238 break;
239
240 case 'scorm2004':
241 include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Tracking.php");
242 $scorm_status = ilSCORM2004Tracking::_getCollectionStatus($scos, $a_obj_id, $a_user_id);
243 break;
244 }
245
246 switch ($scorm_status)
247 {
248 case "in_progress":
250 break;
251 case "completed":
253 break;
254 case "failed":
256 break;
257 }
258 }
259 }
260
261//$ilLog->write("-".$status."-");
262 return $status;
263 }
264
273 function determinePercentage($a_obj_id, $a_user_id, $a_obj = null)
274 {
275 // Which sco's determine the status
276 include_once './Services/Object/classes/class.ilObjectLP.php';
277 $olp = ilObjectLP::getInstance($a_obj_id);
278 $collection = $olp->getCollectionInstance();
279 if($collection)
280 {
281 $scos = $collection->getItems();
282 $reqscos = count($scos);
283
284 include_once './Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php';
285 $subtype = ilObjSAHSLearningModule::_lookupSubType($a_obj_id);
286 if ($subtype != "scorm2004")
287 {
288 include_once("./Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php");
289 $compl = ilObjSCORMTracking::_countCompleted($scos, $a_obj_id, $a_user_id);
290 }
291 else
292 {
293 include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Tracking.php");
294 $compl = ilSCORM2004Tracking::_countCompleted($scos, $a_obj_id, $a_user_id, true);
295 }
296 }
297
298 if ($reqscos > 0)
299 {
300 $per = min(100, 100 / $reqscos * $compl);
301 }
302 else
303 {
304 $per = 100;
305 }
306
307 return $per;
308 }
309
310 function refreshStatus($a_obj_id)
311 {
312 parent::refreshStatus($a_obj_id);
313
314 // this is restricted to SCOs in the current collection
315 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
316 $in_progress = ilLPStatusWrapper::_getInProgress($a_obj_id);
317 $completed = ilLPStatusWrapper::_getCompleted($a_obj_id);
319 $all_active_users = array_unique(array_merge($in_progress, $completed, $failed));
320
321 // get all tracked users regardless of SCOs
322 include_once './Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php';
323 $subtype = ilObjSAHSLearningModule::_lookupSubType($a_obj_id);
324 if ($subtype != "scorm2004")
325 {
326 include_once("./Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php");
327 $all_tracked_users = ilObjSCORMTracking::_getTrackedUsers($a_obj_id);
328 }
329 else
330 {
331 include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Tracking.php");
332 $all_tracked_users = ilSCORM2004Tracking::_getTrackedUsers($a_obj_id);
333 }
334
335 $not_attempted_users = array_diff($all_tracked_users, $all_active_users);
336 unset($all_tracked_users);
337 unset($all_active_users);
338
339 // reset all users which have no data for the current SCOs
340 if($not_attempted_users)
341 {
342 foreach($not_attempted_users as $usr_id)
343 {
344 // this will update any (parent) collections if necessary
345 ilLPStatus::writeStatus($a_obj_id, $usr_id, self::LP_STATUS_NOT_ATTEMPTED_NUM, 0);
346 }
347 }
348 }
349}
350?>
$failed
Definition: Utf8Test.php:86
static hasAccessed($a_obj_id, $a_usr_id)
Has accessed.
determineStatus($a_obj_id, $a_user_id, $a_obj=null)
Determine status.
determinePercentage($a_obj_id, $a_user_id, $a_obj=null)
Determine percentage.
_getCompleted($a_obj_id)
Static function to read the users who have the status 'completed'.
_getFailed($a_obj_id)
Static function to read the users who have the status 'completed'.
_getStatusInfo($a_obj_id)
Reads informations about the object e.g test results, tlt, number of visits.
_getInProgress($a_obj_id)
Static function to read users who have the status 'in_progress'.
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
const LP_STATUS_COMPLETED_NUM
const LP_STATUS_IN_PROGRESS_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
const LP_STATUS_FAILED_NUM
static writeStatus($a_obj_id, $a_user_id, $a_status, $a_percentage=false, $a_force_per=false)
Write status for user and object.
_getTrackingItems($a_obj_id)
get all tracking items of scorm object
_lookupSubType($a_obj_id)
lookup subtype id (scorm, aicc, hacp)
static _getProgressInfo($sco_item_ids, $a_obj_id)
Get info about.
static _countCompleted($a_scos, $a_obj_id, $a_user_id)
static _getCollectionStatus($a_scos, $a_obj_id, $a_user_id)
static _getCountCompletedPerUser($a_scorm_item_ids, $a_obj_id)
Get users who have status completed or passed.
_getTrackedUsers($a_obj_id)
Get all tracked users.
static getInstance($a_obj_id)
static _countCompleted($a_scos, $a_obj_id, $a_user_id, $a_omit_failed=false)
_getCountCompletedPerUser($a_scorm_item_ids, $a_obj_id, $a_omit_failed=false)
Get progress of selected scos.
static _getCollectionStatus($a_scos, $a_obj_id, $a_user_id)
_getTrackedUsers($a_obj_id)
Get all tracked users.
_getItemProgressInfo($a_scorm_item_ids, $a_obj_id, $a_omit_failed=false)
_lookupTitle($a_obj_id)
$info
Definition: example_052.php:80
global $ilDB