Skip to content

Commit

Permalink
MDL-20636 Attempt as converting attempt.php over to renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Lennard authored and timhunt committed May 9, 2011
1 parent b3782c7 commit 606e07d
Showing 2 changed files with 96 additions and 68 deletions.
69 changes: 2 additions & 67 deletions mod/quiz/attempt.php
Original file line number Diff line number Diff line change
@@ -103,71 +103,6 @@
$firstregion = reset($PAGE->blocks->get_regions());
$PAGE->blocks->add_fake_block($navbc, $firstregion);

// Print the page header
$title = get_string('attempt', 'quiz', $attemptobj->get_attempt_number());
$headtags = $attemptobj->get_html_head_contributions($page);
$PAGE->set_heading($attemptobj->get_course()->fullname);
if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) {
$accessmanager->setup_secure_page($attemptobj->get_course()->shortname . ': ' .
format_string($attemptobj->get_quiz_name()));

} else if ($accessmanager->safebrowser_required($attemptobj->is_preview_user())) {
$PAGE->set_title($attemptobj->get_course()->shortname . ': ' .
format_string($attemptobj->get_quiz_name()));
$PAGE->set_cacheable(false);
echo $OUTPUT->header();

} else {
$PAGE->set_title(format_string($attemptobj->get_quiz_name()));
echo $OUTPUT->header();
}

if ($attemptobj->is_preview_user() && $messages) {
// Inform teachers of any restrictions that would apply to students at this point.
echo $OUTPUT->box_start('quizaccessnotices');
echo $OUTPUT->heading(get_string('accessnoticesheader', 'quiz'), 3);
$accessmanager->print_messages($messages);
echo $OUTPUT->box_end();
}

// Start the form
echo '<form id="responseform" method="post" action="', s($attemptobj->processattempt_url()),
'" enctype="multipart/form-data" accept-charset="utf-8">', "\n";
echo '<div>';

// Print all the questions
foreach ($slots as $slot) {
echo $attemptobj->render_question($slot, false, $attemptobj->attempt_url($id, $page));
}
$output = $PAGE->get_renderer('mod_quiz');

// Print a link to the next page.
echo '<div class="submitbtns">';
if ($attemptobj->is_last_page($page)) {
$nextpage = -1;
} else {
$nextpage = $page + 1;
}
echo '<input type="submit" name="next" value="' . get_string('next') . '" />';
echo "</div>";

// Some hidden fields to trach what is going on.
echo '<input type="hidden" name="attempt" value="' . $attemptobj->get_attemptid() . '" />';
echo '<input type="hidden" name="thispage" id="followingpage" value="' . $page . '" />';
echo '<input type="hidden" name="nextpage" value="' . $nextpage . '" />';
echo '<input type="hidden" name="timeup" id="timeup" value="0" />';
echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
echo '<input type="hidden" name="scrollpos" id="scrollpos" value="" />';

// Add a hidden field with questionids. Do this at the end of the form, so
// if you navigate before the form has finished loading, it does not wipe all
// the student's answers.
echo '<input type="hidden" name="slots" value="' .
implode(',', $slots) . "\" />\n";

// Finish the form
echo '</div>';
echo "</form>\n";

// Finish the page
$accessmanager->show_attempt_timer_if_needed($attemptobj->get_attempt(), time());
echo $OUTPUT->footer();
$output->attempt_page($attemptobj, $page, $accessmanager, $messages, $slots, $id);
95 changes: 94 additions & 1 deletion mod/quiz/renderer.php
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@
*/
class mod_quiz_renderer extends plugin_renderer_base {
public function review_page(quiz_attempt $attemptobj, $slots, $page, $showall,
$lastpage, mod_quiz_display_options $displayoptions, $summarydata) {
$lastpage, mod_quiz_display_options $displayoptions, $summarydata) {

$output = '';
$output .= $this->header();
@@ -237,6 +237,99 @@ protected function render_mod_quiz_links_to_other_attempts(
}
return implode(', ', $attemptlinks);
}

/*
* Attempt Page
*/
public function attempt_page($attemptobj, $page, $accessmanager, $messages, $slots, $id){
$output = '';
$output .= $this->attempt_header($attemptobj, $page, $accessmanager);
$output .= $this->quiz_notices($attemptobj, $accessmanager, $messages);
$output .= $this->attempt_form($attemptobj, $page, $slots, $id);
$output .= $this->attempt_footer($attemptobj, $accessmanager);
return $output;
}

protected function attempt_header($attemptobj, $page, $accessmanager){
global $PAGE, $OUTPUT;

$title = get_string('attempt', 'quiz', $attemptobj->get_attempt_number());
$headtags = $attemptobj->get_html_head_contributions($page);
$PAGE->set_heading($attemptobj->get_course()->fullname);
if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) {
$accessmanager->setup_secure_page($attemptobj->get_course()->shortname . ': ' .
format_string($attemptobj->get_quiz_name()));

} else if ($accessmanager->safebrowser_required($attemptobj->is_preview_user())) {
$PAGE->set_title($attemptobj->get_course()->shortname . ': ' .
format_string($attemptobj->get_quiz_name()));
$PAGE->set_cacheable(false);
echo $OUTPUT->header();

} else {
$PAGE->set_title(format_string($attemptobj->get_quiz_name()));
echo $OUTPUT->header();
}
}


private function quiz_notices($attemptobj, $accessmanager, $messages){
if ($attemptobj->is_preview_user() && $messages) {
// Inform teachers of any restrictions that would apply to students at this point.
echo $OUTPUT->box_start('quizaccessnotices');
echo $OUTPUT->heading(get_string('accessnoticesheader', 'quiz'), 3);
$accessmanager->print_messages($messages);
echo $OUTPUT->box_end();
}
}

private function attempt_form($attemptobj, $page, $slots, $id){
// Start the form
//TODO: Convert all html to html:writer
echo '<form id="responseform" method="post" action="', s($attemptobj->processattempt_url()),
'" enctype="multipart/form-data" accept-charset="utf-8">', "\n";
echo '<div>';

// Print all the questions
foreach ($slots as $slot) {
echo $attemptobj->render_question($slot, false, $attemptobj->attempt_url($id, $page));
}

// Print a link to the next page.
echo '<div class="submitbtns">';
if ($attemptobj->is_last_page($page)) {
$nextpage = -1;
} else {
$nextpage = $page + 1;
}
echo '<input type="submit" name="next" value="' . get_string('next') . '" />';
echo "</div>";

// Some hidden fields to trach what is going on.
echo '<input type="hidden" name="attempt" value="' . $attemptobj->get_attemptid() . '" />';
echo '<input type="hidden" name="thispage" id="followingpage" value="' . $page . '" />';
echo '<input type="hidden" name="nextpage" value="' . $nextpage . '" />';
echo '<input type="hidden" name="timeup" id="timeup" value="0" />';
echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
echo '<input type="hidden" name="scrollpos" id="scrollpos" value="" />';

// Add a hidden field with questionids. Do this at the end of the form, so
// if you navigate before the form has finished loading, it does not wipe all
// the student's answers.
echo '<input type="hidden" name="slots" value="' .
implode(',', $slots) . "\" />\n";

// Finish the form
echo '</div>';
echo "</form>\n";
}

protected function attempt_footer($attemptobj, $accessmanager){
global $OUTPUT;

$accessmanager->show_attempt_timer_if_needed($attemptobj->get_attempt(), time());
echo $OUTPUT->footer();
}
}


0 comments on commit 606e07d

Please sign in to comment.