From 8f25c8cb85e6d0272c24d36cae11ddc6ea44409d Mon Sep 17 00:00:00 2001 From: Vasilis Daloukas Date: Thu, 29 Jun 2017 14:09:24 +0300 Subject: [PATCH] Fix: In millionaire shows the correct number of good multichoice questions --- lang/en/game.php | 1 + showanswers.php | 42 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/lang/en/game.php b/lang/en/game.php index 28d8d18..1f9db0f 100644 --- a/lang/en/game.php +++ b/lang/en/game.php @@ -341,6 +341,7 @@ $string[ 'clearrepetitions'] = 'Clear statistics'; $string[ 'computerepetitions'] = 'Compute statistics again'; $string[ 'feedbacks'] = 'Messages correct answer'; $string[ 'repetitions'] = 'Repetitions'; +$string[ 'millionaire_also_multichoice'] = 'Multichoice answers without single correct answer'; // File showattempts.php. $string[ 'lastip'] = 'IP student'; diff --git a/showanswers.php b/showanswers.php index 8bf701d..1337ff7 100644 --- a/showanswers.php +++ b/showanswers.php @@ -52,6 +52,9 @@ echo '

'; $existsbook = ($DB->get_record( 'modules', array( 'name' => 'book'), 'id,id')); game_showanswers( $game, $existsbook, $context); +if ($game->gamekind == 'millionaire') { + game_showanswers_extra_millionaire( $game); +} echo $OUTPUT->footer(); @@ -224,8 +227,12 @@ function game_showanswers_question( $game, $context) { $order = ($showcategories ? 'category,questiontext' : 'questiontext'); $table = '{question} q'; if ($game->gamekind == 'millionaire') { - $select .= " AND qtype='multichoice' AND qmo.single=1 AND qmo.questionid=q.id"; - $table = '{question} q, {qtype_multichoice_options} qmo'; + $select .= " AND q.qtype='multichoice' AND qmo.single=1 AND qmo.question=q.id"; + if (game_get_moodle_version() < '02.06') { + $table .= ',{question_multichoice} qmo'; + } else { + $table .= ',{qtype_multichoice_options} qmo'; + } } game_showanswers_question_select( $game, $table, $select, '*', $order, $showcategories, $game->course, $context); } @@ -506,3 +513,34 @@ function game_showanswers_bookquiz( $game, $context) { game_showanswers_question_select( $game, $table, $select, "DISTINCT q.*", "bc.pagenum,questiontext", $showcategories, $game->course, $context); } + +function game_showanswers_extra_millionaire( $game) +{ + global $CFG, $DB; + + if ($game->questioncategoryid == 0) { + print_error( get_string( 'must_select_questioncategory', 'game')); + } + + // Include subcategories. + $select = 'category='.$game->questioncategoryid; + if ($game->subcategories) { + $cats = question_categorylist( $game->questioncategoryid); + if (count( $cats)) { + $select = 'q.category in ('.implode(',', $cats).')'; + } + } + + $select .= " AND qtype='multichoice' AND qmo.single <> 1 AND qmo.question=q.id"; + if (game_get_moodle_version() < '02.06') { + $table = "{$CFG->prefix}question q, {$CFG->prefix}question_multichoice qmo"; + } else { + $table = "{$CFG->prefix}question q, {$CFG->prefix}qtype_multichoice_options qmo"; + } + + $sql = "SELECT COUNT(*) as c FROM $table WHERE $select"; + $rec = $DB->get_record_sql( $sql); + if ($rec->c != 0) { + echo get_string( 'millionaire_also_multichoice', 'game').': '.$rec->c; + } +}