From 03116995d5b04bab9730c86ea909d6ec6e5a7168 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Mon, 19 Dec 2022 20:25:32 +0000 Subject: [PATCH] MDL-76614 quiz: move quiz_review_nav_panel to classes --- mod/quiz/attemptlib.php | 32 +----------- .../output/navigation_panel_review.php | 52 +++++++++++++++++++ mod/quiz/db/renamedclasses.php | 1 + mod/quiz/review.php | 5 +- mod/quiz/upgrade.txt | 1 + 5 files changed, 59 insertions(+), 32 deletions(-) create mode 100644 mod/quiz/classes/output/navigation_panel_review.php diff --git a/mod/quiz/attemptlib.php b/mod/quiz/attemptlib.php index 12ce2c69223..9e9ae61f595 100644 --- a/mod/quiz/attemptlib.php +++ b/mod/quiz/attemptlib.php @@ -1870,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, navigation_panel_attempt::class or quiz_review_nav_panel + * @param string $panelclass The type of panel, navigation_panel_attempt::class or navigation_panel_review::class * @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. @@ -2710,33 +2710,3 @@ class quiz_attempt { return $totalunanswered; } } - - -/** - * Specialisation of {@see navigation_panel_base} for the review 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_review_nav_panel extends navigation_panel_base { - public function get_question_url($slot) { - return $this->attemptobj->review_url($slot, -1, $this->showall, $this->page); - } - - public function render_end_bits(renderer $output) { - $html = ''; - if ($this->attemptobj->get_num_pages() > 1) { - if ($this->showall) { - $html .= html_writer::link($this->attemptobj->review_url(null, 0, false), - get_string('showeachpage', 'quiz')); - } else { - $html .= html_writer::link($this->attemptobj->review_url(null, 0, true), - get_string('showall', 'quiz')); - } - } - $html .= $output->finish_review_link($this->attemptobj); - $html .= $this->render_restart_preview_link($output); - return $html; - } -} diff --git a/mod/quiz/classes/output/navigation_panel_review.php b/mod/quiz/classes/output/navigation_panel_review.php new file mode 100644 index 00000000000..d07de8e4172 --- /dev/null +++ b/mod/quiz/classes/output/navigation_panel_review.php @@ -0,0 +1,52 @@ +. + +namespace mod_quiz\output; + +use html_writer; + +/** + * Specialisation of {@see navigation_panel_base} for the review 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_review extends navigation_panel_base { + public function get_question_url($slot) { + return $this->attemptobj->review_url($slot, -1, $this->showall, $this->page); + } + + public function render_end_bits(renderer $output) { + $html = ''; + if ($this->attemptobj->get_num_pages() > 1) { + if ($this->showall) { + $html .= html_writer::link($this->attemptobj->review_url(null, 0, false), + get_string('showeachpage', 'quiz')); + } else { + $html .= html_writer::link($this->attemptobj->review_url(null, 0, true), + get_string('showall', 'quiz')); + } + } + $html .= $output->finish_review_link($this->attemptobj); + $html .= $this->render_restart_preview_link($output); + return $html; + } +} diff --git a/mod/quiz/db/renamedclasses.php b/mod/quiz/db/renamedclasses.php index 1e79ecdead5..7fac769cd1b 100644 --- a/mod/quiz/db/renamedclasses.php +++ b/mod/quiz/db/renamedclasses.php @@ -63,4 +63,5 @@ $renamedclasses = [ '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', + 'quiz_review_nav_panel' => 'mod_quiz\output\navigation_panel_review', ]; diff --git a/mod/quiz/review.php b/mod/quiz/review.php index b230b6eb590..ddb9d25fe00 100644 --- a/mod/quiz/review.php +++ b/mod/quiz/review.php @@ -25,6 +25,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +use mod_quiz\output\navigation_panel_review; +use mod_quiz\output\renderer; require_once(__DIR__ . '/../../config.php'); require_once($CFG->dirroot . '/mod/quiz/locallib.php'); @@ -254,10 +256,11 @@ if ($showall) { $lastpage = $attemptobj->is_last_page($page); } +/** @var renderer $output */ $output = $PAGE->get_renderer('mod_quiz'); // Arrange for the navigation to be displayed. -$navbc = $attemptobj->get_navigation_panel($output, 'quiz_review_nav_panel', $page, $showall); +$navbc = $attemptobj->get_navigation_panel($output, navigation_panel_review::class, $page, $showall); $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 cee3520cabc..3d868bb67b4 100644 --- a/mod/quiz/upgrade.txt +++ b/mod/quiz/upgrade.txt @@ -47,6 +47,7 @@ This files describes API changes in the quiz code. - 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 + - quiz_review_nav_panel => mod_quiz\output\navigation_panel_review * The following classes have been deprecated: - mod_quiz_overdue_attempt_updater - merged into mod_quiz\task\update_overdue_attempts