ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilLPStatusSCORM.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=0);
20 
26 {
27  public static function _getInProgress(int $a_obj_id): array
28  {
29  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
30  $users = array();
31  foreach ($status_info['in_progress'] as $in_progress) {
32  $users = array_merge($users, $in_progress);
33  }
34  $users = array_unique($users);
35  $users = array_diff(
36  $users,
38  );
39  $users = array_diff($users, ilLPStatusWrapper::_getFailed($a_obj_id));
40 
41  return $users;
42  }
43 
44  public static function _getCompleted(int $a_obj_id): array
45  {
46  global $DIC;
47 
48  $ilDB = $DIC['ilDB'];
49 
50  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
51  $items = $status_info['scos'];
52  $counter = 0;
53  $users = array();
54  foreach ($items as $sco_id) {
55  $tmp_users = $status_info['completed'][$sco_id];
56 
57  if (!$counter++) {
58  $users = $tmp_users;
59  } else {
60  $users = array_intersect($users, $tmp_users);
61  }
62  }
63 
64  $users = array_diff($users, ilLPStatusWrapper::_getFailed($a_obj_id));
65  return $users;
66  }
67 
68  public static function _getFailed(int $a_obj_id): array
69  {
70  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
71 
72  if (!count($status_info['scos'])) {
73  return array();
74  }
75  $users = array();
76  foreach ($status_info['scos'] as $sco_id) {
77  $users = array_merge(
78  $users,
79  (array) $status_info['failed'][$sco_id]
80  );
81  }
82  return array_unique($users);
83  }
84 
85  public static function _getNotAttempted(int $a_obj_id): array
86  {
87  $users = array();
88 
89  $members = ilObjectLP::getInstance($a_obj_id)->getMembers();
90  if ($members) {
91  // diff in progress and completed (use stored result in LPStatusWrapper)
92  $users = array_diff(
93  (array) $members,
95  );
96  $users = array_diff(
97  $users,
99  );
100  $users = array_diff(
101  $users,
103  );
104  }
105 
106  return $users;
107  }
108 
109  public static function _getStatusInfo(int $a_obj_id): array
110  {
111  // Which sco's determine the status
112  $olp = ilObjectLP::getInstance($a_obj_id);
113  $collection = $olp->getCollectionInstance();
114  if ($collection) {
115  $status_info['scos'] = $collection->getItems();
116  } else {
117  $status_info['scos'] = array();
118  }
119  $status_info['num_scos'] = count($status_info['scos']);
120 
121  // Get subtype
122  $status_info['subtype'] = ilObjSAHSLearningModule::_lookupSubType(
123  $a_obj_id
124  );
125  $info = [];
126  switch ($status_info['subtype']) {
127  case 'hacp':
128  case 'aicc':
129  $status_info['num_completed'] = ilObjSCORMTracking::_getCountCompletedPerUser(
130  $status_info['scos'],
131  $a_obj_id
132  );
133 
134  foreach (ilObjAICCLearningModule::_getTrackingItems(
135  $a_obj_id
136  ) as $item) {
137  if (in_array($item['obj_id'], $status_info['scos'])) {
138  $status_info['scos_title']["$item[obj_id]"] = $item['title'];
139  }
140  }
142  $status_info['scos'],
143  $a_obj_id
144  );
145  break;
146 
147  case 'scorm':
148  $status_info['num_completed'] = ilObjSCORMTracking::_getCountCompletedPerUser(
149  $status_info['scos'],
150  $a_obj_id
151  );
152 
153  foreach ($status_info['scos'] as $sco_id) {
154  $status_info['scos_title'][$sco_id] = ilSCORMItem::_lookupTitle(
155  $sco_id
156  );
157  }
159  $status_info['scos'],
160  $a_obj_id
161  );
162  break;
163 
164  case "scorm2004":
165  $status_info['num_completed'] = ilSCORM2004Tracking::_getCountCompletedPerUser(
166  $status_info['scos'],
167  $a_obj_id,
168  true
169  );
170  foreach ($status_info['scos'] as $sco_id) {
171  $status_info['scos_title'][$sco_id] = ilObjSCORM2004LearningModule::_lookupItemTitle(
172  $sco_id
173  );
174  }
175 
177  $status_info['scos'],
178  $a_obj_id,
179  true
180  );
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  $status_info['completed'][$sco_id] = $info['completed'][$sco_id] ?? array();
189  $status_info['failed'][$sco_id] = $info['failed'][$sco_id] ?? array();
190  $status_info['in_progress'][$sco_id] = $info['in_progress'][$sco_id] ?? array();
191  }
192  //var_dump($status_info["completed"]);
193  return $status_info;
194  }
195 
196  public function determineStatus(
197  int $a_obj_id,
198  int $a_usr_id,
199  ?object $a_obj = null
200  ): int {
201  global $DIC;
202 
203  $status = self::LP_STATUS_NOT_ATTEMPTED_NUM;
204 
205  // if the user has accessed the scorm object
206  // the status is at least "in progress"
207  if (ilChangeEvent::hasAccessed($a_obj_id, $a_usr_id)) {
208  $status = self::LP_STATUS_IN_PROGRESS_NUM;
209  }
210  // Which sco's determine the status
211  $olp = ilObjectLP::getInstance($a_obj_id);
212  $collection = $olp->getCollectionInstance();
213  if ($collection) {
214  $scos = $collection->getItems();
215  if (sizeof(
216  $scos
217  )) { // #15462 (#11513 - empty collections cannot be completed)
218  $subtype = ilObjSAHSLearningModule::_lookupSubType($a_obj_id);
219  $scorm_status = '';
220  switch ($subtype) {
221  case 'hacp':
222  case 'aicc':
223  case 'scorm':
225  $scos,
226  $a_obj_id,
227  $a_usr_id
228  );
229  break;
230 
231  case 'scorm2004':
233  $scos,
234  $a_obj_id,
235  $a_usr_id
236  );
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 
258  public function determinePercentage(
259  int $a_obj_id,
260  int $a_usr_id,
261  ?object $a_obj = null
262  ): int {
263  // Which sco's determine the status
264  $olp = ilObjectLP::getInstance($a_obj_id);
265  $collection = $olp->getCollectionInstance();
266  $reqscos = 0;
267  $compl = 0;
268  if ($collection) {
269  $scos = $collection->getItems();
270  $reqscos = count($scos);
271 
272  $subtype = ilObjSAHSLearningModule::_lookupSubType($a_obj_id);
273  if ($subtype != "scorm2004") {
275  $scos,
276  $a_obj_id,
277  $a_usr_id
278  );
279  } else {
281  $scos,
282  $a_obj_id,
283  $a_usr_id,
284  true
285  );
286  }
287  }
288 
289  if ($reqscos > 0) {
290  $per = (int) min(100, 100 / $reqscos * $compl);
291  } else {
292  $per = 100;
293  }
294 
295  return $per;
296  }
297 
298  public function refreshStatus(int $a_obj_id, ?array $a_users = null): void
299  {
300  parent::refreshStatus($a_obj_id, $a_users);
301 
302  // this is restricted to SCOs in the current collection
303  $in_progress = ilLPStatusWrapper::_getInProgress($a_obj_id);
304  $completed = ilLPStatusWrapper::_getCompleted($a_obj_id);
305  $failed = ilLPStatusWrapper::_getFailed($a_obj_id);
306  $all_active_users = array_unique(
307  array_merge($in_progress, $completed, $failed)
308  );
309 
310  // get all tracked users regardless of SCOs
311  $subtype = ilObjSAHSLearningModule::_lookupSubType($a_obj_id);
312  if ($subtype != "scorm2004") {
313  $all_tracked_users = ilObjSCORMTracking::_getTrackedUsers(
314  $a_obj_id
315  );
316  } else {
317  $all_tracked_users = ilSCORM2004Tracking::_getTrackedUsers(
318  $a_obj_id
319  );
320  }
321 
322  $not_attempted_users = array_diff(
323  $all_tracked_users,
324  $all_active_users
325  );
326  unset($all_tracked_users);
327  unset($all_active_users);
328 
329  // reset all users which have no data for the current SCOs
330  if ($not_attempted_users) {
331  foreach ($not_attempted_users as $usr_id) {
332  // this will update any (parent) collections if necessary
334  $a_obj_id,
335  $usr_id,
336  self::LP_STATUS_NOT_ATTEMPTED_NUM
337  );
338  }
339  }
340  }
341 }
static _getInProgress(int $a_obj_id)
static _getCompleted(int $a_obj_id)
Static function to read the users who have the status &#39;completed&#39;.
static _getCountCompletedPerUser(array $a_scorm_item_ids, int $a_obj_id, bool $a_omit_failed=false)
Get progress of selected scos.
static _getCollectionStatus(?array $a_scos, int $a_obj_id, int $a_user_id)
determineStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
static _getItemProgressInfo(array $a_scorm_item_ids, int $a_obj_id, bool $a_omit_failed)
static _getStatusInfo(int $a_obj_id)
Reads informations about the object e.g test results, tlt, number of visits.
static _getTrackedUsers(int $a_obj_id)
Get all tracked users.
static hasAccessed(int $a_obj_id, int $a_usr_id)
Has accessed.
static _getProgressInfo(array $sco_item_ids, int $a_obj_id)
Get info about.
static _getInProgress(int $a_obj_id)
Static function to read users who have the status &#39;in_progress&#39;.
static _lookupSubType(int $a_obj_id)
lookup subtype id (scorm, )
static _getCollectionStatus(array $a_scos, int $a_obj_id, int $a_user_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
refreshStatus(int $a_obj_id, ?array $a_users=null)
static _getCompleted(int $a_obj_id)
static _getFailed(int $a_obj_id)
static _getNotAttempted(int $a_obj_id)
static _lookupTitle(int $a_obj_id)
static _getFailed(int $a_obj_id)
Static function to read the users who have the status &#39;completed&#39;.
static _getStatusInfo(int $a_obj_id)
global $DIC
Definition: shib_login.php:22
static _getTrackedUsers(int $a_obj_id)
Get all tracked users.
static _countCompleted(?array $a_scos, int $a_obj_id, int $a_user_id)
static _getCountCompletedPerUser(array $a_scorm_item_ids, int $a_obj_id)
Get users who have status completed or passed.
determinePercentage(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
static writeStatus(int $a_obj_id, int $a_user_id, int $a_status, int $a_percentage=0, bool $a_force_per=false, ?int &$a_old_status=self::LP_STATUS_NOT_ATTEMPTED_NUM)
Write status for user and object.
static _countCompleted(array $a_scos, int $a_obj_id, int $a_user_id, bool $a_omit_failed)
static getInstance(int $obj_id)