Beispiel #1
0
             $questionnum = required_param('question', PARAM_INT);
             $userid = $USER->id;
             $answerid = required_param('answer', PARAM_INT);
             realtimequiz_record_answer($quizid, $questionnum, $userid, $answerid, $context);
         } else {
             if ($requesttype == 'getresults') {
                 $questionnum = required_param('question', PARAM_INT);
                 if (realtimequiz_current_question($quizid, $questionnum)) {
                     $timeleft = $DB->get_field('realtimequiz', 'nextendtime', array('id' => $quizid)) - time();
                     if ($timeleft < 0) {
                         $timeleft = 0;
                     }
                     realtimequiz_send_await_results($timeleft);
                     // results not yet ready
                 } else {
                     realtimequiz_send_question($quizid, $context);
                     // asked for results for wrong question
                 }
             } else {
                 realtimequiz_send_error(get_string('unknownrequest', 'realtimequiz') . $requesttype . '\'');
             }
         }
     }
     break;
 case REALTIMEQUIZ_STATUS_SHOWRESULTS:
     // Results being displayed
     if ($requesttype == 'getquestion') {
         // Asking for the next question
         realtimequiz_send_await_question();
     } else {
         if ($requesttype == 'postanswer' || $requesttype == 'getresults' || $requesttype == 'teacherrejoin') {
Beispiel #2
0
function realtimequiz_goto_question($context, $quizid, $questionnum)
{
    global $DB;
    if (has_capability('mod/realtimequiz:control', $context)) {
        $quiz = $DB->get_record('realtimequiz', array('id' => $quizid));
        // Update the question statistics:
        $quiz->classresult += $quiz->questionresult;
        $quiz->questionresult = 0;
        $questionid = $DB->get_field('realtimequiz_question', 'id', array('quizid' => $quizid, 'questionnum' => $questionnum));
        if ($questionid) {
            $quiz->currentquestion = $questionid;
            $quiz->status = REALTIMEQUIZ_STATUS_PREVIEWQUESTION;
            $quiz->nextendtime = time() + 2;
            // Give everyone a chance to get the question before starting
            $DB->update_record('realtimequiz', $quiz);
            // FIXME - not update all fields?
            realtimequiz_send_question($quizid, $context, true);
        } else {
            // Assume we have run out of questions
            $quiz->status = REALTIMEQUIZ_STATUS_FINALRESULTS;
            $DB->update_record('realtimequiz', $quiz);
            // FIXME - not update all fields?
            realtimequiz_send_final_results($quizid);
        }
    } else {
        realtimequiz_send_error(get_string('notauthorised', 'realtimequiz'));
    }
}