Fix get_scorm_time() static not static calls see #7342

1.9.x
Julio Montoya 11 years ago
parent 048d7a3ee5
commit 03c75e8a3f
  1. 2
      main/newscorm/learnpath.class.php
  2. 85
      main/newscorm/learnpathItem.class.php
  3. 8
      main/newscorm/lp_stats.php
  4. 12
      main/tracking/courseLogCSV.php
  5. 4
      main/tracking/userLog.php

@ -1802,7 +1802,7 @@ class learnpath
$info .= "top.set_max(" . learnpathItem :: get_max() . ");\n";
$info .= "top.set_min(" . learnpathItem :: get_min() . ");\n";
$info .= "top.set_lesson_status('" . learnpathItem :: get_status() . "');";
$info .= "top.set_session_time('" . learnpathItem :: get_scorm_time('js') . "');";
$info .= "top.set_session_time('" . learnpathItem :: getScormTimeFromParameter('js') . "');";
$info .= "top.set_suspend_data('" . learnpathItem :: get_suspend_data() . "');";
$info .= "top.set_saved_lesson_status('" . learnpathItem :: get_status() . "');";
$info .= "top.set_flag_synchronized();";

@ -1770,6 +1770,24 @@ class learnpathItem
}
}
/**
* @param string $origin
* @return string
*/
public static function getScormTimeFromParameter($origin = 'php', $time = null)
{
$h = get_lang('h');
if (!isset($time)) {
if ($origin == 'js') {
return '00:00:00';
} else {
return '00' . $h . '00\'00"';
}
} else {
return self::calculateScormTime($origin, $time);
}
}
/**
* Gets the total time spent on this item view so far
* @param string $origin Origin of the request. If coming from PHP,
@ -1783,7 +1801,6 @@ class learnpathItem
$given_time = null,
$query_db = false
) {
$h = get_lang('h');
$time = null;
$course_id = api_get_course_int_id();
if (!isset($given_time)) {
@ -1793,34 +1810,26 @@ class learnpathItem
0
);
}
if (is_object($this)) {
if ($query_db === true) {
$table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$sql = "SELECT start_time, total_time FROM $table
WHERE
c_id = $course_id AND
id = '" . $this->db_item_view_id . "' AND
view_count = '" . $this->get_attempt_id() . "'";
$res = Database::query($sql);
$row = Database::fetch_array($res);
$start = $row['start_time'];
$stop = $start + $row['total_time'];
} else {
$start = $this->current_start_time;
$stop = $this->current_stop_time;
}
if (!empty($start)) {
if (!empty($stop)) {
$time = $stop - $start;
} else {
$time = time() - $start;
}
}
if ($query_db === true) {
$table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$sql = "SELECT start_time, total_time FROM $table
WHERE
c_id = $course_id AND
id = '" . $this->db_item_view_id . "' AND
view_count = '" . $this->get_attempt_id() . "'";
$res = Database::query($sql);
$row = Database::fetch_array($res);
$start = $row['start_time'];
$stop = $start + $row['total_time'];
} else {
if ($origin == 'js') {
return '00:00:00';
$start = $this->current_start_time;
$stop = $this->current_stop_time;
}
if (!empty($start)) {
if (!empty($stop)) {
$time = $stop - $start;
} else {
return '00' . $h . '00\'00"';
$time = time() - $start;
}
}
} else {
@ -1832,21 +1841,35 @@ class learnpathItem
0
);
}
$time = self::calculateScormTime($origin, $time);
return $time;
}
/**
* @param string $origin
* @param string $time
* @return string
*/
public static function calculateScormTime($origin, $time)
{
$h = get_lang('h');
$hours = $time / 3600;
$mins = ($time % 3600) / 60;
$secs = ($time % 60);
if ($origin == 'js') {
$scorm_time = trim(sprintf("%4d:%02d:%02d", $hours, $mins, $secs));
$scormTime = trim(sprintf("%4d:%02d:%02d", $hours, $mins, $secs));
} else {
$scorm_time = trim(
$scormTime = trim(
sprintf("%4d$h%02d'%02d\"", $hours, $mins, $secs)
);
}
if (self::debug > 2) {
error_log('learnpathItem::get_scorm_time(' . $scorm_time . ')', 0);
error_log('learnpathItem::get_scorm_time(' . $scormTime . ')', 0);
}
return $scorm_time;
return $scormTime;
}
/**

@ -335,7 +335,7 @@ if (is_array($list) && count($list) > 0) {
$lesson_status = $row['mystatus'];
$score = $row['myscore'];
$time_for_total = $row['mytime'];
$time = learnpathItem :: get_scorm_time('js', $row['mytime']);
$time = learnpathItem :: getScormTimeFromParameter('js', $row['mytime']);
$scoIdentifier = $row['myid'];
if ($score == 0) {
@ -627,7 +627,7 @@ if (is_array($list) && count($list) > 0) {
}
$time_for_total = $subtotal_time;
$time = learnpathItem :: get_scorm_time('js', $subtotal_time);
$time = learnpathItem :: getScormTimeFromParameter('js', $subtotal_time);
if (empty($title)) {
$title = rl_get_resource_name(api_get_course_id(), $lp_id, $row['myid']);
}
@ -818,7 +818,7 @@ if (is_array($list) && count($list) > 0) {
$mktime_exe_date = api_strtotime($row_attempts['exe_date'], 'UTC');
if ($mktime_start_date && $mktime_exe_date) {
$mytime = ((int) $mktime_exe_date - (int) $mktime_start_date);
$time_attemp = learnpathItem :: get_scorm_time('js', $mytime);
$time_attemp = learnpathItem :: getScormTimeFromParameter('js', $mytime);
$time_attemp = str_replace('NaN', '00' . $h . '00\'00"', $time_attemp);
} else {
$time_attemp = ' - ';
@ -945,7 +945,7 @@ if (!empty($a_my_id)) {
}
}
$total_time = learnpathItem :: get_scorm_time('js', $total_time);
$total_time = learnpathItem :: getScormTimeFromParameter('js', $total_time);
$total_time = str_replace('NaN', '00' . $h . '00\'00"', $total_time);
if (!$is_allowed_to_edit && $result_disabled_ext_all) {

@ -118,11 +118,11 @@ if ($is_allowedToTrack) {
// BEGIN % visited
// sum of all items (= multiple learningpaths + SCORM imported paths)
$sql = "SELECT COUNT(DISTINCT(iv.lp_item_id)) FROM $tbl_learnpath_item_view iv " .
"INNER JOIN $tbl_learnpath_view v
"INNER JOIN $tbl_learnpath_view v
ON iv.lp_view_id = v.id " .
"WHERE
v.c_id = $course_id AND
iv.c_id = $course_id AND
iv.c_id = $course_id AND
v.user_id = " . $results[$j][0];
$total_lpath_items = getOneResult($sql);
@ -130,7 +130,7 @@ if ($is_allowedToTrack) {
$sql = "SELECT COUNT(DISTINCT(iv.lp_item_id)) " .
"FROM $tbl_learnpath_item_view iv " .
"INNER JOIN $tbl_learnpath_view v ON iv.lp_view_id = v.id " .
"WHERE
"WHERE
v.c_id = $course_id AND
iv.c_id = $course_id AND
v.user_id = " . $results[$j][0] . " " .
@ -272,7 +272,7 @@ if ($is_allowedToTrack) {
FROM $TABLETRACK_LINKS AS sl, $TABLECOURSE_LINKS AS cl
WHERE
cl.c_id = $course_id AND
sl.links_link_id = cl.id AND
sl.links_link_id = cl.id AND
sl.links_cours_id = '$_cid'
GROUP BY cl.title, cl.url";
@ -371,7 +371,7 @@ if ($is_allowedToTrack) {
"FROM $tbl_learnpath_item i " .
"INNER JOIN $tbl_learnpath_item_view iv ON i.id=iv.lp_item_id " .
"INNER JOIN $tbl_learnpath_view v ON iv.lp_view_id=v.id " .
"WHERE i.c_id = $course_id AND
"WHERE i.c_id = $course_id AND
iv.c_id = $course_id AND
v.c_id = $course_id AND
v.user_id=$studentId and v.lp_id=$contentId ORDER BY v.id, i.id";
@ -380,7 +380,7 @@ if ($is_allowedToTrack) {
$title_line .= get_lang('ScormTitleColumn') . ";" . get_lang('ScormStatusColumn') . ";" . get_lang('ScormScoreColumn') . ";" . get_lang('ScormTimeColumn');
while ($ar3['status'] != '') {
require_once '../newscorm/learnpathItem.class.php';
$time = learnpathItem::get_scorm_time('php', $ar3['total_time']);
$time = learnpathItem::getScormTimeFromParameter('php', $ar3['total_time']);
$line .= $title . ";" . $ar3['status'] . ";" . $ar3['score'] . ";" . $time;
$ar3 = Database::fetch_array($result3);
}

@ -332,9 +332,9 @@ if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse )) {
</tr>";
while ($ar3['status'] != '') {
require_once '../newscorm/learnpathItem.class.php';
$time = learnpathItem::get_scorm_time('php',$ar3['total_time']);
$time = learnpathItem::getScormTimeFromParameter('php', $ar3['total_time']);
echo "<tr><td>&nbsp;&nbsp;&nbsp;</td><td>";
echo "$title</td><td align=right>{$ar3['status']}</td><td align=right>{$ar3['score']}</td><td align=right>$time</td>";
echo "$title</td><td align=right>{$ar3['status']}</td><td align=right>{$ar3['score']}</td><td align=right>$time</td>";
echo "</tr>";
$ar3=Database::fetch_array($result3);
}

Loading…
Cancel
Save