26 $this->insert = array();
27 if (is_array(
$_GET[
"iL"]))
29 foreach(
$_GET[
"iL"] as $key => $value)
31 $this->insert[] = array(
"left" => $value,
"right" =>
$_GET[
"iR"][$key]);
34 if (is_array(
$_POST[
"iL"]))
36 foreach(
$_POST[
"iL"] as $key => $value)
38 $this->insert[] = array(
"left" => $value,
"right" =>
$_POST[
"iR"][$key]);
42 $this->update = array();
43 if (is_array(
$_GET[
"uL"]))
45 foreach(
$_GET[
"uL"] as $key => $value)
47 $this->update[] = array(
"left" => $value,
"right" =>
$_GET[
"uR"][$key]);
50 if (is_array(
$_POST[
"uL"]))
52 foreach(
$_POST[
"uL"] as $key => $value)
54 $this->update[] = array(
"left" => $value,
"right" =>
$_POST[
"uR"][$key]);
59 function store($obj_id=0, $sahs_id=0, $extractData=1)
70 $f = fopen(
"./Modules/ScormAicc/log/scorm.log",
"a");
71 fwrite($f,
"\nCALLING SCORM store()\n");
72 fwrite($f,
'POST: '.print_r(
$_POST,
true));
81 if (is_object($ilUser))
83 $user_id = $ilUser->getId();
90 fwrite($f,
"Error: No obj_id given.\n");
94 foreach($this->insert as $insert)
96 $set = $ilDB->queryF(
'
97 SELECT * FROM scorm_tracking
102 array(
'integer',
'integer',
'text',
'integer'),
103 array($user_id,$sahs_id,$insert[
"left"],$obj_id));
104 if ($rec = $ilDB->fetchAssoc($set))
106 fwrite($f,
"Error Insert, left value already exists. L:".$insert[
"left"].
",R:".
107 $insert[
"right"].
",sahs_id:".$sahs_id.
",user_id:".$user_id.
"\n");
111 $ilDB->insert(
'scorm_tracking', array(
112 'obj_id' => array(
'integer', $obj_id),
113 'user_id' => array(
'integer', $user_id),
114 'sco_id' => array(
'integer', $sahs_id),
115 'lvalue' => array(
'text', $insert[
"left"]),
116 'rvalue' => array(
'clob', $insert[
"right"]),
120 fwrite($f,
"Insert - L:".$insert[
"left"].
",R:".
121 $insert[
"right"].
",sahs_id:".$sahs_id.
",user_id:".$user_id.
"\n");
124 foreach($this->update as $update)
126 $set = $ilDB->queryF(
'
127 SELECT * FROM scorm_tracking
132 array(
'integer',
'integer',
'text',
'integer'),
133 array($user_id,$sahs_id,$update[
"left"],$obj_id));
135 if ($rec = $ilDB->fetchAssoc($set))
137 $ilDB->update(
'scorm_tracking',
139 'rvalue' => array(
'clob', $update[
"right"]),
143 'user_id' => array(
'integer', $user_id),
144 'sco_id' => array(
'integer', $sahs_id),
145 'lvalue' => array(
'text', $update[
"left"]),
146 'obj_id' => array(
'integer', $obj_id)
152 fwrite($f,
"ERROR Update, left value does not exist. L:".$update[
"left"].
",R:".
153 $update[
"right"].
",sahs_id:".$sahs_id.
",user_id:".$user_id.
"\n");
161 include_once(
"./Services/Tracking/classes/class.ilLPStatusWrapper.php");
172 $b_updateStatus=
false;
175 if ($ilLog->current_log_level == 30)
184 $ilLog->write(
"ScormAicc: CALLING SCORM storeJsApi() ".
$_POST);
186 if (is_object($ilUser))
187 $user_id = $ilUser->getId();
190 if (is_array(
$_POST[
"S"])) {
191 foreach(
$_POST[
"S"] as $key => $value) {
192 $aa_data[] = array(
"sco_id" => $value,
"left" =>
$_POST[
"L"][$key],
"right" =>
$_POST[
"R"][$key]);
197 $ilLog->write(
"ScormAicc: storeJsApi: Error: No valid obj_id given.");
200 foreach($aa_data as $a_data) {
201 $set = $ilDB->queryF(
'
202 SELECT rvalue FROM scorm_tracking
207 array(
'integer',
'integer',
'text',
'integer'),
208 array($user_id,$a_data[
"sco_id"],$a_data[
"left"],$obj_id));
209 if ($rec = $ilDB->fetchAssoc($set)) {
210 if ($a_data[
"left"] ==
'cmi.core.lesson_status' && $a_data[
"right"] != $rec[
"rvalue"]) {
211 $b_updateStatus =
true;
213 $ilDB->update(
'scorm_tracking',
215 'rvalue' => array(
'clob', $a_data[
"right"]),
219 'user_id' => array(
'integer', $user_id),
220 'sco_id' => array(
'integer', $a_data[
"sco_id"]),
221 'lvalue' => array(
'text', $a_data[
"left"]),
222 'obj_id' => array(
'integer', $obj_id)
226 $ilLog->write(
"ScormAicc: storeJsApi Updated - L:".$a_data[
"left"].
",R:".
227 $a_data[
"right"].
" for obj_id:".$obj_id.
",sco_id:".$a_data[
"sco_id"].
",user_id:".$user_id);
231 if ($a_data[
"left"] ==
'cmi.core.lesson_status') {
232 $b_updateStatus =
true;
234 $ilDB->insert(
'scorm_tracking', array(
235 'obj_id' => array(
'integer', $obj_id),
236 'user_id' => array(
'integer', $user_id),
237 'sco_id' => array(
'integer', $a_data[
"sco_id"]),
238 'lvalue' => array(
'text', $a_data[
"left"]),
239 'rvalue' => array(
'clob', $a_data[
"right"]),
243 $ilLog->write(
"ScormAicc: storeJsApi Inserted - L:".$a_data[
"left"].
",R:".
244 $a_data[
"right"].
" for obj_id:".$obj_id.
",sco_id:".$$a_data[
"sco_id"].
",user_id:".$user_id);
251 if ($b_updateStatus ==
true) {
252 include_once(
"./Services/Tracking/classes/class.ilLPStatusWrapper.php");
256 header(
'Content-Type: text/plain; charset=UTF-8');
271 $val_set = $ilDB->queryF(
'
272 SELECT rvalue FROM scorm_tracking
277 array(
'integer',
'integer',
'text',
'integer'),
278 array($a_user_id,0,
'package_attempts',$a_obj_id));
280 $val_rec = $ilDB->fetchAssoc($val_set);
282 $val_rec[
"rvalue"] = str_replace(
"\r\n",
"\n", $val_rec[
"rvalue"]);
283 if ($val_rec[
"rvalue"] == null) {
284 $val_rec[
"rvalue"]=
"";
286 $attempts = $val_rec[
"rvalue"];
289 $sco_set = $ilDB->queryF(
'
290 SELECT sco_id, rvalue FROM scorm_tracking
295 array(
'integer',
'integer',
'text',
'integer'),
296 array($a_obj_id,$a_user_id,
'cmi.core.total_time',0));
299 while($sco_rec = $ilDB->fetchAssoc($sco_set))
301 $tarr = explode(
":", $sco_rec[
"rvalue"]);
302 $sec = (int) $tarr[2] + (
int) $tarr[1] * 60 +
303 (int) substr($tarr[0], strlen($tarr[0]) - 3) * 60 * 60;
307 include_once(
"./Services/Tracking/classes/class.ilChangeEvent.php");
315 $ilDB->insert(
'scorm_tracking', array(
316 'obj_id' => array(
'integer', $a_obj_id),
317 'user_id' => array(
'integer', $ilUser->getId()),
318 'sco_id' => array(
'integer', $a_sahs_id),
319 'lvalue' => array(
'text', $a_lval),
320 'rvalue' => array(
'clob', $a_rval),
324 if ($a_lval ==
"cmi.core.lesson_status")
326 include_once(
"./Services/Tracking/classes/class.ilLPStatusWrapper.php");
338 public static function _getInProgress($scorm_item_id,$a_obj_id,$a_blocked_user_ids = null)
342 if(is_array($scorm_item_id))
344 $in = $ilDB->in(
'sco_id', $scorm_item_id,
false,
'integer');
346 $res = $ilDB->queryF(
'SELECT user_id,sco_id FROM scorm_tracking
349 GROUP BY user_id, sco_id',
350 array(
'integer'),array($a_obj_id));
355 $res = $ilDB->queryF(
'SELECT user_id,sco_id FROM scorm_tracking
358 array(
'integer',
'integer'),array($scorm_item_id,$a_obj_id)
362 while(
$row = $ilDB->fetchObject(
$res))
365 if(!($a_blocked_user_ids && in_array(
$row->user_id, $a_blocked_user_ids)))
367 $in_progress[
$row->sco_id][] =
$row->user_id;
370 return is_array($in_progress) ? $in_progress : array();
383 if(is_array($scorm_item_id))
385 $in = $ilDB->in(
'sco_id', $scorm_item_id,
false,
'integer');
387 $res = $ilDB->queryF(
'SELECT DISTINCT(user_id) FROM scorm_tracking
391 AND ('.$ilDB->like(
'rvalue',
'clob',
'completed').
' OR '.$ilDB->like(
'rvalue',
'clob',
'passed').
')',
392 array(
'integer',
'text'),
393 array($a_obj_id,
'cmi.core.lesson_status'));
397 $res = $ilDB->queryF(
'SELECT DISTINCT(user_id) FROM scorm_tracking
401 AND ('.$ilDB->like(
'rvalue',
'clob',
'completed').
' OR '.$ilDB->like(
'rvalue',
'clob',
'passed').
')',
402 array(
'integer',
'integer',
'text'),
403 array($scorm_item_id,$a_obj_id,
'cmi.core.lesson_status'));
406 while(
$row = $ilDB->fetchObject(
$res))
408 $user_ids[] =
$row->user_id;
410 return $user_ids ? $user_ids : array();
418 $status =
"not_attempted";
420 if (is_array($a_scos))
422 $in = $ilDB->in(
'sco_id', $a_scos,
false,
'integer');
424 $res = $ilDB->queryF(
'SELECT sco_id, rvalue FROM scorm_tracking
429 array(
'integer',
'text',
'integer'),
430 array($a_obj_id,
'cmi.core.lesson_status', $a_user_id));
435 while ($rec = $ilDB->fetchAssoc(
$res))
437 if ($rec[
"rvalue"] ==
"failed")
441 if ($rec[
"rvalue"] !=
"completed" && $rec[
"rvalue"] !=
"passed")
449 $status =
"in_progress";
451 if ($completed && $cnt == count($a_scos))
453 $status =
"completed";
461 if ($status ==
"in_progress" && self::_hasMaxAttempts($a_obj_id, $a_user_id))
474 $val_set = $ilDB->queryF(
'SELECT * FROM sahs_lm WHERE id = %s',
475 array(
'integer'), array($a_obj_id));
476 $val_rec = $ilDB->fetchAssoc($val_set);
477 $max_attempts = $val_rec[
"max_attempt"];
481 $val_set = $ilDB->queryF(
'
482 SELECT * FROM scorm_tracking
487 array(
'integer',
'integer',
'text',
'integer'),
488 array($a_user_id,0,
'package_attempts',$a_obj_id)
490 $val_rec = $ilDB->fetchAssoc($val_set);
492 $val_rec[
"rvalue"] = str_replace(
"\r\n",
"\n", $val_rec[
"rvalue"]);
493 if ($val_rec[
"rvalue"] == null)
495 $val_rec[
"rvalue"] = 0;
497 $act_attempts = $val_rec[
"rvalue"];
499 if ($act_attempts >= $max_attempts)
512 if (is_array($a_scos))
514 $in = $ilDB->in(
'sco_id', $a_scos,
false,
'integer');
516 $res = $ilDB->queryF(
'SELECT sco_id, rvalue FROM scorm_tracking
521 array(
'integer',
'text',
'integer'),
522 array($a_obj_id,
'cmi.core.lesson_status', $a_user_id));
525 while ($rec = $ilDB->fetchAssoc(
$res))
527 if ($rec[
"rvalue"] ==
"completed" || $rec[
"rvalue"] ==
"passed")
546 $query =
'SELECT user_id, MAX(c_timestamp) tst '.
547 'FROM scorm_tracking '.
548 'WHERE obj_id = '.$ilDB->quote($a_obj_id,
'integer').
' '.
570 $res = $ilDB->queryF(
'SELECT DISTINCT user_id FROM scorm_tracking
573 array(
'integer',
'text'),
574 array($a_obj_id,
'cmi.core.lesson_status'));
577 while (
$row = $ilDB->fetchAssoc(
$res))
579 $users[] =
$row[
"user_id"];
594 if(is_array($scorm_item_id))
596 $in = $ilDB->in(
'sco_id', $scorm_item_id,
false,
'integer');
598 $res = $ilDB->queryF(
'
599 SELECT DISTINCT(user_id) FROM scorm_tracking
603 AND '.$ilDB->like(
'rvalue',
'clob',
'failed').
' ',
604 array(
'integer',
'text'),
605 array($a_obj_id,
'cmi.core.lesson_status'));
610 $res = $ilDB->queryF(
'
611 SELECT DISTINCT(user_id) FROM scorm_tracking
615 AND '.$ilDB->like(
'rvalue',
'clob',
'failed').
' ',
616 array(
'integer',
'integer',
'text'),
617 array($scorm_item_id,$a_obj_id,
'cmi.core.lesson_status'));
620 while(
$row = $ilDB->fetchObject(
$res))
622 $user_ids[] =
$row->user_id;
624 return $user_ids ? $user_ids : array();
637 $in = $ilDB->in(
'sco_id', $a_scorm_item_ids,
false,
'integer');
641 $res = $ilDB->queryF(
'
642 SELECT user_id, COUNT(user_id) completed FROM scorm_tracking
646 AND ('.$ilDB->like(
'rvalue',
'clob',
'completed').
' OR '.$ilDB->like(
'rvalue',
'clob',
'passed').
')
648 array(
'integer',
'text'),
649 array($a_obj_id,
'cmi.core.lesson_status')
651 while(
$row = $ilDB->fetchObject(
$res))
653 $users[
$row->user_id] =
$row->completed;
671 return $users ? $users : array();
684 $in = $ilDB->in(
'sco_id', $sco_item_ids,
false,
'integer');
686 $res = $ilDB->queryF(
'
687 SELECT * FROM scorm_tracking
691 array(
'integer',
'text'),
692 array($a_obj_id,
'cmi.core.lesson_status'));
694 $info[
'completed'] = array();
695 $info[
'failed'] = array();
698 while(
$row = $ilDB->fetchObject(
$res))
704 $info[
'completed'][
$row->sco_id][] =
$row->user_id;
705 $user_ids[] =
$row->user_id;
709 $info[
'failed'][
$row->sco_id][] =
$row->user_id;
710 $user_ids[] =
$row->user_id;
723 $user_id = $ilUser->getID();
727 $GLOBALS[
'ilLog']->write(__METHOD__.
' no valid obj_id');
732 $set = $ilDB->queryF(
'
733 SELECT rvalue FROM scorm_tracking
738 array(
'integer',
'integer',
'text',
'integer'),
739 array($user_id,0,
'last_visited',$obj_id));
740 if ($rec = $ilDB->fetchAssoc($set)) {
741 $ilDB->update(
'scorm_tracking',
743 'rvalue' => array(
'clob',
$data),
747 'user_id' => array(
'integer', $user_id),
748 'sco_id' => array(
'integer', 0),
749 'lvalue' => array(
'text',
'last_visited'),
750 'obj_id' => array(
'integer', $obj_id)
755 $ilDB->insert(
'scorm_tracking', array(
756 'obj_id' => array(
'integer', $obj_id),
757 'user_id' => array(
'integer', $user_id),
758 'sco_id' => array(
'integer', 0),
759 'lvalue' => array(
'text',
'last_visited'),
760 'rvalue' => array(
'clob',
$data),
769 header(
'Content-Type: text/plain; charset=UTF-8');