From 2e4e8d16c77fb88293ae289c6f750c0ffd06d6f4 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 13 Jan 2015 13:55:33 +0000 Subject: [PATCH] MDL-48829 quiz nav: add a data attr to buttons giving the page This way, if you need to know which page each button goes to in JavaScript, you can find out. --- mod/quiz/attemptlib.php | 12 +++++++++++- mod/quiz/renderer.php | 10 +++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/mod/quiz/attemptlib.php b/mod/quiz/attemptlib.php index fe7044a25e5..3c2fa1a7aac 100644 --- a/mod/quiz/attemptlib.php +++ b/mod/quiz/attemptlib.php @@ -1683,12 +1683,21 @@ class quiz_attempt { * @since Moodle 2.1 */ class quiz_nav_question_button implements renderable { + /** @var string id="..." to add to the HTML for this button. */ public $id; + /** @var string number to display in this button. Either the question number of 'i'. */ public $number; + /** @var string class to add to the class="" attribute to represnt the question state. */ public $stateclass; + /** @var string Textual description of the question state, e.g. to use as a tool tip. */ public $statestring; + /** @var int the page number this question is on. */ + public $page; + /** @var bool true if this question is on the current page. */ public $currentpage; + /** @var bool true if this question has been flagged. */ public $flagged; + /** @var moodle_url the link this button goes to, or null if there should not be a link. */ public $url; } @@ -1734,7 +1743,8 @@ abstract class quiz_nav_panel_base { $button->stateclass = 'complete'; } $button->statestring = $this->get_state_string($qa, $showcorrectness); - $button->currentpage = $this->showall || $this->attemptobj->get_question_page($slot) == $this->page; + $button->page = $this->attemptobj->get_question_page($slot); + $button->currentpage = $this->showall || $button->page == $this->page; $button->flagged = $qa->is_flagged(); $button->url = $this->get_question_url($slot); $buttons[] = $button; diff --git a/mod/quiz/renderer.php b/mod/quiz/renderer.php index 4c9a1c0a028..9b746718655 100644 --- a/mod/quiz/renderer.php +++ b/mod/quiz/renderer.php @@ -335,11 +335,11 @@ class mod_quiz_renderer extends plugin_renderer_base { */ protected function render_quiz_nav_question_button(quiz_nav_question_button $button) { $classes = array('qnbutton', $button->stateclass, $button->navmethod); - $attributes = array(); + $extrainfo = array(); if ($button->currentpage) { $classes[] = 'thispage'; - $attributes[] = get_string('onthispage', 'quiz'); + $extrainfo[] = get_string('onthispage', 'quiz'); } // Flagged? @@ -349,7 +349,7 @@ class mod_quiz_renderer extends plugin_renderer_base { } else { $flaglabel = ''; } - $attributes[] = html_writer::tag('span', $flaglabel, array('class' => 'flagstate')); + $extrainfo[] = html_writer::tag('span', $flaglabel, array('class' => 'flagstate')); if (is_numeric($button->number)) { $qnostring = 'questionnonav'; @@ -359,12 +359,12 @@ class mod_quiz_renderer extends plugin_renderer_base { $a = new stdClass(); $a->number = $button->number; - $a->attributes = implode(' ', $attributes); + $a->attributes = implode(' ', $extrainfo); $tagcontents = html_writer::tag('span', '', array('class' => 'thispageholder')) . html_writer::tag('span', '', array('class' => 'trafficlight')) . get_string($qnostring, 'quiz', $a); $tagattributes = array('class' => implode(' ', $classes), 'id' => $button->id, - 'title' => $button->statestring); + 'title' => $button->statestring, 'data-quiz-page' => $button->page); if ($button->url) { return html_writer::link($button->url, $tagcontents, $tagattributes);