Example #1
0
function game_bookquiz_check_questions($id, $game, $attempt, $bookquiz, $context)
{
    global $USER, $DB;
    $scoreattempt = optional_param('scoreattempt', 0, PARAM_INT);
    $responses = data_submitted();
    $questionlist = $responses->questionids;
    $questions = game_sudoku_getquestions($questionlist);
    $grades = game_grade_questions($questions);
    $scorequestion = 0;
    $scoreattempt = 0;
    $chapterid = required_param('chapterid', PARAM_INT);
    $nextchapterid = required_param('nextchapterid', PARAM_INT);
    foreach ($questions as $question) {
        if (!array_key_exists($question->id, $grades)) {
            //no answered
            continue;
        }
        $grade = $grades[$question->id];
        if ($grade->grade < 0.5) {
            continue;
        }
        //found one correct answer
        if (!$DB->get_field('game_bookquiz_chapters', 'id', array('attemptid' => $attempt->id, 'chapterid' => $chapterid))) {
            $newrec = new stdClass();
            $newrec->attemptid = $attempt->id;
            $newrec->chapterid = $chapterid;
            if (!$DB->insert_record('game_bookquiz_chapters', $newrec, false)) {
                print_object($newrec);
                print_error("Can't insert to table game_bookquiz_chapters");
            }
        }
        //Have to go to next page.
        $bookquiz->lastchapterid = $nextchapterid;
        $scorequestion = 1;
        break;
    }
    $query = new stdClass();
    $query->id = 0;
    $query->attemptid = $attempt->id;
    $query->gameid = $game->id;
    $query->userid = $USER->id;
    $query->sourcemodule = 'question';
    $query->questionid = $question->id;
    $query->glossaryentryid = 0;
    $query->questiontext = $question->questiontext;
    $query->timelastattempt = time();
    game_update_queries($game, $attempt, $query, $scorequestion, '');
    game_updateattempts($game, $attempt, $scoreattempt, 0);
    game_bookquiz_continue($id, $game, $attempt, $bookquiz, $bookquiz->lastchapterid, $context);
}
function game_create($game, $id, $forcenew, $course, $context)
{
    global $USER, $CFG, $DB;
    $attempt = game_getattempt($game, $detail);
    switch ($game->gamekind) {
        case 'cross':
            game_cross_continue($id, $game, $attempt, $detail, '', $forcenew, $context);
            break;
        case 'hangman':
            if (array_key_exists('newletter', $_GET)) {
                $newletter = $_GET['newletter'];
            } else {
                $newletter = '';
            }
            if (array_key_exists('action2', $_GET)) {
                $action2 = $_GET['action2'];
            } else {
                $action2 = '';
            }
            game_hangman_continue($id, $game, $attempt, $detail, $newletter, $action2, $context);
            break;
        case 'millionaire':
            game_millionaire_continue($id, $game, $attempt, $detail, $context);
            break;
        case 'bookquiz':
            if (array_key_exists('chapterid', $_GET)) {
                $chapterid = (int) $_GET['chapterid'];
            } else {
                $chapterid = 0;
            }
            game_bookquiz_continue($id, $game, $attempt, $detail, $chapterid);
            break;
        case 'sudoku':
            game_sudoku_continue($id, $game, $attempt, $detail, '', $context);
            break;
        case 'cryptex':
            game_cryptex_continue($id, $game, $attempt, $detail, $forcenew, $context);
            break;
        case 'snakes':
            game_snakes_continue($id, $game, $attempt, $detail, $context);
            break;
        case 'hiddenpicture':
            game_hiddenpicture_continue($id, $game, $attempt, $detail, $context);
            break;
        default:
            error("Game {$game->gamekind} not found");
            break;
    }
}
function game_create($game, $id, $forcenew, $course, $context)
{
    global $USER, $CFG, $DB;
    $attempt = game_getattempt($game, $detail);
    $chapterid = optional_param('chapterid', 0, PARAM_INT);
    $newletter = optional_param('newletter', '', PARAM_ALPHA);
    $action2 = optional_param('action2', '', PARAM_ALPHA);
    switch ($game->gamekind) {
        case 'cross':
            game_cross_continue($id, $game, $attempt, $detail, '', $forcenew, $context);
            break;
        case 'hangman':
            game_hangman_continue($id, $game, $attempt, $detail, $newletter, $action2, $context);
            break;
        case 'millionaire':
            game_millionaire_continue($id, $game, $attempt, $detail, $context);
            break;
        case 'bookquiz':
            game_bookquiz_continue($id, $game, $attempt, $detail, $chapterid, $context);
            break;
        case 'sudoku':
            game_sudoku_continue($id, $game, $attempt, $detail, '', $context);
            break;
        case 'cryptex':
            game_cryptex_continue($id, $game, $attempt, $detail, $forcenew, $context);
            break;
        case 'snakes':
            game_snakes_continue($id, $game, $attempt, $detail, $context);
            break;
        case 'hiddenpicture':
            game_hiddenpicture_continue($id, $game, $attempt, $detail, $context);
            break;
        default:
            print_error("Game {$game->gamekind} not found");
            break;
    }
}
function game_bookquiz_check_questions($id, $game, $attempt, $bookquiz)
{
    global $QTYPES, $CFG, $USER;
    $responses = data_submitted();
    $questionlist = $responses->questionids;
    $questions = game_sudoku_getquestions($questionlist);
    $actions = question_extract_responses($questions, $responses, QUESTION_EVENTSUBMIT);
    $scorequestion = 0;
    $scoreattempt = 0;
    foreach ($questions as $question) {
        if (!array_key_exists($question->id, $actions)) {
            //no answered
            continue;
        }
        unset($state);
        unset($cmoptions);
        $question->maxgrade = 100;
        $state->responses = $actions[$question->id]->responses;
        $state->event = QUESTION_EVENTGRADE;
        $cmoptions = array();
        $QTYPES[$question->qtype]->grade_responses($question, $state, $cmoptions);
        if ($state->raw_grade < 50) {
            continue;
        }
        //found one correct answer
        $chapterid = $responses->chapterid;
        if (!get_field('game_bookquiz_chapters', 'id', 'attemptid', $attempt->id, 'chapterid', $chapterid)) {
            unset($newrec);
            $newrec->attemptid = $attempt->id;
            $newrec->chapterid = $chapterid;
            if (!insert_record('game_bookquiz_chapters', $newrec, false)) {
                print_object($newrec);
                error("Can't insert to table game_bookquiz_chapters");
            }
        }
        //Have to go to next page.
        $bookquiz->lastchapterid = $responses->nextchapterid;
        if (!set_field('game_bookquiz', 'lastchapterid', $bookquiz->lastchapterid, 'id', $bookquiz->id)) {
            error("Can't compute next chapter");
        }
        $scorequestion = 1;
        $scoreattempt = $_POST['scoreattempt'];
        break;
    }
    $query->id = 0;
    $query->attemptid = $attempt->id;
    $query->gameid = $game->id;
    $query->userid = $USER->id;
    $query->sourcemodule = 'question';
    $query->questionid = $question->id;
    $query->glossaryentryid = 0;
    $query->questiontext = $question->questiontext;
    $query->timelastattempt = time();
    game_update_queries($game, $attempt, $query, $scorequestion, '');
    game_updateattempts($game, $attempt, $scoreattempt, 0);
    game_bookquiz_continue($id, $game, $attempt, $bookquiz);
}
Example #5
0
function game_bookquiz_check_questions($id, $game, $attempt, $bookquiz)
{
    global $QTYPES, $CFG, $USER, $DB;
    $responses = data_submitted();
    $questionlist = $responses->questionids;
    $questions = game_sudoku_getquestions($questionlist);
    $scorequestion = 0;
    $scoreattempt = 0;
    foreach ($questions as $question) {
        $grade = game_grade_responses($question, $responses, 100, $answertext);
        if ($grade < 50) {
            continue;
        }
        //found one correct answer
        $chapterid = $responses->chapterid;
        if (!$DB->get_field('game_bookquiz_chapters', 'id', array('attemptid' => $attempt->id, 'chapterid' => $chapterid))) {
            unset($newrec);
            $newrec->attemptid = $attempt->id;
            $newrec->chapterid = $chapterid;
            if (!$DB->insert_record('game_bookquiz_chapters', $newrec, false)) {
                print_object($newrec);
                print_error("Can't insert to table game_bookquiz_chapters");
            }
        }
        //Have to go to next page.
        $bookquiz->lastchapterid = $responses->nextchapterid;
        if (!$DB->set_field('game_bookquiz', 'lastchapterid', $bookquiz->lastchapterid, array('id' => $bookquiz->id))) {
            print_error("Can't compute next chapter");
        }
        $scorequestion = 1;
        $scoreattempt = $_POST['scoreattempt'];
        break;
    }
    $query->id = 0;
    $query->attemptid = $attempt->id;
    $query->gameid = $game->id;
    $query->userid = $USER->id;
    $query->sourcemodule = 'question';
    $query->questionid = $question->id;
    $query->glossaryentryid = 0;
    $query->questiontext = $question->questiontext;
    $query->timelastattempt = time();
    game_update_queries($game, $attempt, $query, $scorequestion, '');
    game_updateattempts($game, $attempt, $scoreattempt, 0);
    game_bookquiz_continue($id, $game, $attempt, $bookquiz);
}
function game_create($game, $id, $forcenew, $course)
{
    global $USER, $CFG;
    $attempt = game_getattempt($game, $detail);
    switch ($game->gamekind) {
        case 'cross':
            game_cross_continue($id, $game, $attempt, $detail, '', $forcenew);
            break;
        case 'hangman':
            if (array_key_exists('newletter', $_GET)) {
                $newletter = $_GET['newletter'];
            } else {
                $newletter = '';
            }
            if (array_key_exists('action2', $_GET)) {
                $action2 = $_GET['action2'];
            } else {
                $action2 = '';
            }
            game_hangman_continue($id, $game, $attempt, $detail, $newletter, $action2);
            break;
        case 'millionaire':
            game_millionaire_continue($id, $game, $attempt, $detail);
            break;
        case 'bookquiz':
            if (array_key_exists('chapterid', $_GET)) {
                $chapterid = (int) $_GET['chapterid'];
            } else {
                $chapterid = 0;
            }
            game_bookquiz_continue($id, $game, $attempt, $detail, $chapterid);
            break;
        case 'sudoku':
            game_sudoku_continue($id, $game, $attempt, $detail);
            break;
        case 'cryptex':
            game_cryptex_continue($id, $game, $attempt, $detail, $forcenew);
            break;
        case 'snakes':
            game_snakes_continue($id, $game, $attempt, $detail);
            break;
        case 'hiddenpicture':
            game_hiddenpicture_continue($id, $game, $attempt, $detail);
            break;
        case '':
            echo get_string('useupdategame', 'game');
            print_continue($CFG->wwwroot . '/course/view.php?id=' . $course->id);
            break;
        default:
            error("Game {$game->gamekind} not found");
            break;
    }
}