Browse Source

Message with common problems

MOODLE_20_STABLE
bdaloukas 8 years ago
parent
commit
ab7c945647
  1. 1
      lang/en/game.php
  2. 107
      locallib.php
  3. 6
      showanswers.php
  4. 6
      version.php

1
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';

107
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 = '<ul>'.get_string( 'common_problems', 'game');
foreach( $warnings as $line) {
$s .= '<li>'.$line.'</li>';
}
return $s.'</ul>';
}
/**
* 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";
}
}

6
showanswers.php

@ -52,9 +52,9 @@ echo '<br><br>';
$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 '<hr>'.$s;
echo $OUTPUT->footer();

6
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
}

Loading…
Cancel
Save