From dfb3de1eb3de83e3aa16f9366670f248cafe34f4 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Mon, 27 Feb 2023 12:59:52 +0000 Subject: [PATCH] MDL-74610 quiz: multiple grades - UI mockup and nav --- mod/quiz/classes/output/edit_grading_page.php | 50 ++++ mod/quiz/classes/output/edit_nav_actions.php | 78 ++++++ mod/quiz/edit.php | 10 +- mod/quiz/editgrading.php | 72 ++++++ mod/quiz/lang/en/quiz.php | 2 + mod/quiz/templates/edit_grading_page.mustache | 232 ++++++++++++++++++ mod/quiz/templates/edit_nav_actions.mustache | 59 +++++ 7 files changed, 501 insertions(+), 2 deletions(-) create mode 100644 mod/quiz/classes/output/edit_grading_page.php create mode 100644 mod/quiz/classes/output/edit_nav_actions.php create mode 100644 mod/quiz/editgrading.php create mode 100644 mod/quiz/templates/edit_grading_page.mustache create mode 100644 mod/quiz/templates/edit_nav_actions.mustache diff --git a/mod/quiz/classes/output/edit_grading_page.php b/mod/quiz/classes/output/edit_grading_page.php new file mode 100644 index 00000000000..bd146e45c67 --- /dev/null +++ b/mod/quiz/classes/output/edit_grading_page.php @@ -0,0 +1,50 @@ +. + +namespace mod_quiz\output; + +use mod_quiz\structure; +use renderable; +use renderer_base; +use templatable; + +/** + * Represents the page where teachers can set up additional grade items. + * + * @package mod_quiz + * @category output + * @copyright 2023 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class edit_grading_page implements renderable, templatable { + + /** + * Constructor. + * + * @param structure $structure + */ + public function __construct( + + /** @var structure structure of the quiz for which to display the grade edit page. */ + protected readonly structure $structure, + + ) { + } + + public function export_for_template(renderer_base $output) { + return []; + } +} diff --git a/mod/quiz/classes/output/edit_nav_actions.php b/mod/quiz/classes/output/edit_nav_actions.php new file mode 100644 index 00000000000..0e7b7bf9d6f --- /dev/null +++ b/mod/quiz/classes/output/edit_nav_actions.php @@ -0,0 +1,78 @@ +. + +namespace mod_quiz\output; + +use moodle_url; +use renderable; +use renderer_base; +use templatable; +use url_select; + +/** + * Represents the tertiary navigation around the quiz edit pages. + * + * @package mod_quiz + * @copyright 2023 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class edit_nav_actions implements renderable, templatable { + /** @var string option for $whichpage argument to the constructor. */ + const SUMMARY = 'summary'; + + /** @var string option for $whichpage argument to the constructor. */ + const GRADING = 'grading'; + + /** + * overrides_action constructor. + * + * @param int $cmid The course module id. + * @param string $whichpage self::SUMMARY (edit.php) or self::GRADING (editgrading.php). + */ + public function __construct( + + /** @var int The course module ID. */ + protected readonly int $cmid, + + /** @var string which page this is. Either self::SUMMARY (edit.php) or self::GRADING (editgrading.php). */ + protected readonly string $whichpage, + + ) { + } + + public function export_for_template(renderer_base $output): array { + + // Build the navigation drop-down. + $questionsurl = new moodle_url('/mod/quiz/edit.php', ['cmid' => $this->cmid]); + $complexgradingurl = new moodle_url('/mod/quiz/editgrading.php', ['cmid' => $this->cmid]); + + $menu = [ + $questionsurl->out(false) => get_string('questions', 'quiz'), + $complexgradingurl->out(false) => get_string('complexgrading', 'quiz'), + ]; + + $overridesnav = new url_select( + $menu, + $this->whichpage === self::SUMMARY ? $questionsurl->out(false) : $complexgradingurl->out(false), + null + ); + $overridesnav->set_label(get_string('quizsetupnavigation', 'quiz'), ['class' => 'sr-only']); + + return [ + 'navmenu' => $overridesnav->export_for_template($output), + ]; + } +} diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index 1a74a09b494..3d86cb72876 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -40,6 +40,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +use mod_quiz\output\edit_nav_actions; use mod_quiz\quiz_settings; require_once(__DIR__ . '/../../config.php'); @@ -186,7 +187,12 @@ if ($message = optional_param('message', '', PARAM_TEXT)) { core\notification::add($message, core\notification::SUCCESS); } -echo $OUTPUT->header(); +$tertiarynav = new edit_nav_actions($cmid, edit_nav_actions::SUMMARY); + +// Do output. +echo $output->header(); +echo $output->render($tertiarynav); + // Initialise the JavaScript. $quizeditconfig = new stdClass(); $quizeditconfig->url = $thispageurl->out(true, ['qbanktool' => '0']); @@ -211,4 +217,4 @@ echo $output->edit_page($quizobj, $structure, $contexts, $thispageurl, $pagevars // Questions wrapper end. echo html_writer::end_tag('div'); -echo $OUTPUT->footer(); +echo $output->footer(); diff --git a/mod/quiz/editgrading.php b/mod/quiz/editgrading.php new file mode 100644 index 00000000000..e3912757abe --- /dev/null +++ b/mod/quiz/editgrading.php @@ -0,0 +1,72 @@ +. + +/** + * Page to edit complex grading setups for quizzes + * + * For quizzes with basic grading, everything can be done on edit.php. + * However, more advanced options are possible, if you come to this + * separate page. + * + * @package mod_quiz + * @copyright 2023 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +use mod_quiz\output\edit_grading_page; +use mod_quiz\output\edit_nav_actions; +use mod_quiz\quiz_settings; + +// The require_login check is done in question_edit_setup, but the automated checker can't see this. +// phpcs:ignore moodle.Files.RequireLogin.Missing +require_once(__DIR__ . '/../../config.php'); +require_once($CFG->dirroot . '/mod/quiz/locallib.php'); +require_once($CFG->dirroot . '/question/editlib.php'); + +list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) = + question_edit_setup('editq', '/mod/quiz/editgrading.php', true); + +$PAGE->set_url($thispageurl); +$PAGE->set_secondary_active_tab('mod_quiz_edit'); + +// You need mod/quiz:manage in addition to question capabilities to access this page. +require_capability('mod/quiz:manage', $contexts->lowest()); + +// Get the course object and related bits. +$course = get_course($quiz->course); +$quizobj = new quiz_settings($quiz, $cm, $course); +$structure = $quizobj->get_structure(); +$editpage = new edit_grading_page($structure); + +$quizhasattempts = quiz_has_attempts($quiz->id); + +// Initialise output. +$PAGE->set_pagelayout('incourse'); +$PAGE->set_pagetype('mod-quiz-edit'); + +$output = $PAGE->get_renderer('mod_quiz', 'edit'); + +$PAGE->set_title(get_string('editingquizx', 'quiz', format_string($quiz->name))); +$PAGE->set_heading($course->fullname); +$PAGE->activityheader->disable(); +$PAGE->set_secondary_active_tab('mod_quiz_edit'); +$tertiarynav = new edit_nav_actions($cmid, edit_nav_actions::GRADING); + +// Do output. +echo $output->header(); +echo $output->render($tertiarynav); +echo $output->render($editpage); +echo $output->footer(); diff --git a/mod/quiz/lang/en/quiz.php b/mod/quiz/lang/en/quiz.php index ee17c971e76..afb1804059b 100644 --- a/mod/quiz/lang/en/quiz.php +++ b/mod/quiz/lang/en/quiz.php @@ -191,6 +191,7 @@ $string['completionminattemptserror'] = 'Minimum number of attempts must be lowe $string['completionpassorattemptsexhausteddesc'] = 'Student must achieve a passing grade, or exhaust all available attempts to complete this activity'; $string['completionattemptsexhausted'] = 'Passing grade or all available attempts completed'; $string['completionattemptsexhausted_help'] = 'Mark quiz complete when the student has exhausted the maximum number of attempts.'; +$string['complexgrading'] = 'Complex grading setup'; $string['configadaptive'] = 'If you choose Yes for this option then the student will be allowed multiple responses to a question even within the same attempt at the quiz.'; $string['configattemptsallowed'] = 'Restriction on the number of attempts students are allowed at the quiz.'; $string['configdecimaldigits'] = 'Number of digits that should be shown after the decimal point when displaying grades.'; @@ -810,6 +811,7 @@ $string['quiz:reopenattempts'] = 'Reopen never submitted quiz attempts'; $string['quizreport'] = 'Quiz report'; $string['quiz:reviewmyattempts'] = 'Review your own attempts'; $string['quizsettings'] = 'Quiz settings'; +$string['quizsetupnavigation'] = 'Quiz setup navigation'; $string['quiz:view'] = 'View quiz information'; $string['quiz:viewreports'] = 'View quiz reports'; $string['quiztimer'] = 'Quiz Timer'; diff --git a/mod/quiz/templates/edit_grading_page.mustache b/mod/quiz/templates/edit_grading_page.mustache new file mode 100644 index 00000000000..27ea23e9de6 --- /dev/null +++ b/mod/quiz/templates/edit_grading_page.mustache @@ -0,0 +1,232 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template mod_quiz/edit_grading_page + + Display the Quiz complex grading page, from below tertiary nav, to above the footer. + + Classes required for JS: + * none. + + Data attributes required for JS: + * Many. See mod_quiz/edit_grading module. + + Context variables required for this template: + * TBC + + Example context (json): + { + } +}} + +

Quiz grading setup (advanced view)

+ +

Grade items

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Grade itemMax markActions
+ + + Spelling + + + + + + + + + 8.00 + + + + + + + + + +
+ + + Grammar + + + + + + + + + 8.00 + + + + + + + + + +
+ + + Comprehension + + + + + + + + + 8.00 + + + + + + + + + +
Total + + + 24.00 + + + + + +  
+ +
+ + +
+ +

Mark scheme

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
No.QuestionSpellingGrammarComprehension
+

Section 1: Holidays

+
i + Description + Instructions + To answer this quiz you need to ... +    
1 + + Beach 1 + What colour is the sand? +    + + + 2.00 + + + + + +
2 + + Beach 2 + The sea is blue. How do you write that in French? + + + + 2.00 + + + + + +   
+

Section 2: Food

+
+

Section 3: Pets

+
diff --git a/mod/quiz/templates/edit_nav_actions.mustache b/mod/quiz/templates/edit_nav_actions.mustache new file mode 100644 index 00000000000..63cbbd0e692 --- /dev/null +++ b/mod/quiz/templates/edit_nav_actions.mustache @@ -0,0 +1,59 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template mod_quiz/edit_nav_actions + + Actions bar at the top of the various quiz edit pages. + + Classes required for JS: + * none + + Data attributes required for JS: + * none + + Context variables required for this template: + * overridesnav - must alwasy be present. + * addoverridebutton - should only be present if the user has permission to add a new override. + + Example context (json): + { + "id": "url_select_test", + "action": "https://example.com/post", + "formid": "url_select_form", + "sesskey": "sesskey", + "navmenu": { + "options": [{ + "name": "Questions", + "value": "/mod/quiz/edit.php?cmid=123" + }, + { + "name": "Complex grading", + "value": "/mod/quiz/editgrading.php?cmid=123" + } + ] + } + } +}} +
+
+ {{#navmenu}} + + {{/navmenu}} +
+