function game_millionaire_loadquestions($game, $millionaire, &$query, &$aanswer, $context) { global $DB; $query = $DB->get_record('game_queries', array('id' => $millionaire->queryid), 'id,questiontext,answertext,correct,questionid'); $aids = explode(',', $query->answertext); $aanswer = array(); foreach ($aids as $id) { $rec = $DB->get_record('question_answers', array('id' => $id), 'id,answer'); $aanswer[] = game_filterquestion_answer(str_replace('\\"', '"', $rec->answer), $id, $context->id, $game->course); } }
function game_print_question_multichoice($game, $question, $context) { global $CFG; $i = 0; $questiontext = $question->questiontext; $answerprompt = get_string('singleanswer', 'quiz'); $feedback = ''; $anss = array(); foreach ($question->options->answers as $a) { $answer = new stdClass(); if (substr($a->answer, 0, 3) == '<p>' or substr($a->answer, 0, 3) == '<P>') { $a->answer = substr($a->answer, 3); $s = rtrim($a->answer); if (substr($s, 0, -3) == '<p>' or substr($s, 0, -3) == '<P>') { $a->answer = substr($a->answer, 0, -3); } } $a->answer = game_filterquestion_answer(str_replace('\\"', '"', $a->answer), $a->id, $context->id, $game->course); $answer->control = "<input id=\"resp{$question->id}_{$a->id}\" name=\"resp{$question->id}_\" type=\"radio\" value=\"{$a->id}\" /> " . $a->answer; $answer->class = 'radio'; $answer->id = $a->id; $answer->text = $a->answer; $answer->feedbackimg = ''; $answer->feedback = ''; $anss[] = $answer; } ?> <div class="qtext"> <?php echo game_filterquestion(str_replace('\\"', '"', $questiontext), $question->id, $context->id, $game->course); ?> </div> <div class="ablock clearfix"> <div class="prompt"> <?php echo $answerprompt; ?> </div> <table class="answer"> <?php $row = 1; foreach ($anss as $answer) { ?> <tr class="<?php echo 'r' . ($row = $row ? 0 : 1); ?> "> <td> <?php echo $answer->control; ?> </td> </tr> <?php } ?> </table> </div> <?php }
function game_millionaire_SelectQuestion(&$aAnswer, $game, $attempt, &$millionaire, &$query, $context) { global $DB, $USER; if ($game->sourcemodule != 'quiz' and $game->sourcemodule != 'question') { print_error(get_string('millionaire_sourcemodule_must_quiz_question', 'game', get_string('modulename', 'quiz')) . ' ' . get_string('modulename', $attempt->sourcemodule)); } if ($millionaire->queryid != 0) { game_millionaire_loadquestions($millionaire, $query, $aAnswer); return; } if ($game->sourcemodule == 'quiz') { if ($game->quizid == 0) { error(get_string('must_select_quiz', 'game')); } $select = "qtype='multichoice' AND quiz='{$game->quizid}' " . " AND qqi.question=q.id"; $table = "{question} q,{quiz_question_instances} qqi"; } else { 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 (strpos($cats, ',') > 0) { $select = 'category in (' . $cats . ')'; } } $select .= " AND qtype='multichoice'"; $table = '{question} q'; } $select .= ' AND hidden=0'; if ($game->shuffle) { $questionid = game_question_selectrandom($game, $table, $select, 'q.id as id', true); } else { $questionid = game_millionaire_select_serial_question($game, $table, $select, 'q.id as id', $millionaire->level); } if ($questionid == 0) { print_error(get_string('no_questions', 'game')); } $q = $DB->get_record('question', array('id' => $questionid), 'id,questiontext'); $recs = $DB->get_records('question_answers', array('question' => $questionid)); if ($recs === false) { print_error(get_string('no_questions', 'game')); } $correct = 0; $ids = array(); foreach ($recs as $rec) { $aAnswer[] = game_filterquestion_answer(str_replace('\\"', '"', $rec->answer), $rec->id, $context->id, $game->course); $ids[] = $rec->id; if ($rec->fraction == 1) { $correct = $rec->id; } } $count = count($aAnswer); for ($i = 1; $i <= $count; $i++) { $sel = mt_rand(0, $count - 1); $temp = array_splice($aAnswer, $sel, 1); $aAnswer[] = $temp[0]; $temp = array_splice($ids, $sel, 1); $ids[] = $temp[0]; } $query = new StdClass(); $query->attemptid = $attempt->id; $query->gamekind = $game->gamekind; $query->gameid = $game->id; $query->userid = $USER->id; $query->sourcemodule = $game->sourcemodule; $query->glossaryentryid = 0; $query->questionid = $questionid; $query->questiontext = addslashes($q->questiontext); $query->answertext = implode(',', $ids); $query->correct = array_search($correct, $ids) + 1; if (!($query->id = $DB->insert_record('game_queries', $query))) { print_object($query); print_error('error inserting to game_queries'); } $updrec->id = $millionaire->id; $updrec->queryid = $query->id; if (!($newid = $DB->update_record('game_millionaire', $updrec))) { print_error('error updating in game_millionaire'); } $score = $millionaire->level / 15; game_updateattempts($game, $attempt, $score, 0); game_update_queries($game, $attempt, $query, $score, ''); }