|
|
@ -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"; |
|
|
|
} |
|
|
|
} |
|
|
|