diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index 4375498aab3..9cd4e0e286c 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -22,6 +22,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +use mod_quiz\output\navigation_panel_attempt; +use mod_quiz\output\renderer; + require_once(__DIR__ . '/../../config.php'); require_once($CFG->dirroot . '/mod/quiz/locallib.php'); @@ -82,6 +85,7 @@ if ($attemptobj->is_finished()) { // Check the access rules. $accessmanager = $attemptobj->get_access_manager(time()); $accessmanager->setup_attempt_page($PAGE); +/** @var renderer $output */ $output = $PAGE->get_renderer('mod_quiz'); $messages = $accessmanager->prevent_access(); if (!$attemptobj->is_preview_user() && $messages) { @@ -121,7 +125,7 @@ $PAGE->requires->js_init_call('M.mod_quiz.init_attempt_form', null, false, quiz_ \core\session\manager::keepalive(); // Try to prevent sessions expiring during quiz attempts. // Arrange for the navigation to be displayed in the first region on the page. -$navbc = $attemptobj->get_navigation_panel($output, 'quiz_attempt_nav_panel', $page); +$navbc = $attemptobj->get_navigation_panel($output, navigation_panel_attempt::class, $page); $regions = $PAGE->blocks->get_regions(); $PAGE->blocks->add_fake_block($navbc, reset($regions)); diff --git a/mod/quiz/attemptlib.php b/mod/quiz/attemptlib.php index b207e98d3a5..12ce2c69223 100644 --- a/mod/quiz/attemptlib.php +++ b/mod/quiz/attemptlib.php @@ -30,8 +30,6 @@ defined('MOODLE_INTERNAL') || die(); use mod_quiz\access_manager; use mod_quiz\output\links_to_other_attempts; use mod_quiz\output\navigation_panel_base; -use mod_quiz\output\navigation_question_button; -use mod_quiz\output\navigation_section_heading; use mod_quiz\output\renderer; use mod_quiz\question\bank\qbank_helper; use mod_quiz\question\display_options; @@ -1872,7 +1870,7 @@ class quiz_attempt { * Get the navigation panel object for this attempt. * * @param renderer $output the quiz renderer to use to output things. - * @param string $panelclass The type of panel, quiz_attempt_nav_panel or quiz_review_nav_panel + * @param string $panelclass The type of panel, navigation_panel_attempt::class or quiz_review_nav_panel * @param int $page the current page number. * @param bool $showall whether we are showing the whole quiz on one page. (Used by review.php.) * @return block_contents the requested object. @@ -2714,39 +2712,6 @@ class quiz_attempt { } -/** - * Specialisation of {@see navigation_panel_base} for the attempt quiz page. - * - * @copyright 2008 Tim Hunt - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since Moodle 2.0 - */ -class quiz_attempt_nav_panel extends navigation_panel_base { - public function get_question_url($slot) { - if ($this->attemptobj->can_navigate_to($slot)) { - return $this->attemptobj->attempt_url($slot, -1, $this->page); - } else { - return null; - } - } - - public function render_before_button_bits(renderer $output) { - return html_writer::tag('div', get_string('navnojswarning', 'quiz'), - array('id' => 'quiznojswarning')); - } - - public function render_end_bits(renderer $output) { - if ($this->page == -1) { - // Don't link from the summary page to itself. - return ''; - } - return html_writer::link($this->attemptobj->summary_url(), - get_string('endtest', 'quiz'), array('class' => 'endtestlink aalink')) . - $this->render_restart_preview_link($output); - } -} - - /** * Specialisation of {@see navigation_panel_base} for the review quiz page. * diff --git a/mod/quiz/classes/output/navigation_panel_attempt.php b/mod/quiz/classes/output/navigation_panel_attempt.php new file mode 100644 index 00000000000..1fd6fbfc80a --- /dev/null +++ b/mod/quiz/classes/output/navigation_panel_attempt.php @@ -0,0 +1,55 @@ +. + +namespace mod_quiz\output; + +use html_writer; + +/** + * Specialisation of {@see navigation_panel_base} for the attempt quiz page. + * + * This class is not currently renderable or templatable, but it probably should be in the future, + * which is why it is already in the output namespace. + * + * @package mod_quiz + * @category output + * @copyright 2008 Tim Hunt + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class navigation_panel_attempt extends navigation_panel_base { + public function get_question_url($slot) { + if ($this->attemptobj->can_navigate_to($slot)) { + return $this->attemptobj->attempt_url($slot, -1, $this->page); + } else { + return null; + } + } + + public function render_before_button_bits(renderer $output) { + return html_writer::tag('div', get_string('navnojswarning', 'quiz'), + array('id' => 'quiznojswarning')); + } + + public function render_end_bits(renderer $output) { + if ($this->page == -1) { + // Don't link from the summary page to itself. + return ''; + } + return html_writer::link($this->attemptobj->summary_url(), + get_string('endtest', 'quiz'), array('class' => 'endtestlink aalink')) . + $this->render_restart_preview_link($output); + } +} diff --git a/mod/quiz/db/renamedclasses.php b/mod/quiz/db/renamedclasses.php index c2d3605782d..1e79ecdead5 100644 --- a/mod/quiz/db/renamedclasses.php +++ b/mod/quiz/db/renamedclasses.php @@ -62,4 +62,5 @@ $renamedclasses = [ 'quiz_nav_question_button' => 'mod_quiz\output\navigation_question_button', 'quiz_nav_section_heading' => 'mod_quiz\output\navigation_section_heading', 'quiz_nav_panel_base' => 'mod_quiz\output\navigation_panel_base', + 'quiz_attempt_nav_panel' => 'mod_quiz\output\navigation_panel_attempt', ]; diff --git a/mod/quiz/summary.php b/mod/quiz/summary.php index dc429195f8d..f3c22ac05df 100644 --- a/mod/quiz/summary.php +++ b/mod/quiz/summary.php @@ -22,6 +22,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +use mod_quiz\output\navigation_panel_attempt; +use mod_quiz\output\renderer; require_once(__DIR__ . '/../../config.php'); require_once($CFG->dirroot . '/mod/quiz/locallib.php'); @@ -60,6 +62,7 @@ if ($attemptobj->is_preview_user()) { // Check access. $accessmanager = $attemptobj->get_access_manager(time()); $accessmanager->setup_attempt_page($PAGE); +/** @var renderer $output */ $output = $PAGE->get_renderer('mod_quiz'); $messages = $accessmanager->prevent_access(); if (!$attemptobj->is_preview_user() && $messages) { @@ -87,7 +90,7 @@ if (empty($attemptobj->get_quiz()->showblocks)) { $PAGE->blocks->show_only_fake_blocks(); } -$navbc = $attemptobj->get_navigation_panel($output, 'quiz_attempt_nav_panel', -1); +$navbc = $attemptobj->get_navigation_panel($output, navigation_panel_attempt::class, -1); $regions = $PAGE->blocks->get_regions(); $PAGE->blocks->add_fake_block($navbc, reset($regions)); diff --git a/mod/quiz/upgrade.txt b/mod/quiz/upgrade.txt index c1cb5192b3c..cee3520cabc 100644 --- a/mod/quiz/upgrade.txt +++ b/mod/quiz/upgrade.txt @@ -46,6 +46,7 @@ This files describes API changes in the quiz code. - quiz_nav_question_button => mod_quiz\output\navigation_question_button - quiz_nav_section_heading => mod_quiz\output\navigation_section_heading - quiz_nav_panel_base => mod_quiz\output\navigation_panel_base + - quiz_attempt_nav_panel => mod_quiz\output\navigation_panel_attempt * The following classes have been deprecated: - mod_quiz_overdue_attempt_updater - merged into mod_quiz\task\update_overdue_attempts