Permalink
Browse files

MDL-28277 SCORM optimising function get_scorm_question_count

  • Loading branch information...
1 parent b2f5ce3 commit 3ab853fade076d2e40fc2563d4f2ccc388201a8b @ankitagarwal ankitagarwal committed Nov 2, 2011
Showing with 20 additions and 18 deletions.
  1. +1 −1 mod/scorm/report/interactions/report.php
  2. +19 −17 mod/scorm/report/reportlib.php
@@ -179,7 +179,7 @@ function display($scorm, $cm, $course, $download) {
$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;
@@ -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;
}

0 comments on commit 3ab853f

Please sign in to comment.