19 declare(strict_types=1);
31 $obj_id = $DIC->http()->wrapper()->query()->retrieve(
'package_id', $DIC->refinery()->kindlyTo()->int());
32 $refId = $DIC->http()->wrapper()->query()->retrieve(
'ref_id', $DIC->refinery()->kindlyTo()->int());
33 $in = file_get_contents(
"php://input");
34 $data = json_decode($in);
37 header(
'Content-Type: text/plain; charset=UTF-8');
41 print(
"storeJsApiCmi failed");
45 print(
"syncGlobalStatus failed");
57 $ilDB = $DIC->database();
59 $b_updateStatus =
false;
69 foreach ($data->cmi as $value) {
70 $aa_data[] = array(
"sco_id" => (
int) $value[0],
78 $ilLog->write(
"ScormAicc: storeJsApi: Error: No valid obj_id given.");
80 foreach ($aa_data as $a_data) {
83 SELECT rvalue FROM scorm_tracking 88 array(
'integer',
'integer',
'text',
'integer'),
89 array($user_id, $a_data[
"sco_id"], $a_data[
"left"], $obj_id)
91 if ($rec =
$ilDB->fetchAssoc($set)) {
92 if ($a_data[
"left"] ===
'cmi.core.lesson_status' && $a_data[
"right"] != $rec[
"rvalue"]) {
93 $b_updateStatus =
true;
98 'rvalue' => array(
'clob', $a_data[
"right"]),
102 'user_id' => array(
'integer', $user_id),
103 'sco_id' => array(
'integer', $a_data[
"sco_id"]),
104 'lvalue' => array(
'text', $a_data[
"left"]),
105 'obj_id' => array(
'integer', $obj_id)
108 $ilLog->debug(
"ScormAicc: storeJsApi Updated - L:" . $a_data[
"left"] .
",R:" .
109 $a_data[
"right"] .
" for obj_id:" . $obj_id .
",sco_id:" . $a_data[
"sco_id"] .
",user_id:" . $user_id);
111 if ($a_data[
"left"] ===
'cmi.core.lesson_status') {
112 $b_updateStatus =
true;
114 $ilDB->insert(
'scorm_tracking', array(
115 'obj_id' => array(
'integer', $obj_id),
116 'user_id' => array(
'integer', $user_id),
117 'sco_id' => array(
'integer', $a_data[
"sco_id"]),
118 'lvalue' => array(
'text', $a_data[
"left"]),
119 'rvalue' => array(
'clob', $a_data[
"right"]),
122 $ilLog->debug(
"ScormAicc: storeJsApi Inserted - L:" . $a_data[
"left"] .
",R:" .
123 $a_data[
"right"] .
" for obj_id:" . $obj_id .
",sco_id:" . $a_data[
"sco_id"] .
",user_id:" . $user_id);
125 if ($a_data[
"left"] ===
'cmi.core.score.max') {
126 $i_score_max = $a_data[
"right"];
128 if ($a_data[
"left"] ===
'cmi.core.score.raw') {
129 $i_score_raw = $a_data[
"right"];
133 if ($i_score_max > 0 && $i_score_raw > 0) {
138 ($i_score_raw / $i_score_max) * 100
156 $ilDB = $DIC->database();
158 $saved_global_status = $data->saved_global_status;
159 $ilLog->write(
"saved_global_status=" . $saved_global_status);
162 if (!isset($data->packageAttempts)) {
163 $val_set =
$ilDB->queryF(
164 'SELECT package_attempts FROM sahs_user WHERE obj_id = %s AND user_id = %s',
165 array(
'integer',
'integer'),
166 array($packageId, $userId)
168 $val_rec =
$ilDB->fetchAssoc($val_set);
169 $attempts = $val_rec[
"package_attempts"];
171 $attempts = $data->packageAttempts;
173 if ($attempts ==
null) {
178 $totalTime = (
int) $data->totalTimeCentisec;
179 $totalTime = round($totalTime / 100);
181 'UPDATE sahs_user SET last_visited=%s, last_access = %s, sco_total_time_sec=%s, status=%s, percentage_completed=%s, package_attempts=%s WHERE obj_id = %s AND user_id = %s',
182 array(
'text',
'timestamp',
'integer',
'integer',
'integer',
'integer',
'integer',
'integer'),
183 array($data->last_visited,
187 $data->percentageCompleted,
196 $ilObjDataCache = $DIC[
'ilObjDataCache'];
223 if ($new_global_status !=
null) {
231 public static function _insertTrackData(
int $a_sahs_id,
string $a_lval,
string $a_rval,
int $a_obj_id): void
234 $ilDB = $DIC->database();
235 $ilUser = $DIC->user();
237 $ilDB->insert(
'scorm_tracking', array(
238 'obj_id' => array(
'integer', $a_obj_id),
239 'user_id' => array(
'integer', $ilUser->getId()),
240 'sco_id' => array(
'integer', $a_sahs_id),
241 'lvalue' => array(
'text', $a_lval),
242 'rvalue' => array(
'clob', $a_rval),
246 if ($a_lval ===
"cmi.core.lesson_status") {
255 public static function _getCompleted(
object $scorm_item_id,
int $a_obj_id): array
258 $ilDB = $DIC->database();
262 if (is_array($scorm_item_id)) {
263 $in =
$ilDB->in(
'sco_id', $scorm_item_id,
false,
'integer');
266 'SELECT DISTINCT(user_id) FROM scorm_tracking 270 AND (' .
$ilDB->like(
'rvalue',
'clob',
'completed') .
' OR ' .
$ilDB->like(
275 array(
'integer',
'text'),
276 array($a_obj_id,
'cmi.core.lesson_status')
280 'SELECT DISTINCT(user_id) FROM scorm_tracking 284 AND (' .
$ilDB->like(
'rvalue',
'clob',
'completed') .
' OR ' .
$ilDB->like(
289 array(
'integer',
'integer',
'text'),
290 array($scorm_item_id, $a_obj_id,
'cmi.core.lesson_status')
294 while ($row =
$ilDB->fetchObject(
$res)) {
295 $user_ids[] = $row->user_id;
303 $ilDB = $DIC->database();
305 $status =
"not_attempted";
307 if (is_array($a_scos)) {
308 $in =
$ilDB->in(
'sco_id', $a_scos,
false,
'integer');
311 'SELECT sco_id, rvalue FROM scorm_tracking 316 array(
'integer',
'text',
'integer'),
317 array($a_obj_id,
'cmi.core.lesson_status', $a_user_id)
324 if ($rec[
"rvalue"] ===
"failed") {
327 if ($rec[
"rvalue"] !==
"completed" && $rec[
"rvalue"] !==
"passed") {
333 $status =
"in_progress";
335 if ($completed && $cnt == count($a_scos)) {
336 $status =
"completed";
348 $ilDB = $DIC->database();
351 if (is_array($a_scos)) {
352 $in =
$ilDB->in(
'sco_id', $a_scos,
false,
'integer');
355 'SELECT sco_id, rvalue FROM scorm_tracking 360 array(
'integer',
'text',
'integer'),
361 array($a_obj_id,
'cmi.core.lesson_status', $a_user_id)
365 if ($rec[
"rvalue"] ===
"completed" || $rec[
"rvalue"] ===
"passed") {
380 $ilDB = $DIC->database();
383 $query =
'SELECT user_id, MAX(c_timestamp) tst ' .
384 'FROM scorm_tracking ' .
385 'WHERE obj_id = ' .
$ilDB->quote($a_obj_id,
'integer') .
' ' .
390 $users[$row->user_id] = $row->tst;
401 $ilDB = $DIC->database();
405 'SELECT DISTINCT user_id FROM scorm_tracking 408 array(
'integer',
'text'),
409 array($a_obj_id,
'cmi.core.lesson_status')
414 $users[] = $row[
"user_id"];
422 public static function _getFailed(
object $scorm_item_id,
int $a_obj_id): array
425 $ilDB = $DIC->database();
428 if (is_array($scorm_item_id)) {
429 $in =
$ilDB->in(
'sco_id', $scorm_item_id,
false,
'integer');
433 SELECT DISTINCT(user_id) FROM scorm_tracking 437 AND ' .
$ilDB->like(
'rvalue',
'clob',
'failed') .
' ',
438 array(
'integer',
'text'),
439 array($a_obj_id,
'cmi.core.lesson_status')
444 SELECT DISTINCT(user_id) FROM scorm_tracking 448 AND ' .
$ilDB->like(
'rvalue',
'clob',
'failed') .
' ',
449 array(
'integer',
'integer',
'text'),
450 array($scorm_item_id, $a_obj_id,
'cmi.core.lesson_status')
454 while ($row =
$ilDB->fetchObject(
$res)) {
455 $user_ids[] = $row->user_id;
467 $ilDB = $DIC->database();
470 $in =
$ilDB->in(
'sco_id', $a_scorm_item_ids,
false,
'integer');
476 SELECT user_id, COUNT(user_id) completed FROM scorm_tracking 480 AND (' .
$ilDB->like(
'rvalue',
'clob',
'completed') .
' OR ' .
$ilDB->like(
'rvalue',
'clob',
'passed') .
') 482 array(
'integer',
'text'),
483 array($a_obj_id,
'cmi.core.lesson_status')
485 while ($row =
$ilDB->fetchObject(
$res)) {
486 $users[$row->user_id] = $row->completed;
498 $ilDB = $DIC->database();
500 $in =
$ilDB->in(
'sco_id', $sco_item_ids,
false,
'integer');
504 SELECT * FROM scorm_tracking 508 array(
'integer',
'text'),
509 array($a_obj_id,
'cmi.core.lesson_status')
512 $info[
'completed'] = array();
513 $info[
'failed'] = array();
516 while ($row =
$ilDB->fetchObject(
$res)) {
517 switch ($row->rvalue) {
520 $info[
'completed'][$row->sco_id][] = $row->user_id;
521 $user_ids[$row->sco_id][] = $row->user_id;
525 $info[
'failed'][$row->sco_id][] = $row->user_id;
526 $user_ids[$row->sco_id][] = $row->user_id;
538 public static function _getInProgress(array|
int $scorm_item_id,
int $a_obj_id, ?array $a_blocked_user_ids =
null): array
541 $ilDB = $DIC->database();
543 if (is_array($scorm_item_id)) {
544 $in =
$ilDB->in(
'sco_id', $scorm_item_id,
false,
'integer');
547 'SELECT user_id,sco_id FROM scorm_tracking 550 GROUP BY user_id, sco_id',
556 'SELECT user_id,sco_id FROM scorm_tracking 559 array(
'integer',
'integer'),
560 array($scorm_item_id, $a_obj_id)
564 $in_progress = array();
566 while ($row =
$ilDB->fetchObject(
$res)) {
568 if (!($a_blocked_user_ids &&
569 isset($a_blocked_user_ids[$row->sco_id]) &&
570 is_array($a_blocked_user_ids[$row->sco_id]) &&
571 in_array($row->user_id, $a_blocked_user_ids[$row->sco_id]))) {
572 $in_progress[$row->sco_id][] = $row->user_id;
581 $ilDB = $DIC->database();
582 $user_id = $DIC->http()->wrapper()->query()->retrieve(
'p', $DIC->refinery()->kindlyTo()->int());
583 $ref_id = $DIC->http()->wrapper()->query()->retrieve(
'ref_id', $DIC->refinery()->kindlyTo()->int());
584 $obj_id = $DIC->http()->wrapper()->query()->retrieve(
'package_id', $DIC->refinery()->kindlyTo()->int());
586 $GLOBALS[
'DIC'][
'ilLog']->write(__METHOD__ .
' no valid obj_id');
589 if ($DIC->http()->wrapper()->query()->has(
'last_visited')) {
590 $last_visited = $DIC->http()->wrapper()->query()->retrieve(
'last_visited', $DIC->refinery()->kindlyTo()->string());
595 mktime((
int) date(
'H'), (
int) date(
'i') + 5, (
int) date(
's'), (
int) date(
'm'), (
int) date(
'd'), (
int) date(
'Y'))
599 SET last_visited = %s, hash_end =%s, last_access = %s 600 WHERE obj_id = %s AND user_id = %s',
601 array(
'text',
'timestamp',
'timestamp',
'integer',
'integer'),
602 array($last_visited, $endDate, date(
'Y-m-d H:i:s'), $obj_id,
$user_id)
608 header(
'Content-Type: text/plain; charset=UTF-8');
615 $ilDB = $DIC->database();
617 'select hash from sahs_user where obj_id=%s AND user_id=%s AND hash_end>%s',
618 array(
'integer',
'integer',
'timestamp'),
619 array($packageId, $userId, date(
'Y-m-d H:i:s'))
622 if (! ($rowtmp && $rowtmp[
'hash'] == $hash)) {
628 public static function _syncReadEvent(
int $a_obj_id,
int $a_user_id,
string $a_type,
int $a_ref_id): void
631 $ilDB = $DIC->database();
633 $val_set =
$ilDB->queryF(
634 'SELECT package_attempts, total_time_sec, sco_total_time_sec, time_from_lms FROM sahs_user, sahs_lm ' 635 .
'WHERE sahs_user.obj_id = %s AND sahs_user.user_id = %s AND sahs_user.obj_id = sahs_lm.id',
636 array(
'integer',
'integer'),
637 array($a_obj_id, $a_user_id)
640 $val_rec =
$ilDB->fetchAssoc($val_set);
642 if ($val_rec[
"package_attempts"] ==
null) {
643 $val_rec[
"package_attempts"] =
"";
645 $attempts = $val_rec[
"package_attempts"];
647 $time = (
int) $val_rec[
"sco_total_time_sec"];
651 $sco_set =
$ilDB->queryF(
653 SELECT sco_id, rvalue FROM scorm_tracking 658 array(
'integer',
'integer',
'text',
'integer'),
659 array($a_obj_id, $a_user_id,
'cmi.core.total_time', 0)
662 while ($sco_rec =
$ilDB->fetchAssoc($sco_set)) {
663 $tarr = explode(
":", $sco_rec[
"rvalue"]);
664 $sec = (
int) $tarr[2] + (
int) $tarr[1] * 60 +
665 (
int) substr($tarr[0], strlen($tarr[0]) - 3) * 60 * 60;
static _getInProgress(array|int $scorm_item_id, int $a_obj_id, ?array $a_blocked_user_ids=null)
static storeJsApiCmi(int $user_id, int $obj_id, object $data)
static getLogger(string $a_component_id)
Get component logger.
static _lookupPresentableItems(int $a_slm_id)
Count number of presentable SCOs/Assets of SCORM learning module.
static _getCollectionStatus(?array $a_scos, int $a_obj_id, int $a_user_id)
static _getFailed(object $scorm_item_id, int $a_obj_id)
like necessary because of Oracle
Class ilObjSCORMTracking.
static _getProgressInfo(array $sco_item_ids, int $a_obj_id)
Get info about.
static lookupLastAccessTimes(int $a_obj_id)
Lookup last acccess time for all users of a scorm module.
static now()
Return current timestamp in Y-m-d H:i:s format.
static _insertTrackData(int $a_sahs_id, string $a_lval, string $a_rval, int $a_obj_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static _recordReadEvent(string $a_type, int $a_ref_id, int $obj_id, int $usr_id, bool $isCatchupWriteEvents=true, $a_ext_rc=null, $a_ext_time=null)
static _getTrackedUsers(int $a_obj_id)
Get all tracked users.
static syncGlobalStatus(int $userId, int $packageId, int $refId, object $data, ?int $new_global_status)
static handleOutcomeWithoutLP(int $a_obj_id, int $a_usr_id, ?float $a_percentage)
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.
static checkIfAllowed(int $packageId, int $userId, int $hash)
static scorm12PlayerUnload()
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 _getCompleted(object $scorm_item_id, int $a_obj_id)
like necessary because of Oracle
static _syncReadEvent(int $a_obj_id, int $a_user_id, string $a_type, int $a_ref_id)
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)