diff --git a/mod/quiz/accessrules.php b/mod/quiz/accessrules.php index dd7cc9bf8b3..434ed3f652a 100644 --- a/mod/quiz/accessrules.php +++ b/mod/quiz/accessrules.php @@ -95,27 +95,6 @@ class quiz_access_manager { } } - /** - * Print each message in an array, surrounded by <p>, </p> tags. - * - * @param array $messages the array of message strings. - * @param bool $return if true, return a string, instead of outputting. - * - * @return mixed, if $return is true, return the string that would have been output, otherwise - * return null. - */ - public function print_messages($messages, $return=false) { - $output = ''; - foreach ($messages as $message) { - $output .= '

' . $message . "

\n"; - } - if ($return) { - return $output; - } else { - echo $output; - } - } - /** * Provide a description of the rules that apply to this quiz, such * as is shown at the top of the quiz view page. Note that not all diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index f685a82636f..178852ed682 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -27,8 +27,6 @@ require_once(dirname(__FILE__) . '/../../config.php'); require_once($CFG->dirroot . '/mod/quiz/locallib.php'); -$output = $PAGE->get_renderer('mod_quiz'); - // Look for old-style URLs, such as may be in the logs, and redirect them to startattemtp.php if ($id = optional_param('id', 0, PARAM_INTEGER)) { redirect($CFG->wwwroot . '/mod/quiz/startattempt.php?cmid=' . $id . '&sesskey=' . sesskey()); @@ -78,8 +76,10 @@ if ($attemptobj->is_finished()) { // Check the access rules. $accessmanager = $attemptobj->get_access_manager(time()); $messages = $accessmanager->prevent_access(); +$output = $PAGE->get_renderer('mod_quiz'); if (!$attemptobj->is_preview_user() && $messages) { - $output->print_message($attemptobj, $accessmanager, $messages); +print_error('attempterror', 'quiz', $attemptobj->view_url(), + $output->print_messages($messages)); } $accessmanager->do_password_check($attemptobj->is_preview_user()); diff --git a/mod/quiz/renderer.php b/mod/quiz/renderer.php index 148573df93a..7843beb8b1a 100644 --- a/mod/quiz/renderer.php +++ b/mod/quiz/renderer.php @@ -62,8 +62,8 @@ class mod_quiz_renderer extends plugin_renderer_base { } 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 ''; } @@ -97,7 +97,7 @@ class mod_quiz_renderer extends plugin_renderer_base { } public function questions(quiz_attempt $attemptobj, $reviewing, $slots, $page, $showall, - mod_quiz_display_options $displayoptions) { + mod_quiz_display_options $displayoptions) { $output = ''; foreach ($slots as $slot) { $output .= $attemptobj->render_question($slot, $reviewing, @@ -116,15 +116,18 @@ class mod_quiz_renderer extends plugin_renderer_base { // TODO fix this to use html_writer. $output = ''; - $output .= '
'; - $output .= ''; - $output .= $content; - $output .= '
' . "\n" . - '' . - "
\n" . - "\n
\n"; + $output .= html_writer::start_tag('form', array('action' => $attemptobj->review_url(0, + $page, $showall), 'method' => 'post', 'class' => 'questionflagsaveform')); + $output .= html_writer::start_tag('div'); + $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', + 'value' => sesskey())); + $output .= html_writer::start_tag('div', array('class' => 'submitbtns')); + $output .= html_writer::empty_tag('input', array('type' => 'submit', + 'class' => 'questionflagsavebutton', 'name' => 'savingflags', + 'value' => get_string('saveflags', 'question'))); + $output .= html_writer::eng_tag('div'); + $output .= html_writer::eng_tag('div'); + $output .= html_writer::eng_tag('form'); return $output; } @@ -229,8 +232,7 @@ class mod_quiz_renderer extends plugin_renderer_base { } protected function render_mod_quiz_links_to_other_attempts( - mod_quiz_links_to_other_attempts - $links) { + mod_quiz_links_to_other_attempts $links) { $attemptlinks = array(); foreach ($links->links as $attempt => $url) { if ($url) { @@ -246,33 +248,29 @@ class mod_quiz_renderer extends plugin_renderer_base { * Attempt Page */ public function attempt_page($attemptobj, $page, $accessmanager, $messages, $slots, $id, - $nextpage) { + $nextpage) { $output = ''; - $output .= $this->quiz_notices($attemptobj, $accessmanager, $messages); + $output .= $this->quiz_notices($messages); $output .= $this->attempt_form($attemptobj, $page, $slots, $id, $nextpage); return $output; } - 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. - $output = $this->box_start('quizaccessnotices'); - $output .= $this->heading(get_string('accessnoticesheader', 'quiz'), 3); - $accessmanager->print_messages($messages); - $output .= $this->box_end(); - - return $output; + private function quiz_notices($messages) { + if (!$messages) { + return ''; } + return $this->box($this->heading(get_string('accessnoticesheader', 'quiz'), 3) . + $this->access_messages($messages), 'quizaccessnotices'); } private function attempt_form($attemptobj, $page, $slots, $id, $nextpage) { // Start the form //TODO: Convert all html to html:writer $output = ''; - $output .= '
'. "\n"; - $output .= '
'; + + //Start Form + $output .= html_writer::start_tag('form', array('action' => s($attemptobj->processattempt_url()), 'method' => 'post', 'enctype' => 'multipart/form-data', 'accept-charset' => 'utf-8', 'id' => 'responseform')); + $output .= html_writer::start_tag('div'); // Print all the questions foreach ($slots as $slot) { @@ -280,37 +278,45 @@ class mod_quiz_renderer extends plugin_renderer_base { $page)); } - // Print a link to the next page. - $output .= '
'; - $output .= ''; - $output .= "
"; + $output .= html_writer::start_tag('div', array('class' => 'submitbtns')); + $output .= html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'next', 'value' => get_string('next'))); + $output .= html_writer::end_tag('div'); // Some hidden fields to trach what is going on. - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; + $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'attempt', 'value' => $attemptobj->get_attemptid())); + $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'thispage', 'value' => $page, 'id' => 'followingpage')); + $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'nextpage', 'value' => $nextpage)); + $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'timeup', 'value' => '0', 'id' => 'timeup')); + $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())); + $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'scrollpos', 'value' => '', 'id' => 'scrollpos')); // 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. - $output .= '\n"; - - // Finish the form - $output .= '
'; - $output .= "
\n"; + $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'slots', 'value' => implode(',', $slots))); + + //Finish form + $output .= html_writer::end_tag('div'); + $output .= html_writer::end_tag('form'); return $output; } - public function print_message($attemptobj, $accessmanager, $messages) { - print_error('attempterror', 'quiz', $attemptobj->view_url(), - $accessmanager->print_messages($messages, true)); + /** + * Print each message in an array, surrounded by <p>, </p> tags. + * + * @param array $messages the array of message strings. + * @param bool $return if true, return a string, instead of outputting. + * + * @return mixed, if $return is true, return the string that would have been output, otherwise + * return null. + */ + public function print_messages($messages) { + $output = ''; + foreach ($messages as $message) { + $output .= html_writer::tag('p', $message) . "\n"; + } + return $output; } } diff --git a/mod/quiz/startattempt.php b/mod/quiz/startattempt.php index 58bfbd1af79..110e6db0c66 100644 --- a/mod/quiz/startattempt.php +++ b/mod/quiz/startattempt.php @@ -97,10 +97,11 @@ if ($lastattempt && !$lastattempt->preview && !$quizobj->is_preview_user()) { // Check access. $messages = $accessmanager->prevent_access() + - $accessmanager->prevent_new_attempt($attemptnumber - 1, $lastattempt); +$accessmanager->prevent_new_attempt($attemptnumber - 1, $lastattempt); +$output = $PAGE->get_renderer('mod_quiz'); if (!$quizobj->is_preview_user() && $messages) { print_error('attempterror', 'quiz', $quizobj->view_url(), - $accessmanager->print_messages($messages, true)); + $output->print_messages($messages)); } $accessmanager->do_password_check($quizobj->is_preview_user()); diff --git a/mod/quiz/summary.php b/mod/quiz/summary.php index daa5b7374ed..b479f1ba371 100644 --- a/mod/quiz/summary.php +++ b/mod/quiz/summary.php @@ -59,9 +59,10 @@ if ($attemptobj->is_preview_user()) { // Check access. $accessmanager = $attemptobj->get_access_manager(time()); $messages = $accessmanager->prevent_access(); +$output = $PAGE->get_renderer('mod_quiz'); if (!$attemptobj->is_preview_user() && $messages) { print_error('attempterror', 'quiz', $attemptobj->view_url(), - $accessmanager->print_messages($messages, true)); + $output->print_messages($messages)); } $accessmanager->do_password_check($attemptobj->is_preview_user()); diff --git a/mod/quiz/view.php b/mod/quiz/view.php index 25223d1daf2..48bad64fc85 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -85,6 +85,7 @@ if ($edit != -1 && $PAGE->user_allowed_editing()) { $title = $course->shortname . ': ' . format_string($quiz->name); $PAGE->set_title($title); $PAGE->set_heading($course->fullname); +$output = $PAGE->get_renderer('mod_quiz'); echo $OUTPUT->header(); // Print quiz name and description @@ -100,7 +101,7 @@ if ($quiz->attempts != 1) { quiz_get_grading_option_name($quiz->grademethod)); } echo $OUTPUT->box_start('quizinfo'); -$accessmanager->print_messages($messages); +$output->print_messages($messages); echo $OUTPUT->box_end(); // Show number of attempts summary to those who can view reports. @@ -367,7 +368,7 @@ if (!quiz_clean_layout($quiz->questions, true)) { if ($canattempt) { $messages = $accessmanager->prevent_new_attempt($numattempts, $lastfinishedattempt); if ($messages) { - $accessmanager->print_messages($messages); + $output->print_messages($messages); } else if ($numattempts == 0) { $buttontext = get_string('attemptquiznow', 'quiz'); } else { @@ -385,7 +386,7 @@ if (!quiz_clean_layout($quiz->questions, true)) { if (!$moreattempts) { $buttontext = ''; } else if ($canattempt && $messages = $accessmanager->prevent_access()) { - $accessmanager->print_messages($messages); + $output->print_messages($messages); $buttontext = ''; } }