From 03c75e8a3fed2bec3d2f458c6ac062774b43bcc0 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 22 Oct 2014 13:01:49 +0200 Subject: [PATCH] Fix get_scorm_time() static not static calls see #7342 --- main/newscorm/learnpath.class.php | 2 +- main/newscorm/learnpathItem.class.php | 85 +++++++++++++++++---------- main/newscorm/lp_stats.php | 8 +-- main/tracking/courseLogCSV.php | 12 ++-- main/tracking/userLog.php | 4 +- 5 files changed, 67 insertions(+), 44 deletions(-) diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 2d33d353e65..142d02ee0de 100755 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -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();"; diff --git a/main/newscorm/learnpathItem.class.php b/main/newscorm/learnpathItem.class.php index 665b1250c85..bf9098f06e8 100755 --- a/main/newscorm/learnpathItem.class.php +++ b/main/newscorm/learnpathItem.class.php @@ -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, @@ -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)) { @@ -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 { @@ -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; } /** diff --git a/main/newscorm/lp_stats.php b/main/newscorm/lp_stats.php index 8a5c174e978..6614cf10646 100755 --- a/main/newscorm/lp_stats.php +++ b/main/newscorm/lp_stats.php @@ -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) { @@ -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']); } @@ -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 = ' - '; @@ -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) { diff --git a/main/tracking/courseLogCSV.php b/main/tracking/courseLogCSV.php index 7ab9be9d7e2..9b7d967300c 100755 --- a/main/tracking/courseLogCSV.php +++ b/main/tracking/courseLogCSV.php @@ -118,11 +118,11 @@ // 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 @@ $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 @@ 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 @@ "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 @@ $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); } diff --git a/main/tracking/userLog.php b/main/tracking/userLog.php index 3e979d14627..af485e9ff97 100755 --- a/main/tracking/userLog.php +++ b/main/tracking/userLog.php @@ -332,9 +332,9 @@ "; 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 "   "; - echo "$title{$ar3['status']}{$ar3['score']}$time"; + echo "$title{$ar3['status']}{$ar3['score']}$time"; echo ""; $ar3=Database::fetch_array($result3); }