$attemptobj = new quiz_attempt($attemptid);
+/// Because IE is buggy (see http://www.peterbe.com/plog/button-tag-in-IE) we cannot
+/// do the quiz navigation buttons as <button type="submit" name="page" value="N">Caption</button>.
+/// Instead we have to do them as <input type="submit" name="gotopageN" value="Caption"/> -
+/// at lest that seemed like the least horrible work-around to me. Therefore, we need to
+/// intercept gotopageN parameters here, and adjust $pgae accordingly.
+ if (optional_param('gotosummary', false, PARAM_BOOL)) {
+ $page = -1;
+ } else {
+ $numpagesinquiz = $attemptobj->get_num_pages();
+ for ($i = 0; $i < $numpagesinquiz; $i++) {
+ if (optional_param('gotopage' . $i, false, PARAM_BOOL)) {
+ $page = $i;
+ break;
+ }
+ }
+ }
+
/// We treat automatically closed attempts just like normally closed attempts
if ($timeup) {
$finishattempt = 1;
}
echo '<div>';
-/// Print the navigation panel if required
- // TODO!!!
- quiz_print_navigation_panel($page, $attemptobj->get_num_pages());
+/// Print the navigation panel in a left column.
+ print_container_start();
+ echo '<div id="left-column">';
+ $attemptobj->print_navigation_panel('quiz_attempt_nav_panel', $page);
+ echo '</div>';
+ print_container_end();
+
+/// Start the main column.
+ echo '<div id="middle-column">';
+ print_container_start();
+ echo skip_main_destination();
/// Print all the questions
foreach ($attemptobj->get_question_ids($page) as $id) {
}
/// Print a link to the next page.
- echo "<div class=\"submitbtns mdl-align\">\n";
+ echo '<div class="submitbtns">';
if ($attemptobj->is_last_page($page)) {
- $nextpage = -1;
+ $nextpage = 'gotosummary';
} else {
- $nextpage = $page + 1;
+ $nextpage = 'gotopage' . ($page + 1);
}
- echo link_arrow_right(get_string('next'), 'javascript:navigate(' . $nextpage . ')');
+ echo '<input type="submit" name="' . $nextpage . '" value="' . get_string('next') . '" />';
echo "</div>";
// Finish the form
echo "</form>\n";
+ // End middle column.
+ print_container_end();
+ echo '</div>';
+
+ echo '</div>';
+ echo '<div class="clearer"></div>';
+
// Finish the page
$accessmanager->show_attempt_timer_if_needed($attemptobj->get_attempt(), time());
if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) {
* @return object the question object with that id.
*/
public function get_question($id) {
- $this->ensure_question_loaded($id);
return $this->questions[$id];
}
*/
public function attempt_url($attemptid) {
global $CFG;
- return $CFG->wwwroot . '/mod/quiz/attempt.php?attempt=' . $attemptid . '&page=0';
+ return $CFG->wwwroot . '/mod/quiz/attempt.php?attempt=' . $attemptid;
}
/**
*/
public function attempt_url($questionid = 0, $page = -1) {
global $CFG;
- return $CFG->wwwroot . '/mod/quiz/attempt.php?attempt=' . $this->attempt->id . '&' .
+ return $CFG->wwwroot . '/mod/quiz/attempt.php?attempt=' . $this->attempt->id .
$this->page_and_question_fragment($questionid, $page);
}
if (is_null($otherattemptid)) {
$otherattemptid = $this->attempt->id;
}
- return $CFG->wwwroot . '/mod/quiz/review.php?attempt=' . $otherattemptid . '&' .
+ return $CFG->wwwroot . '/mod/quiz/review.php?attempt=' . $otherattemptid .
$this->page_and_question_fragment($questionid, $page, $showall);
}
quiz_send_notification_emails($this->course, $this->quiz, $this->attempt,
$this->context, $this->cm);
}
-
+
+ public function print_navigation_panel($panelclass, $page) {
+ $panel = new quiz_attempt_nav_panel($this, $this->get_review_options(), $page);
+ $panel->display();
+ }
// Private methods =====================================================================
// Check that the state of a particular question is loaded, and if not throw an exception.
* @return string bit to add to the end of a URL.
*/
private function page_and_question_fragment($questionid, $page, $showall = false) {
- if ($page = -1) {
+ if ($page == -1) {
if ($questionid) {
$page = $this->questions[$questionid]->_page;
} else {
}
$param = '';
if ($showall) {
- $param = 'showall=1';
- } else if (/*$page > 1*/ true) {
- // TODO currently needed by the navigate JS, but clean this up later.
- $param = 'page=' . $page;
+ $param = '&showall=1';
+ } else if ($page > 0) {
+ $param = '&page=' . $page;
}
return $param . $fragment;
}
return $this->current() !== false;
}
}
+
+abstract class quiz_nav_panel_base {
+ protected $attemptobj;
+ protected $options;
+ protected $page;
+
+ protected function __construct(quiz_attempt $attemptobj, $options, $page) {
+ $this->attemptobj = $attemptobj;
+ $this->options = $options;
+ $this->page = $page;
+ }
+
+ protected function get_question_buttons() {
+ $html = '<div class="qn_buttons">';
+ foreach ($this->attemptobj->get_question_iterator() as $number => $question) {
+ $html .= $this->get_question_button($number, $question);
+ }
+ $html .= '</div>';
+ return $html;
+ }
+
+ abstract protected function get_question_button($number, $question);
+
+ abstract protected function get_end_bits();
+
+ protected function get_question_state($question) {
+ $state = 'todo'; // TODO
+ if ($question->_page == $this->page) {
+ $state .= ' thispage';
+ }
+ return $state;
+ }
+
+ public function display() {
+ $strquiznavigation = get_string('quiznavigation', 'quiz');
+ $content = $this->get_question_buttons() . $this->get_end_bits();
+ print_side_block($strquiznavigation, $content, NULL, NULL, '', array('id' => 'quiznavigation'), $strquiznavigation);
+ }
+}
+
+class quiz_attempt_nav_panel extends quiz_nav_panel_base {
+ public function __construct(quiz_attempt $attemptobj, $options, $page) {
+ parent::__construct($attemptobj, $options, $page);
+ }
+
+ protected function get_question_button($number, $question) {
+ $questionsonpage = $this->attemptobj->get_question_ids($question->_page);
+ $onclick = '';
+ if ($question->id != reset($questionsonpage)) {
+ $onclick = ' onclick="form.action = form.action + \'#q' . $question->id .
+ '\'; return true;"';
+ }
+ return '<input type="submit" name="gotopage' . $question->_page .
+ '" value="' . $number . '" class="qnbutton ' .
+ $this->get_question_state($question) . '"' . $onclick . '/>';
+ }
+
+ protected function get_end_bits() {
+ return '<input type="submit" name="gotosummary" value="' .
+ get_string('endtest', 'quiz') . '" class="endtestlink" />';
+ }
+}
+
+class quiz_review_nav_panel extends quiz_nav_panel_base {
+ public function __construct(quiz_attempt $attemptobj, $options, $page) {
+ parent::__construct($attemptobj, $options, $page);
+ }
+
+ protected function get_question_button($number, $question) {
+ return '<a href="' . $this->attemptobj->review_url($question->id) .
+ '" class="qnbutton ' . $this->get_question_state($question) .
+ '">' . $number . '</a>';
+ }
+
+ protected function get_end_bits() {
+ $html = '<a href="' . $this->attemptobj->review_url(0, 0, true) . '">' .
+ get_string('showall', 'quiz') . '</a>';
+ $html .= '<a href="' . $this->attemptobj->view_url() . '">' .
+ get_string('finishreview', 'quiz') . '</a>';
+ return $html;
+ }
+}
?>
\ No newline at end of file