diff --git a/lang/en/game.php b/lang/en/game.php index 1f9db0f..314feed 100644 --- a/lang/en/game.php +++ b/lang/en/game.php @@ -230,6 +230,7 @@ $string[ 'convertfrom'] = '-'; $string[ 'convertto'] = '-'; $string[ 'gradeaverage'] = 'Average grade'; $string[ 'gradehighest'] = 'Highest grade'; +$string[ 'common_problems'] = 'Common problems'; // File mod_form.php. $string[ 'bookquiz_layout'] = 'Layout'; diff --git a/locallib.php b/locallib.php index 9581374..f1b3791 100644 --- a/locallib.php +++ b/locallib.php @@ -2567,3 +2567,110 @@ function game_use_events() { function game_feedback_for_grade($grade, $gameid) { return ''; } + +/** + * Checks for common problems + * + * @param stdClass $context + * @param stdClass $game + */ +function game_check_common_problems($context, $game) { + if (!has_capability('mod/game:viewreports', $context)) { + return ''; + } + + $warnings = array(); + + switch( $game->gamekind) { + case 'millionaire': + game_check_common_problems_multichoice( $game, $warnings); + break; + case 'hangman': + case 'cross': + case 'cryptex': + game_check_common_problems_shortanswer( $game, $warnings); + break; + } + + if( count( $warnings) == 0) { + return ''; + } + + + $s = ''; +} + +/** + * Checks for common problems on multichoice answers + * + * @param stdClass $game + * @param string $warnings + */ +function game_check_common_problems_multichoice($game, &$warnings) { + + global $CFG, $DB; + + if ($game->questioncategoryid == 0) { + $warnings[] = get_string( 'must_select_questioncategory', 'game'); + return; + } + + // Include subcategories. + $select = 'category='.$game->questioncategoryid; + if ($game->subcategories) { + $cats = question_categorylist( $game->questioncategoryid); + if (count( $cats)) { + $select = 'q.category in ('.implode(',', $cats).')'; + } + } + + if (game_get_moodle_version() < '02.06') { + $table = "{$CFG->prefix}question q, {$CFG->prefix}question_multichoice qmo"; + $select .= " AND qtype='multichoice' AND qmo.single <> 1 AND qmo.question=q.id"; + } else { + $table = "{$CFG->prefix}question q, {$CFG->prefix}qtype_multichoice_options qmo"; + $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_also_multichoice', 'game').': '.$rec->c; + } +} + +/** + * Checks for common problems on short answers + * + * @param stdClass $game + * @param string $warnings + */ +function game_check_common_problems_shortanswer($game, &$warnings) { + + global $CFG, $DB; + + if ($game->sourcemodule == 'question') { + if ($game->questioncategoryid == 0) { + $warnings[] = get_string( 'must_select_questioncategory', 'game'); + return; + } + + // Include subcategories. + $select = 'category='.$game->questioncategoryid; + if ($game->subcategories) { + $cats = question_categorylist( $game->questioncategoryid); + if (count( $cats)) { + $select = 'q.category in ('.implode(',', $cats).')'; + } + } + + $table = '{question} q'; + $select .= " AND q.qtype = 'shortanswer'"; + + $sql = "SELECT COUNT(*) as c FROM $table WHERE $select"; + } +} diff --git a/showanswers.php b/showanswers.php index d2ab2d4..9d38566 100644 --- a/showanswers.php +++ b/showanswers.php @@ -52,9 +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); -} +$s = game_check_common_problems( $context, $game); +if ($s != '') + echo '
'.$s; echo $OUTPUT->footer(); diff --git a/version.php b/version.php index f586f86..9642730 100644 --- a/version.php +++ b/version.php @@ -35,12 +35,12 @@ if (!isset( $plugin)) { } $plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics). -$plugin->version = 2017063002; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2017070201; // 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-06-30'; +$plugin->release = '2017-07-02'; $plugin->maturity = MATURITY_STABLE; if ($useplugin != 2) { - $module = $plugin; + $module = $plugin }