From f806d6a1bdb6776f6414660194c3942ff919573e Mon Sep 17 00:00:00 2001 From: bdaloukas Date: Mon, 14 Aug 2017 15:30:29 +0300 Subject: [PATCH] New: Auto detects common problems in millionaire --- check.php | 18 +++++++++++++++++- lang/en/game.php | 1 + showanswers.php | 4 +++- version.php | 4 ++-- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/check.php b/check.php index ddc6349..bacf64a 100644 --- a/check.php +++ b/check.php @@ -100,6 +100,7 @@ function game_check_common_problems_multichoice_question($game, &$warnings) { $select = 'q.category in ('.implode(',', $cats).')'; } } + $select0 = $select; if (game_get_moodle_version() < '02.06') { $table = "{$CFG->prefix}question q, {$CFG->prefix}question_multichoice qmo"; @@ -114,6 +115,19 @@ function game_check_common_problems_multichoice_question($game, &$warnings) { if ($rec->c != 0) { $warnings[] = get_string( 'millionaire_also_multichoice', 'game').': '.$rec->c; } + + $select = $select0; + if (game_get_moodle_version() < '02.06') { + $select .= " AND qtype='multichoice' AND qmo.single = 1 AND qmo.question=q.id"; + } else { + $select .= " AND qtype='multichoice' AND qmo.single = 1 AND qmo.questionid=q.id"; + } + + $sql = "SELECT COUNT(*) as c FROM $table WHERE $select"; + $rec = $DB->get_record_sql( $sql); + if ($rec->c == 0) { + $warnings[] = get_string( 'millionaire_no_multichoice_questions', 'game'); + } } /** @@ -216,8 +230,10 @@ function game_check_common_problems_shortanswer_question($game, &$warnings) { foreach ($recs as $rec) { // Maybe there are more answers to one question. I use as correct the one with bigger fraction. $sql = "SELECT DISTINCT answer FROM {$CFG->prefix}question_answers WHERE question={$rec->id} ORDER BY fraction DESC"; - if (($rec2 = $DB->get_record_sql( $sql, null, 0, 1)) != false) { + $recs2 = $DB->get_records_sql( $sql); + foreach( $recs2 as $rec2) { $a[] = $rec2->answer; + break; } } game_check_common_problems_shortanswer_allowspaces( $game, $warnings, $a); diff --git a/lang/en/game.php b/lang/en/game.php index 9027b1b..dbbb01b 100644 --- a/lang/en/game.php +++ b/lang/en/game.php @@ -42,6 +42,7 @@ $string[ 'millionaire_also_multichoice'] = 'Multichoice answers without single c $string[ 'common_problems_allowspaces'] = 'There are words with spaces but in the game, spaces are not allowed'; $string[ 'common_problems_shortanswer_hangman'] = 'Not all characters are in the language of game'; $string[ 'common_problems_crossword_param1'] = "'Maximum number of cols/rows' is too small"; +$string[ 'millionaire_no_multichoice_questions'] = 'There are no multichoice questions'; // Classes. $string[ 'eventgamecreated'] = 'Game created'; diff --git a/showanswers.php b/showanswers.php index 3662b0f..1cb3e97 100644 --- a/showanswers.php +++ b/showanswers.php @@ -206,7 +206,9 @@ function game_showanswers_question( $game, $context) { if ($game->subcategories) { $cats = question_categorylist( $game->questioncategoryid); - if (strpos( $cats, ',') > 0) { + if (is_array( $cats)) { + $select = ' category in ('.implode( ',', $cats).')'; + } else if (strpos( $cats, ',') > 0) { $select = ' category in ('.$cats.')'; } } diff --git a/version.php b/version.php index 5794e3a..5cbeddd 100644 --- a/version.php +++ b/version.php @@ -35,10 +35,10 @@ if (!isset( $plugin)) { } $plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics). -$plugin->version = 2017081302; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2017081401; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2010112400; // Requires Moodle 2.0. $plugin->cron = 0; // Period for cron to check this module (secs). -$plugin->release = '2017-08-13'; +$plugin->release = '2017-08-14'; $plugin->maturity = MATURITY_STABLE; if ($useplugin != 2) {