/** * Return questions information for a given attempt. * * @param quiz_attempt $attemptobj the quiz attempt object * @param bool $review whether if we are in review mode or not * @param mixed $page string 'all' or integer page number * @return array array of questions including data */ private static function get_attempt_questions_data(quiz_attempt $attemptobj, $review, $page = 'all') { global $PAGE; $questions = array(); $contextid = $attemptobj->get_quizobj()->get_context()->id; $displayoptions = $attemptobj->get_display_options($review); $renderer = $PAGE->get_renderer('mod_quiz'); foreach ($attemptobj->get_slots($page) as $slot) { $question = array('slot' => $slot, 'type' => $attemptobj->get_question_type_name($slot), 'page' => $attemptobj->get_question_page($slot), 'flagged' => $attemptobj->is_question_flagged($slot), 'html' => $attemptobj->render_question($slot, $review, $renderer) . $PAGE->requires->get_end_code()); if ($attemptobj->is_real_question($slot)) { $question['number'] = $attemptobj->get_question_number($slot); $question['state'] = (string) $attemptobj->get_question_state($slot); $question['status'] = $attemptobj->get_question_status($slot, $displayoptions->correctness); } if ($displayoptions->marks >= question_display_options::MAX_ONLY) { $question['maxmark'] = $attemptobj->get_question_attempt($slot)->get_max_mark(); } if ($displayoptions->marks >= question_display_options::MARK_AND_MAX) { $question['mark'] = $attemptobj->get_question_mark($slot); } $questions[] = $question; } return $questions; }
$picture = print_user_picture($student, $attemptobj->get_courseid(), $student->picture, false, true); $rows[] = '<tr><th scope="row" class="cell">' . $picture . '</th><td class="cell"><a href="' . $CFG->wwwroot . '/user/view.php?id=' . $student->id . '&course=' . $attemptobj->get_courseid() . '">' . fullname($student, true) . '</a></td></tr>'; } /// Quiz name. $rows[] = '<tr><th scope="row" class="cell">' . get_string('modulename', 'quiz') . '</th><td class="cell">' . format_string($attemptobj->get_quiz_name()) . '</td></tr>'; /// Question name. $rows[] = '<tr><th scope="row" class="cell">' . get_string('question', 'quiz') . '</th><td class="cell">' . format_string($attemptobj->get_question($questionid)->name) . '</td></tr>'; /// Other attempts at the quiz. if ($attemptobj->has_capability('mod/quiz:viewreports')) { $attemptlist = $attemptobj->links_to_other_attempts($baseurl); if ($attemptlist) { $rows[] = '<tr><th scope="row" class="cell">' . get_string('attempts', 'quiz') . '</th><td class="cell">' . $attemptlist . '</td></tr>'; } } /// Timestamp of this action. $timestamp = $attemptobj->get_question_state($questionid)->timestamp; if ($timestamp) { $rows[] = '<tr><th scope="row" class="cell">' . get_string('completedon', 'quiz') . '</th><td class="cell">' . userdate($timestamp) . '</td></tr>'; } /// Now output the summary table, if there are any rows to be shown. if (!empty($rows)) { echo '<table class="generaltable generalbox quizreviewsummary"><tbody>', "\n"; echo implode("\n", $rows); echo "\n</tbody></table>\n"; } /// Print the question in the requested state. if ($stateid) { $baseurl .= '&state=' . $stateid; } $attemptobj->print_question($questionid, true, $baseurl); /// Finish the page
/// Extract the responses. $actions will be an array indexed by the questions ids. $actions = question_extract_responses($attemptobj->get_questions($submittedquestionids), $responses, $event); /// Process each question in turn $success = true; $attempt = $attemptobj->get_attempt(); foreach ($submittedquestionids as $id) { if (!isset($actions[$id])) { $actions[$id]->responses = array('' => ''); $actions[$id]->event = QUESTION_EVENTOPEN; } $actions[$id]->timestamp = $timenow; /// If a particular question was submitted, update the nexturl to go back to that question. if ($actions[$id]->event == QUESTION_EVENTSUBMIT) { $nexturl = $attemptobj->attempt_url($id); } $state = $attemptobj->get_question_state($id); if (question_process_responses($attemptobj->get_question($id), $state, $actions[$id], $attemptobj->get_quiz(), $attempt)) { save_question_session($attemptobj->get_question($id), $state); } else { $success = false; } } if (!$success) { print_error('errorprocessingresponses', 'question', $attemptobj->attempt_url(0, $page)); } /// If we do not have to finish the attempts (if we are only processing responses) /// save the attempt and redirect to the next page. if (!$finishattempt) { $attempt->timemodified = $timenow; $DB->update_record('quiz_attempts', $attempt); redirect($nexturl);
echo "<tr>"; echo "<th>Question</th>"; echo "<th>Answer</th>"; echo "<th>Score</th>"; echo "</tr>"; echo "</thead>"; echo "<tbody>"; $cnt = 0; $score = 0; // Print Quiz Attempt Review foreach ($attemptobj->get_question_ids($page) as $id) { $cnt++; $score += $attemptobj->get_question_score($id); $actual = $attemptobj->get_actual_id($id, false, $attemptobj->attempt_url($id, $page)); $question = $DB->get_record('question', array('id' => $actual)); $responses = get_question_actual_response($attemptobj->get_question($id), $attemptobj->get_question_state($id)); echo "<tr class='odd'><td colspan='3'>Question: " . $cnt . "</td></tr>"; echo "<tr>"; // Question echo "<td>" . replace_keywords($attemptid, $question->questiontext) . "</td>"; echo "<td>"; // Answer foreach ($responses as $r) { echo replace_keywords($attemptid, $r); } echo "</td>"; // Score echo "<td>" . $attemptobj->get_question_score($id) . "</td>"; echo "</tr>"; } echo "</tbody>";