Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'MDL-27902' of git://github.com/timhunt/moodle
  • Loading branch information
stronk7 committed Jun 19, 2011
2 parents f263d49 + 3a5da40 commit b941266
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 39 deletions.
46 changes: 44 additions & 2 deletions mod/quiz/renderer.php
Expand Up @@ -59,6 +59,49 @@ public function review_page(quiz_attempt $attemptobj, $slots, $page, $showall,
return $output;
}

/**
* Renders the review question pop-up.
*
* @param quiz_attempt $attemptobj an instance of quiz_attempt.
* @param int $slot which question to display.
* @param int $seq which step of the question attempt to show. null = latest.
* @param mod_quiz_display_options $displayoptions instance of mod_quiz_display_options.
* @param array $summarydata contains all table data
* @return $output containing html data.
*/
public function review_question_page(quiz_attempt $attemptobj, $slot, $seq,
mod_quiz_display_options $displayoptions, $summarydata) {

$output = '';
$output .= $this->header();
$output .= $this->review_summary_table($summarydata, 0);

if (!is_null($seq)) {
$output .= $attemptobj->render_question_at_step($slot, $seq, true, $this->page->url);
} else {
$output .= $attemptobj->render_question($slot, true, $this->page->url);
}

$output .= $this->close_window_button();
$output .= $this->footer();
return $output;
}

/**
* Renders the review question pop-up.
*
* @param string $message Why the review is not allowed.
* @return string html to output.
*/
public function review_question_not_allowed($message) {
$output = '';
$output .= $this->header();
$output .= $this->notification($message);
$output .= $this->close_window_button();
$output .= $this->footer();
return $output;
}

/**
* Filters the summarydata array.
*
Expand Down Expand Up @@ -88,8 +131,7 @@ protected function filter_summary_table($summarydata, $page) {
* @param int $page contains the current page number
*/
public function review_summary_table($summarydata, $page) {
$summarydata = $this->filter_summary_table($summarydata,
$page);
$summarydata = $this->filter_summary_table($summarydata, $page);
if (empty($summarydata)) {
return '';
}
Expand Down
4 changes: 1 addition & 3 deletions mod/quiz/review.php
Expand Up @@ -135,9 +135,7 @@
$timetaken = get_string('unfinished', 'quiz');
}

// Print summary table about the whole attempt.
// First we assemble all the rows that are appopriate to the current situation in
// an array, then later we only output the table if there are any rows to show.
// Prepare summary informat about the whole attempt.
$summarydata = array();
if (!$attemptobj->get_quiz()->showuserpicture && $attemptobj->get_userid() != $USER->id) {
// If showuserpicture is true, the picture is shown elsewhere, so don't repeat it.
Expand Down
60 changes: 26 additions & 34 deletions mod/quiz/reviewquestion.php
Expand Up @@ -39,74 +39,66 @@
$currenturl->param('step', $seq);
}
$PAGE->set_url($currenturl);
$PAGE->set_pagelayout('popup');

$attemptobj = quiz_attempt::create($attemptid);

// Check login.
require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm());
$attemptobj->check_review_capability();

echo $OUTPUT->header();
$PAGE->set_pagelayout('popup');
$output = $PAGE->get_renderer('mod_quiz');

// Check permissions.
if ($attemptobj->is_own_attempt()) {
if (!$attemptobj->is_finished()) {
echo $OUTPUT->notification(get_string('cannotreviewopen', 'quiz'));
echo $OUTPUT->close_window_button();
echo $OUTPUT->footer();
echo $output->review_question_not_allowed(get_string('cannotreviewopen', 'quiz'));
die();
} else if (!$options->responses) {
$accessmanager = $attemptobj->get_access_manager(time());
echo $OUTPUT->notification($accessmanager->cannot_review_message(
$attemptobj->get_review_options()));
echo $OUTPUT->close_window_button();
echo $OUTPUT->footer();
echo $output->review_question_not_allowed(
$accessmanager->cannot_review_message($attemptobj->get_review_options()));
die();
}

} else if (!$attemptobj->is_review_allowed()) {
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noreviewattempt');
}

// Prepare summary informat about this question attempt.
$summarydata = array();

// 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>';
$summarydata['quizname'] = array(
'title' => get_string('modulename', 'quiz'),
'content' => format_string($attemptobj->get_quiz_name()),
);

// Question name.
$rows[] = '<tr><th scope="row" class="cell">' . get_string('question', 'quiz') .
'</th><td class="cell">' . format_string(
$attemptobj->get_question_name($slot)) . '</td></tr>';
$summarydata['questionname'] = array(
'title' => get_string('question', 'quiz'),
'content' => $attemptobj->get_question_name($slot),
);

// 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>';
$summarydata['attemptlist'] = array(
'title' => get_string('attempts', 'quiz'),
'content' => $attemptlist,
);
}
}

// Timestamp of this action.
$timestamp = $attemptobj->get_question_action_time($slot);
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 (!is_null($seq)) {
echo $attemptobj->render_question_at_step($slot, $seq, true, $currenturl);
} else {
echo $attemptobj->render_question($slot, true, $currenturl);
$summarydata['timestamp'] = array(
'title' => get_string('completedon', 'quiz'),
'content' => userdate($timestamp),
);
}

// Finish the page
echo $OUTPUT->footer();
echo $output->review_question_page($attemptobj, $slot, $seq,
$attemptobj->get_display_options(true), $summarydata);

0 comments on commit b941266

Please sign in to comment.