ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
5 include_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  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
30  include_once './Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php';
31 
32  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
33  $users = array();
34 
35  foreach($status_info['in_progress'] as $in_progress)
36  {
37  $users = array_merge($users,$in_progress);
38  }
39  $users = array_unique($users);
40  $users = array_diff($users,ilLPStatusWrapper::_getCompleted($a_obj_id));
41  $users = array_diff($users,ilLPStatusWrapper::_getFailed($a_obj_id));
42 
43  return $users;
44  }
45 
46  function _getCompleted($a_obj_id)
47  {
48  global $ilDB;
49 
50  include_once './Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php';
51 
52  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
53 
54  $items = $status_info['scos'];
55 
56  $counter = 0;
57  $users = array();
58  foreach($items as $sco_id)
59  {
60  $tmp_users = $status_info['completed'][$sco_id];
61 
62  if(!$counter++)
63  {
64  $users = $tmp_users;
65  }
66  else
67  {
68  $users = array_intersect($users,$tmp_users);
69  }
70  }
71 
72  $users = array_diff($users,ilLPStatusWrapper::_getFailed($a_obj_id));
73  return $users;
74  }
75 
76  function _getFailed($a_obj_id)
77  {
78  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
79 
80  if(!count($status_info['scos']))
81  {
82  return array();
83  }
84  $users = array();
85  foreach($status_info['scos'] as $sco_id)
86  {
87  // max attempts vs. failed
88  if(sizeof($status_info['in_progress'][$sco_id]))
89  {
90  foreach($status_info['in_progress'][$sco_id] as $user_id)
91  {
92  if(!in_array($user_id, $status_info['failed'][$sco_id]))
93  {
94  switch($status_info["subtype"])
95  {
96  case 'hacp':
97  case 'aicc':
98  case 'scorm':
99  include_once './Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php';
100  $has_max_attempts = ilObjSCORMTracking::_hasMaxAttempts($a_obj_id, $user_id);
101  break;
102 
103  case 'scorm2004':
104  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Tracking.php");
105  $has_max_attempts = ilSCORM2004Tracking::_hasMaxAttempts($a_obj_id, $user_id);
106  break;
107  }
108 
109  if($has_max_attempts)
110  {
111  $status_info['failed'][$sco_id][] = $user_id;
112  }
113  }
114  }
115  }
116 
117  $users = array_merge($users,(array) $status_info['failed'][$sco_id]);
118  }
119  return array_unique($users);
120  }
121 
122 
123  function _getStatusInfo($a_obj_id)
124  {
125  // Which sco's determine the status
126  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
127  $status_info['scos'] = ilLPCollectionCache::_getItems($a_obj_id);
128 
129  $status_info['num_scos'] = count($status_info['scos']);
130 
131  // Get subtype
132  include_once './Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php';
133  $status_info['subtype'] = ilObjSAHSLearningModule::_lookupSubType($a_obj_id);
134 
135  switch($status_info['subtype'])
136  {
137  case 'hacp':
138  case 'aicc':
139  include_once './Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php';
140  $status_info['num_completed'] = ilObjSCORMTracking::_getCountCompletedPerUser($status_info['scos'],$a_obj_id);
141 
142  include_once './Modules/ScormAicc/classes/class.ilObjAICCLearningModule.php';
143  foreach(ilObjAICCLearningModule::_getTrackingItems($a_obj_id) as $item)
144  {
145  if(in_array($item['obj_id'],$status_info['scos']))
146  {
147  $status_info['scos_title']["$item[obj_id]"] = $item['title'];
148  }
149  }
150  $info = ilObjSCORMTracking::_getProgressInfo($status_info['scos'],$a_obj_id);
151  break;
152 
153  case 'scorm':
154  include_once './Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php';
155  $status_info['num_completed'] = ilObjSCORMTracking::_getCountCompletedPerUser($status_info['scos'],$a_obj_id);
156 
157  include_once './Modules/ScormAicc/classes/SCORM/class.ilSCORMItem.php';
158  foreach($status_info['scos'] as $sco_id)
159  {
160  $status_info['scos_title'][$sco_id] = ilSCORMItem::_lookupTitle($sco_id);
161  }
162  $info = ilObjSCORMTracking::_getProgressInfo($status_info['scos'],$a_obj_id);
163  break;
164 
165  case "scorm2004":
166  include_once './Modules/Scorm2004/classes/class.ilSCORM2004Tracking.php';
167  $status_info['num_completed'] = ilSCORM2004Tracking::_getCountCompletedPerUser($status_info['scos'],$a_obj_id,true);
168  include_once './Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php';
169  foreach($status_info['scos'] as $sco_id)
170  {
171  $status_info['scos_title'][$sco_id] = ilObjSCORM2004LearningModule::_lookupItemTitle($sco_id);
172  }
173 
174  $info = ilSCORM2004Tracking::_getItemProgressInfo($status_info['scos'],$a_obj_id,true);
175  break;
176  }
177 
178  $status_info['completed'] = array();
179  $status_info['failed'] = array();
180  $status_info['in_progress'] = array();
181  foreach($status_info['scos'] as $sco_id)
182  {
183  $status_info['completed'][$sco_id] = $info['completed'][$sco_id] ? $info['completed'][$sco_id] : array();
184  $status_info['failed'][$sco_id] = $info['failed'][$sco_id] ? $info['failed'][$sco_id] : array();
185  $status_info['in_progress'][$sco_id] = $info['in_progress'][$sco_id] ? $info['in_progress'][$sco_id] : array();
186  }
187 //var_dump($status_info["completed"]);
188  return $status_info;
189  }
190 
199  function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
200  {
201  global $ilObjDataCache, $ilDB, $ilLog;
202 
203  $status = LP_STATUS_NOT_ATTEMPTED_NUM;
204 
205  // if the user has accessed the scorm object
206  // the status is at least "in progress"
207  include_once("./Services/Tracking/classes/class.ilChangeEvent.php");
208  if (ilChangeEvent::hasAccessed($a_obj_id, $a_user_id))
209  {
210  $status = LP_STATUS_IN_PROGRESS_NUM;
211  }
212 //$ilLog->write("-".$status."-");
213  // Which sco's determine the status
214  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
215  include_once './Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php';
216  $scos = ilLPCollectionCache::_getItems($a_obj_id);
217  $completed = true;
218  $failed = false;
219  $subtype = ilObjSAHSLearningModule::_lookupSubType($a_obj_id);
220  switch($subtype)
221  {
222  case 'hacp':
223  case 'aicc':
224  case 'scorm':
225  include_once("./Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php");
226  $scorm_status = ilObjSCORMTracking::_getCollectionStatus($scos, $a_obj_id, $a_user_id);
227  break;
228 
229  case 'scorm2004':
230  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Tracking.php");
231  $scorm_status = ilSCORM2004Tracking::_getCollectionStatus($scos, $a_obj_id, $a_user_id);
232  break;
233  }
234 
235  switch ($scorm_status)
236  {
237  case "in_progress":
238  $status = LP_STATUS_IN_PROGRESS_NUM;
239  break;
240  case "completed":
241  $status = LP_STATUS_COMPLETED_NUM;
242  break;
243  case "failed":
244  $status = LP_STATUS_FAILED_NUM;
245  break;
246  }
247 //$ilLog->write("-".$status."-");
248  return $status;
249  }
250 
259  function determinePercentage($a_obj_id, $a_user_id, $a_obj = null)
260  {
261  // Which sco's determine the status
262  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
263  $scos = ilLPCollectionCache::_getItems($a_obj_id);
264  $reqscos = count($scos);
265 
266  include_once './Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php';
267  $subtype = ilObjSAHSLearningModule::_lookupSubType($a_obj_id);
268 
269  if ($subtype != "scorm2004")
270  {
271  include_once("./Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php");
272  $compl = ilObjSCORMTracking::_countCompleted($scos, $a_obj_id, $a_user_id);
273  }
274  else
275  {
276  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Tracking.php");
277  $compl = ilSCORM2004Tracking::_countCompleted($scos, $a_obj_id, $a_user_id, true);
278  }
279 
280  if ($reqscos > 0)
281  {
282  $per = min(100, 100 / $reqscos * $compl);
283  }
284  else
285  {
286  $per = 100;
287  }
288 
289  return $per;
290  }
291 
292  function refreshStatus($a_obj_id)
293  {
294  parent::refreshStatus($a_obj_id);
295 
296  // this is restricted to SCOs in the current collection
297  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
298  $in_progress = ilLPStatusWrapper::_getInProgress($a_obj_id);
299  $completed = ilLPStatusWrapper::_getCompleted($a_obj_id);
301  $all_active_users = array_unique(array_merge($in_progress, $completed, $failed));
302 
303  // get all tracked users regardless of SCOs
304  include_once './Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php';
305  $subtype = ilObjSAHSLearningModule::_lookupSubType($a_obj_id);
306  if ($subtype != "scorm2004")
307  {
308  include_once("./Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php");
309  $all_tracked_users = ilObjSCORMTracking::_getTrackedUsers($a_obj_id);
310  }
311  else
312  {
313  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Tracking.php");
314  $all_tracked_users = ilSCORM2004Tracking::_getTrackedUsers($a_obj_id);
315  }
316 
317  $not_attempted_users = array_diff($all_tracked_users, $all_active_users);
318  unset($all_tracked_users);
319  unset($all_active_users);
320 
321  // reset all users which have no data for the current SCOs
322  if($not_attempted_users)
323  {
324  foreach($not_attempted_users as $usr_id)
325  {
326  // this will update any (parent) collections if necessary
327  ilLPStatus::writeStatus($a_obj_id, $usr_id, LP_STATUS_NOT_ATTEMPTED_NUM, 0);
328  }
329  }
330  }
331 }
332 ?>