ILIAS  release_8 Revision v8.24
class.ilLPStatusSCORM.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=0);
4
5/* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
6
12{
13 public static function _getInProgress(int $a_obj_id): array
14 {
15 $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
16 $users = array();
17 foreach ($status_info['in_progress'] as $in_progress) {
18 $users = array_merge($users, $in_progress);
19 }
20 $users = array_unique($users);
21 $users = array_diff(
22 $users,
24 );
25 $users = array_diff($users, ilLPStatusWrapper::_getFailed($a_obj_id));
26
27 return $users;
28 }
29
30 public static function _getCompleted(int $a_obj_id): array
31 {
32 global $DIC;
33
34 $ilDB = $DIC['ilDB'];
35
36 $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
37 $items = $status_info['scos'];
38 $counter = 0;
39 $users = array();
40 foreach ($items as $sco_id) {
41 $tmp_users = $status_info['completed'][$sco_id];
42
43 if (!$counter++) {
44 $users = $tmp_users;
45 } else {
46 $users = array_intersect($users, $tmp_users);
47 }
48 }
49
50 $users = array_diff($users, ilLPStatusWrapper::_getFailed($a_obj_id));
51 return $users;
52 }
53
54 public static function _getFailed(int $a_obj_id): array
55 {
56 $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
57
58 if (!count($status_info['scos'])) {
59 return array();
60 }
61 $users = array();
62 foreach ($status_info['scos'] as $sco_id) {
63 $users = array_merge(
64 $users,
65 (array) $status_info['failed'][$sco_id]
66 );
67 }
68 return array_unique($users);
69 }
70
71 public static function _getNotAttempted(int $a_obj_id): array
72 {
73 $users = array();
74
75 $members = ilObjectLP::getInstance($a_obj_id)->getMembers();
76 if ($members) {
77 // diff in progress and completed (use stored result in LPStatusWrapper)
78 $users = array_diff(
79 (array) $members,
81 );
82 $users = array_diff(
83 $users,
85 );
86 $users = array_diff(
87 $users,
89 );
90 }
91
92 return $users;
93 }
94
95 public static function _getStatusInfo(int $a_obj_id): array
96 {
97 // Which sco's determine the status
98 $olp = ilObjectLP::getInstance($a_obj_id);
99 $collection = $olp->getCollectionInstance();
100 if ($collection) {
101 $status_info['scos'] = $collection->getItems();
102 } else {
103 $status_info['scos'] = array();
104 }
105 $status_info['num_scos'] = count($status_info['scos']);
106
107 // Get subtype
108 $status_info['subtype'] = ilObjSAHSLearningModule::_lookupSubType(
109 $a_obj_id
110 );
111 $info = [];
112 switch ($status_info['subtype']) {
113 case 'hacp':
114 case 'aicc':
115 $status_info['num_completed'] = ilObjSCORMTracking::_getCountCompletedPerUser(
116 $status_info['scos'],
117 $a_obj_id
118 );
119
120 foreach (ilObjAICCLearningModule::_getTrackingItems(
121 $a_obj_id
122 ) as $item) {
123 if (in_array($item['obj_id'], $status_info['scos'])) {
124 $status_info['scos_title']["$item[obj_id]"] = $item['title'];
125 }
126 }
128 $status_info['scos'],
129 $a_obj_id
130 );
131 break;
132
133 case 'scorm':
134 $status_info['num_completed'] = ilObjSCORMTracking::_getCountCompletedPerUser(
135 $status_info['scos'],
136 $a_obj_id
137 );
138
139 foreach ($status_info['scos'] as $sco_id) {
140 $status_info['scos_title'][$sco_id] = ilSCORMItem::_lookupTitle(
141 $sco_id
142 );
143 }
145 $status_info['scos'],
146 $a_obj_id
147 );
148 break;
149
150 case "scorm2004":
151 $status_info['num_completed'] = ilSCORM2004Tracking::_getCountCompletedPerUser(
152 $status_info['scos'],
153 $a_obj_id,
154 true
155 );
156 foreach ($status_info['scos'] as $sco_id) {
157 $status_info['scos_title'][$sco_id] = ilObjSCORM2004LearningModule::_lookupItemTitle(
158 $sco_id
159 );
160 }
161
163 $status_info['scos'],
164 $a_obj_id,
165 true
166 );
167 break;
168 }
169
170 $status_info['completed'] = array();
171 $status_info['failed'] = array();
172 $status_info['in_progress'] = array();
173 foreach ($status_info['scos'] as $sco_id) {
174 $status_info['completed'][$sco_id] = $info['completed'][$sco_id] ?? array();
175 $status_info['failed'][$sco_id] = $info['failed'][$sco_id] ?? array();
176 $status_info['in_progress'][$sco_id] = $info['in_progress'][$sco_id] ?? array();
177 }
178 //var_dump($status_info["completed"]);
179 return $status_info;
180 }
181
182 public function determineStatus(
183 int $a_obj_id,
184 int $a_usr_id,
185 object $a_obj = null
186 ): int {
187 global $DIC;
188
190
191 // if the user has accessed the scorm object
192 // the status is at least "in progress"
193 if (ilChangeEvent::hasAccessed($a_obj_id, $a_usr_id)) {
195 }
196 // Which sco's determine the status
197 $olp = ilObjectLP::getInstance($a_obj_id);
198 $collection = $olp->getCollectionInstance();
199 if ($collection) {
200 $scos = $collection->getItems();
201 if (sizeof(
202 $scos
203 )) { // #15462 (#11513 - empty collections cannot be completed)
204 $subtype = ilObjSAHSLearningModule::_lookupSubType($a_obj_id);
205 $scorm_status = '';
206 switch ($subtype) {
207 case 'hacp':
208 case 'aicc':
209 case 'scorm':
211 $scos,
212 $a_obj_id,
213 $a_usr_id
214 );
215 break;
216
217 case 'scorm2004':
219 $scos,
220 $a_obj_id,
221 $a_usr_id
222 );
223 break;
224 }
225
226 switch ($scorm_status) {
227 case "in_progress":
229 break;
230 case "completed":
232 break;
233 case "failed":
235 break;
236 }
237 }
238 }
239
240 //$ilLog->write("-".$status."-");
241 return $status;
242 }
243
244 public function determinePercentage(
245 int $a_obj_id,
246 int $a_usr_id,
247 ?object $a_obj = null
248 ): int {
249 // Which sco's determine the status
250 $olp = ilObjectLP::getInstance($a_obj_id);
251 $collection = $olp->getCollectionInstance();
252 $reqscos = 0;
253 $compl = 0;
254 if ($collection) {
255 $scos = $collection->getItems();
256 $reqscos = count($scos);
257
258 $subtype = ilObjSAHSLearningModule::_lookupSubType($a_obj_id);
259 if ($subtype != "scorm2004") {
261 $scos,
262 $a_obj_id,
263 $a_usr_id
264 );
265 } else {
267 $scos,
268 $a_obj_id,
269 $a_usr_id,
270 true
271 );
272 }
273 }
274
275 if ($reqscos > 0) {
276 $per = min(100, 100 / $reqscos * $compl);
277 } else {
278 $per = 100;
279 }
280
281 return $per;
282 }
283
284 public function refreshStatus(int $a_obj_id, ?array $a_users = null): void
285 {
286 parent::refreshStatus($a_obj_id, $a_users);
287
288 // this is restricted to SCOs in the current collection
289 $in_progress = ilLPStatusWrapper::_getInProgress($a_obj_id);
290 $completed = ilLPStatusWrapper::_getCompleted($a_obj_id);
291 $failed = ilLPStatusWrapper::_getFailed($a_obj_id);
292 $all_active_users = array_unique(
293 array_merge($in_progress, $completed, $failed)
294 );
295
296 // get all tracked users regardless of SCOs
297 $subtype = ilObjSAHSLearningModule::_lookupSubType($a_obj_id);
298 if ($subtype != "scorm2004") {
299 $all_tracked_users = ilObjSCORMTracking::_getTrackedUsers(
300 $a_obj_id
301 );
302 } else {
303 $all_tracked_users = ilSCORM2004Tracking::_getTrackedUsers(
304 $a_obj_id
305 );
306 }
307
308 $not_attempted_users = array_diff(
309 $all_tracked_users,
310 $all_active_users
311 );
312 unset($all_tracked_users);
313 unset($all_active_users);
314
315 // reset all users which have no data for the current SCOs
316 if ($not_attempted_users) {
317 foreach ($not_attempted_users as $usr_id) {
318 // this will update any (parent) collections if necessary
320 $a_obj_id,
321 $usr_id,
322 self::LP_STATUS_NOT_ATTEMPTED_NUM
323 );
324 }
325 }
326 }
327}
static hasAccessed(int $a_obj_id, int $a_usr_id)
Has accessed.
determineStatus(int $a_obj_id, int $a_usr_id, object $a_obj=null)
static _getCompleted(int $a_obj_id)
static _getStatusInfo(int $a_obj_id)
static _getInProgress(int $a_obj_id)
refreshStatus(int $a_obj_id, ?array $a_users=null)
Refresh status.
static _getFailed(int $a_obj_id)
static _getNotAttempted(int $a_obj_id)
determinePercentage(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
static _getInProgress(int $a_obj_id)
Static function to read users who have the status 'in_progress'.
static _getFailed(int $a_obj_id)
Static function to read the users who have the status 'completed'.
static _getCompleted(int $a_obj_id)
Static function to read the users who have the status 'completed'.
static _getStatusInfo(int $a_obj_id)
Reads informations about the object e.g test results, tlt, number of visits.
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
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.
const LP_STATUS_COMPLETED_NUM
const LP_STATUS_IN_PROGRESS_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
const LP_STATUS_FAILED_NUM
static _lookupSubType(int $a_obj_id)
lookup subtype id (scorm, )
static _getProgressInfo(array $sco_item_ids, int $a_obj_id)
Get info about.
static _getCountCompletedPerUser(array $a_scorm_item_ids, int $a_obj_id)
Get users who have status completed or passed.
static _getTrackedUsers(int $a_obj_id)
Get all tracked users.
static _getCollectionStatus(?array $a_scos, int $a_obj_id, int $a_user_id)
static _countCompleted(?array $a_scos, int $a_obj_id, int $a_user_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance(int $obj_id)
static _getCollectionStatus(array $a_scos, int $a_obj_id, int $a_user_id)
static _getTrackedUsers(int $a_obj_id)
Get all tracked users.
static _getCountCompletedPerUser(array $a_scorm_item_ids, int $a_obj_id, bool $a_omit_failed=false)
Get progress of selected scos.
static _countCompleted(array $a_scos, int $a_obj_id, int $a_user_id, bool $a_omit_failed)
static _getItemProgressInfo(array $a_scorm_item_ids, int $a_obj_id, bool $a_omit_failed)
static _lookupTitle(int $a_obj_id)
global $DIC
Definition: feed.php:28