diff --git a/mod/quiz/attemptlib.php b/mod/quiz/attemptlib.php index fd55f4c7cea..5813053aea6 100644 --- a/mod/quiz/attemptlib.php +++ b/mod/quiz/attemptlib.php @@ -28,6 +28,7 @@ defined('MOODLE_INTERNAL') || die(); use mod_quiz\access_manager; +use mod_quiz\output\links_to_other_attempts; use mod_quiz\question\bank\qbank_helper; use mod_quiz\question\display_options; @@ -1889,14 +1890,14 @@ class quiz_attempt { * * The $url passed in must contain an attempt parameter. * - * The {@link mod_quiz_links_to_other_attempts} object returned contains an + * The {@see links_to_other_attempts} object returned contains an * array with keys that are the attempt number, 1, 2, 3. * The array values are either a {@link moodle_url} with the attempt parameter * updated to point to the attempt id of the other attempt, or null corresponding * to the current attempt number. * * @param moodle_url $url a URL. - * @return mod_quiz_links_to_other_attempts|bool containing array int => null|moodle_url. + * @return links_to_other_attempts|bool containing array int => null|moodle_url. * False if none. */ public function links_to_other_attempts(moodle_url $url) { @@ -1905,7 +1906,7 @@ class quiz_attempt { return false; } - $links = new mod_quiz_links_to_other_attempts(); + $links = new links_to_other_attempts(); foreach ($attempts as $at) { if ($at->id == $this->attempt->id) { $links->links[$at->attempt] = null; @@ -1921,15 +1922,15 @@ class quiz_attempt { * * The $url passed in must contain a slot parameter. * - * The {@link mod_quiz_links_to_other_attempts} object returned contains an + * The {@see links_to_other_attempts} object returned contains an * array with keys that are the redo number, 1, 2, 3. - * The array values are either a {@link moodle_url} with the slot parameter + * The array values are either a {@see moodle_url} with the slot parameter * updated to point to the slot that has that redo of this question; or null * corresponding to the redo identified by $slot. * * @param int $slot identifies a question in this attempt. * @param moodle_url $baseurl the base URL to modify to generate each link. - * @return mod_quiz_links_to_other_attempts|null containing array int => null|moodle_url, + * @return links_to_other_attempts|null containing array int => null|moodle_url, * or null if the question in this slot has not been redone. */ public function links_to_other_redos($slot, moodle_url $baseurl) { @@ -1940,7 +1941,7 @@ class quiz_attempt { return null; } - $links = new mod_quiz_links_to_other_attempts(); + $links = new links_to_other_attempts(); $index = 1; foreach ($qas as $qa) { if ($qa->get_slot() == $slot) { diff --git a/mod/quiz/classes/output/links_to_other_attempts.php b/mod/quiz/classes/output/links_to_other_attempts.php new file mode 100644 index 00000000000..7a94410281d --- /dev/null +++ b/mod/quiz/classes/output/links_to_other_attempts.php @@ -0,0 +1,38 @@ +. + +namespace mod_quiz\output; + +use renderable; + +/** + * Represents the list of links to other attempts + * + * @package mod_quiz + * @category output + * @copyright 2011 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class links_to_other_attempts implements renderable { + /** + * @var array The list of links. string attempt number => one of three things: + * - null if this is the current attempt, and so should not be linked. (Just the number is output.) + * - moodle_url if this is a different attempt. (Output as a link to the URL with the number as link text.) + * - a renderable, in which case the results of rendering the renderable is output. + * (This is used by {@see quiz_attempt::links_to_other_redos()}.) + */ + public $links = []; +} diff --git a/mod/quiz/db/renamedclasses.php b/mod/quiz/db/renamedclasses.php index 5752280611c..d3dc759dc58 100644 --- a/mod/quiz/db/renamedclasses.php +++ b/mod/quiz/db/renamedclasses.php @@ -56,4 +56,5 @@ $renamedclasses = [ 'quiz_override_form' => 'mod_quiz\form\edit_override_form', 'quiz_access_rule_base' => 'mod_quiz\local\access_rule_base', 'quiz_add_random_form' => 'mod_quiz\form\add_random_form', + 'mod_quiz_links_to_other_attempts' => 'mod_quiz\output\links_to_other_attempts', ]; diff --git a/mod/quiz/renderer.php b/mod/quiz/renderer.php index be7f147b816..8e108fc7d94 100644 --- a/mod/quiz/renderer.php +++ b/mod/quiz/renderer.php @@ -27,6 +27,7 @@ defined('MOODLE_INTERNAL') || die(); use mod_quiz\access_manager; use mod_quiz\form\preflight_check_form; +use mod_quiz\output\links_to_other_attempts; use mod_quiz\question\display_options; @@ -410,12 +411,13 @@ class mod_quiz_renderer extends plugin_renderer_base { } /** - * outputs the link the other attempts. + * Renders a list of links the other attempts. * - * @param mod_quiz_links_to_other_attempts $links + * @param links_to_other_attempts $links + * @return string HTML fragment. */ - protected function render_mod_quiz_links_to_other_attempts( - mod_quiz_links_to_other_attempts $links) { + protected function render_links_to_other_attempts( + links_to_other_attempts $links) { $attemptlinks = array(); foreach ($links->links as $attempt => $url) { if (!$url) { @@ -1416,15 +1418,19 @@ class mod_quiz_renderer extends plugin_renderer_base { array('id' => 'connection-error', 'style' => 'display: none;', 'role' => 'alert')) . html_writer::tag('div', $ok, array('id' => 'connection-ok', 'style' => 'display: none;', 'role' => 'alert')); } -} -class mod_quiz_links_to_other_attempts implements renderable { /** - * @var array string attempt number => url, or null for the current attempt. - * url may be either a moodle_url, or a renderable. + * Deprecated version of render_links_to_other_attempts. + * + * @param links_to_other_attempts $links + * @return string HTML fragment. + * @deprecated since Moodle 4.2. Please use render_links_to_other_attempts instead. + * @todo MDL-76612 Final deprecation in Moodle 4.6 */ - public $links = array(); + protected function render_mod_quiz_links_to_other_attempts(links_to_other_attempts $links) { + return $this->render_links_to_other_attempts($links); + } } diff --git a/mod/quiz/upgrade.txt b/mod/quiz/upgrade.txt index b78063e9c71..409bf2717dc 100644 --- a/mod/quiz/upgrade.txt +++ b/mod/quiz/upgrade.txt @@ -40,6 +40,7 @@ This files describes API changes in the quiz code. - quiz_override_form => mod_quiz\form\edit_override_form - quiz_access_rule_base => mod_quiz\local\access_rule_base - quiz_add_random_form => mod_quiz\form\add_random_form + - mod_quiz_links_to_other_attempts => mod_quiz\output\links_to_other_attempts * The following classes have been deprecated: - mod_quiz_overdue_attempt_updater - merged into mod_quiz\task\update_overdue_attempts