diff --git a/mod/scorm/report/interactions/report.php b/mod/scorm/report/interactions/report.php index 4b097d0267e..4de69bfdf88 100644 --- a/mod/scorm/report/interactions/report.php +++ b/mod/scorm/report/interactions/report.php @@ -179,7 +179,7 @@ class scorm_interactions_report extends scorm_default_report { $countsql .= 'COUNT(DISTINCT(u.id)) AS nbusers '; $countsql .= $from.$where; $attempts = $DB->get_records_sql($select.$from.$where, $params); - $questioncount = get_scorm_question_count($scoes,$attempts); + $questioncount = get_scorm_question_count($scorm->id); for($id = 0; $id < $questioncount; $id++) { if ($displayoptions['qtext']) { $columns[] = 'question' . $id; diff --git a/mod/scorm/report/reportlib.php b/mod/scorm/report/reportlib.php index 7f3008dda43..17528a360f9 100644 --- a/mod/scorm/report/reportlib.php +++ b/mod/scorm/report/reportlib.php @@ -49,27 +49,29 @@ function scorm_report_list($context) { } /** * Returns The maximum numbers of Questions associated with an Scorm Pack - * @param array array of sco objects - * @param array array of attempt objects + * + * @param int Scorm ID * @return int an integer representing the question count */ -function get_scorm_question_count($scoes,$attempts) -{ - $count=0; - foreach($attempts as $scouser){ - foreach($scoes as $sco) { - $i=0; - if ($trackdata = scorm_get_tracks($sco->id, $scouser->userid, $scouser->attempt)) { - $element='cmi.interactions_'.$i.'.id'; - while(isset($trackdata->$element)) { - $i++; - $element='cmi.interactions_'.$i.'.id'; - } - } - if($i>$count) - $count=$i; +function get_scorm_question_count($scormid) { + global $DB; + $count = 0; + $params = array(); + $select = "scormid = ? AND "; + $select .= $DB->sql_like("element", "?", false); + $params[] = $scormid; + $params[] = "cmi.interactions_%.id"; + $rs = $DB->get_recordset_select("scorm_scoes_track", $select, $params, 'element'); + $keywords = array("cmi.interactions_", ".id"); + foreach ($rs as $record) { + $num = trim(str_ireplace($keywords, '', $record->element)); + if (is_numeric($num) && $num > $count) { + $count = $num; } } + //done as interactions start at 0 + $count++; + $rs->close(); // closing recordset return $count; }