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