Browse Source

Fix: Millionaire with no random quiz questions

MOODLE_20_STABLE
Vasilis Daloukas 10 years ago
parent
commit
8a27fc600f
  1. 21
      millionaire/play.php
  2. 4
      version.php

21
millionaire/play.php

@ -304,11 +304,13 @@ function game_millionaire_SelectQuestion( &$aAnswer, $game, $attempt, &$milliona
$select = "qtype='multichoice' AND quiz='$game->quizid' AND qmo.questionid=q.id". $select = "qtype='multichoice' AND quiz='$game->quizid' AND qmo.questionid=q.id".
" AND qqi.question=q.id"; " AND qqi.question=q.id";
$table = "{quiz_question_instances} qqi,{question} q, {qtype_multichoice_options} qmo"; $table = "{quiz_question_instances} qqi,{question} q, {qtype_multichoice_options} qmo";
$order = '';
}else }else
{ {
$select = "qtype='multichoice' AND qs.quizid='$game->quizid' AND qmo.questionid=q.id". $select = "qtype='multichoice' AND qs.quizid='$game->quizid' AND qmo.questionid=q.id".
" AND qs.questionid=q.id"; " AND qs.questionid=q.id";
$table = "{quiz_slots} qs,{question} q, {qtype_multichoice_options} qmo"; $table = "{quiz_slots} qs,{question} q, {qtype_multichoice_options} qmo";
$order = 'qs.page,qs.slot';
} }
}else }else
{ {
@ -332,7 +334,7 @@ function game_millionaire_SelectQuestion( &$aAnswer, $game, $attempt, &$milliona
if( $game->shuffle or $game->quizid == 0) if( $game->shuffle or $game->quizid == 0)
$questionid = game_question_selectrandom( $game, $table, $select, 'q.id as id', true); $questionid = game_question_selectrandom( $game, $table, $select, 'q.id as id', true);
else else
$questionid = game_millionaire_select_serial_question( $game, $table, $select, 'q.id as id', $millionaire->level); $questionid = game_millionaire_select_serial_question( $game, $table, $select, 'q.id as id', $millionaire->level, $order);
if( $questionid == 0){ if( $questionid == 0){
print_error( get_string( 'no_questions', 'game')); print_error( get_string( 'no_questions', 'game'));
@ -397,28 +399,19 @@ function game_millionaire_SelectQuestion( &$aAnswer, $game, $attempt, &$milliona
game_update_queries( $game, $attempt, $query, $score, ''); game_update_queries( $game, $attempt, $query, $score, '');
} }
function game_millionaire_select_serial_question( $game, $table, $select, $id_fields="id", $level) function game_millionaire_select_serial_question( $game, $table, $select, $id_fields="id", $level, $order)
{ {
global $DB, $USER; global $DB, $USER;
if( $game->sourcemodule == 'quiz') $sql = "SELECT $id_fields,$id_fields FROM ".$table." WHERE $select ";
{ if( $order != '')
$rec = $DB->get_record( 'quiz', array( 'id' => $game->quizid)); $sql .= " ORDER BY $order";
if( $rec === false)
return false;
$questions = $rec->questions;
$questions = explode( ',', $rec->questions);
array_pop( $questions);
}else
{
$sql = "SELECT $id_fields,$id_fields FROM ".$table." WHERE $select ORDER BY q.name";
if( ($recs = $DB->get_records_sql( $sql)) == false) if( ($recs = $DB->get_records_sql( $sql)) == false)
return false; return false;
$questions = array(); $questions = array();
foreach( $recs as $rec) foreach( $recs as $rec)
$questions[] = $rec->id; $questions[] = $rec->id;
}
$count = count( $questions); $count = count( $questions);
if( $count == 0) if( $count == 0)

4
version.php

@ -22,10 +22,10 @@ if( !isset( $plugin))
$useplugin = 2; $useplugin = 2;
$plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics) $plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics)
$plugin->version = 2015071503; // The current module version (Date: YYYYMMDDXX) $plugin->version = 2015071504; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2010112400; // Requires Moodle 2.0 $plugin->requires = 2010112400; // Requires Moodle 2.0
$plugin->cron = 0; // Period for cron to check this module (secs) $plugin->cron = 0; // Period for cron to check this module (secs)
$plugin->release = '3.30.15.3'; $plugin->release = '3.30.15.4';
if( $useplugin != 2) if( $useplugin != 2)
$module = $plugin; $module = $plugin;

Loading…
Cancel
Save