Skip to content

Commit

Permalink
Fix get_scorm_time() static not static calls see #7342
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Oct 22, 2014
1 parent 048d7a3 commit 03c75e8
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 44 deletions.
2 changes: 1 addition & 1 deletion main/newscorm/learnpath.class.php
Expand Up @@ -1802,7 +1802,7 @@ public function get_js_info($item_id = '') {
$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();";
Expand Down
85 changes: 54 additions & 31 deletions main/newscorm/learnpathItem.class.php
Expand Up @@ -1770,6 +1770,24 @@ public function get_suspend_data()
}
}

/**
* @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,
Expand All @@ -1783,7 +1801,6 @@ public function get_scorm_time(
$given_time = null,
$query_db = false
) {
$h = get_lang('h');
$time = null;
$course_id = api_get_course_int_id();
if (!isset($given_time)) {
Expand All @@ -1793,34 +1810,26 @@ public function get_scorm_time(
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 {
Expand All @@ -1832,21 +1841,35 @@ public function get_scorm_time(
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;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions main/newscorm/lp_stats.php
Expand Up @@ -335,7 +335,7 @@
$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) {
Expand Down Expand Up @@ -627,7 +627,7 @@
}

$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']);
}
Expand Down Expand Up @@ -818,7 +818,7 @@
$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 = ' - ';
Expand Down Expand Up @@ -945,7 +945,7 @@
}
}

$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) {
Expand Down
12 changes: 6 additions & 6 deletions main/tracking/courseLogCSV.php
Expand Up @@ -118,19 +118,19 @@
// 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);

// sum of all completed 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 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] . " " .
Expand Down Expand Up @@ -272,7 +272,7 @@
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";

Expand Down Expand Up @@ -371,7 +371,7 @@
"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";
Expand All @@ -380,7 +380,7 @@
$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);
}
Expand Down
4 changes: 2 additions & 2 deletions main/tracking/userLog.php
Expand Up @@ -332,9 +332,9 @@
</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);
}
Expand Down

0 comments on commit 03c75e8

Please sign in to comment.