Skip to content

Commit

Permalink
MDL-73335 mod_quiz: Add tertiary nav for the quiz module
Browse files Browse the repository at this point in the history
The tertiary navigation added for quiz module.

- Added tertiary nav buttons for the edit, attempt and view page
- urlselector is added to the overrides page to access user/groups
- The secondary tabs are highlighted when user navigates to
  each page in quiz.
- Updated the behat tests for the changes made.

This commit is mostly Sujith's work, with further changes by
Tim Hunt <T.J.Hunt@open.ac.uk> so we share the blame/credit.
  • Loading branch information
sharidas authored and ilyatregubov committed Feb 24, 2022
1 parent 2995042 commit 3458d15
Show file tree
Hide file tree
Showing 36 changed files with 505 additions and 200 deletions.
2 changes: 2 additions & 0 deletions mod/quiz/attempt.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
// During quiz attempts, the browser back/forwards buttons should force a reload.
$PAGE->set_cacheable(false);

$PAGE->set_secondary_active_tab("modulepage");

// Check login.
require_login($attemptobj->get_course(), false, $attemptobj->get_cm());

Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/attemptlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public function get_context() {
}

/**
* @return bool wether the current user is someone who previews the quiz,
* @return bool whether the current user is someone who previews the quiz,
* rather than attempting it.
*/
public function is_preview_user() {
Expand Down
60 changes: 60 additions & 0 deletions mod/quiz/classes/local/views/secondary.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
// 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 <http://www.gnu.org/licenses/>.

namespace mod_quiz\local\views;

use core\navigation\views\secondary as core_secondary;

/**
* Class secondary_navigation_view.
*
* Custom implementation for a plugin.
*
* @package mod_quiz
* @category navigation
* @copyright 2021 Sujith Haridasan <sujith@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class secondary extends core_secondary {
/**
* Define a custom secondary nav order/view.
*
* @return array
*/
protected function get_default_module_mapping(): array {
$defaultmaping = parent::get_default_module_mapping();

$defaultmaping[self::TYPE_SETTING] = array_merge($defaultmaping[self::TYPE_SETTING], [
'mod_quiz_edit' => 3,
'quiz_report' => 4,
'mod_quiz_useroverrides' => 6,
'roleassign' => 7,
'filtermanage' => 8,
'roleoverride' => 9,
'rolecheck' => 9.1,
'logreport' => 10,
'backup' => 11,
'restore' => 12,
'competencybreakdown' => 13,
]);

$defaultmaping[self::TYPE_CONTAINER] = [
'questionbank' => 5,
];

return $defaultmaping;
}
}
4 changes: 1 addition & 3 deletions mod/quiz/classes/output/edit_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ public function edit_page(\quiz $quizobj, structure $structure,
$output = '';

// Page title.
$output .= $this->heading_with_help(get_string('editingquizx', 'quiz',
format_string($quizobj->get_quiz_name())), 'editingquiz', 'quiz', '',
get_string('basicideasofquiz', 'quiz'), 2);
$output .= $this->heading(get_string('questions', 'quiz'));

// Information at the top.
$output .= $this->quiz_state_warnings($structure);
Expand Down
111 changes: 111 additions & 0 deletions mod/quiz/classes/output/overrides_actions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php
// 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 <http://www.gnu.org/licenses/>.

namespace mod_quiz\output;

use moodle_url;
use renderable;
use renderer_base;
use templatable;
use url_select;

/**
* Render overrides action in the quiz secondary navigation
*
* The user/group overrides are now handled in the secondary navigation.
* This class provides the data for the templates to handle the data for
* overrides tab.
*
* @package mod_quiz
* @copyright 2021 Sujith Haridasan <sujith@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class overrides_actions implements renderable, templatable {
/** @var int The course module ID. */
private $cmid;

/** @var string The mode passed for the overrides url. */
private $mode;

/** @var bool Check if the user have capabilities to list overrides. */
private $canedit;

/** @var bool Should the add override button be enabled or disabled. */
private $addenabled;

/**
* overrides_action constructor.
*
* @param int $cmid The course module id.
* @param string $mode The mode passed for the overrides url.
* @param bool $canedit Does the user have capabilities to list overrides.
* @param bool $addenabled Whether the add button should be enabled or disabled.
*/
public function __construct(int $cmid, string $mode, bool $canedit, bool $addenabled) {
$this->cmid = $cmid;
$this->mode = $mode;
$this->canedit = $canedit;
$this->addenabled = $addenabled;
}

/**
* Create the add override button.
*
* @param \renderer_base $output an instance of the quiz renderer.
* @return \single_button the button, ready to reander.
*/
public function create_add_button(\renderer_base $output): \single_button {
$addoverrideurl = new moodle_url('/mod/quiz/overrideedit.php',
['cmid' => $this->cmid, 'action' => 'add' . $this->mode]);

if ($this->mode === 'group') {
$label = get_string('addnewgroupoverride', 'quiz');
} else {
$label = get_string('addnewuseroverride', 'quiz');
}

$addoverridebutton = new \single_button($addoverrideurl, $label, 'get', true);
if (!$this->addenabled) {
$addoverridebutton->disabled = true;
}

return $addoverridebutton;
}

public function export_for_template(renderer_base $output): array {
global $PAGE;
$templatecontext = [];

// Build the navigation drop-down.
$useroverridesurl = new moodle_url('/mod/quiz/overrides.php', ['cmid' => $this->cmid, 'mode' => 'user']);
$groupoverridesurl = new moodle_url('/mod/quiz/overrides.php', ['cmid' => $this->cmid, 'mode' => 'group']);

$menu = [
$useroverridesurl->out(false) => get_string('useroverrides', 'quiz'),
$groupoverridesurl->out(false) => get_string('groupoverrides', 'quiz')
];

$overridesnav = new url_select($menu, $PAGE->url->out(false), null, 'quizoverrides');
$templatecontext['overridesnav'] = $overridesnav->export_for_template($output);

// Build the add button - but only if the user can edit.
if ($this->canedit) {
$templatecontext['addoverridebutton'] = $this->create_add_button($output)->export_for_template($output);
}

return $templatecontext;
}
}
1 change: 1 addition & 0 deletions mod/quiz/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
$quizhasattempts = quiz_has_attempts($quiz->id);

$PAGE->set_url($thispageurl);
$PAGE->set_secondary_active_tab("mod_quiz_edit");

// Get the course object and related bits.
$course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST);
Expand Down
1 change: 1 addition & 0 deletions mod/quiz/lang/en/deprecated.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ completionpassdesc,mod_quiz
completionpass_help,mod_quiz
completiondetail:passgrade,mod_quiz
gradetopassnotset,mod_quiz
basicideasofquiz,mod_quiz
4 changes: 3 additions & 1 deletion mod/quiz/lang/en/quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
$string['attemptlast'] = 'Last attempt';
$string['attemptnumber'] = 'Attempt';
$string['attemptquiznow'] = 'Attempt quiz now';
$string['attemptquiz'] = 'Attempt quiz';
$string['attemptreviewtitle'] = '{$a}: Attempt review';
$string['attemptreviewtitlepaged'] = '{$a->name}: Attempt review (page {$a->currentpage} of {$a->totalpages})';
$string['attempts'] = 'Attempts';
Expand All @@ -124,7 +125,6 @@
$string['backtocourse'] = 'Back to the course';
$string['backtoquestionlist'] = 'Back to question list';
$string['backtoquiz'] = 'Back to quiz editing';
$string['basicideasofquiz'] = 'The basic ideas of quiz-making';
$string['bestgrade'] = 'Best grade';
$string['bothattempts'] = 'Show students with and without attempts';
$string['browsersecurity'] = 'Browser security';
Expand Down Expand Up @@ -687,6 +687,7 @@
$string['preview'] = 'Preview';
$string['previewquestion'] = 'Preview question';
$string['previewquiz'] = 'Preview {$a}';
$string['previewquizstart'] = 'Preview quiz';
$string['previewquiznow'] = 'Preview quiz now';
$string['previous'] = 'Previous state';
$string['privacy:metadata:core_question'] = 'The quiz activity stores question usage information in the core_question subsystem.';
Expand Down Expand Up @@ -1065,3 +1066,4 @@
$string['completionpass_help'] = 'If enabled, this activity is considered complete when the student receives a pass grade (as specified in the Grade section of the quiz settings) or higher.';
$string['completiondetail:passgrade'] = 'Receive a pass grade';
$string['gradetopassnotset'] = 'This quiz does not yet have a grade to pass set. It may be set in the Grade section of the quiz settings.';
$string['basicideasofquiz'] = 'The basic ideas of quiz-making';
27 changes: 11 additions & 16 deletions mod/quiz/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ function quiz_user_complete($course, $user, $mod, $quiz) {
* @param int $userid the userid.
* @param string $status 'all', 'finished' or 'unfinished' to control
* @param bool $includepreviews
* @return an array of all the user's attempts at this quiz. Returns an empty
* @return array of all the user's attempts at this quiz. Returns an empty
* array if there are none.
*/
function quiz_get_user_attempts($quizids, $userid, $status = 'finished', $includepreviews = false) {
Expand Down Expand Up @@ -1724,20 +1724,14 @@ function quiz_extend_settings_navigation($settings, $quiznode) {
}

if (has_any_capability(['mod/quiz:manageoverrides', 'mod/quiz:viewoverrides'], $PAGE->cm->context)) {
$url = new moodle_url('/mod/quiz/overrides.php', array('cmid'=>$PAGE->cm->id));
$node = navigation_node::create(get_string('groupoverrides', 'quiz'),
new moodle_url($url, array('mode'=>'group')),
navigation_node::TYPE_SETTING, null, 'mod_quiz_groupoverrides');
$quiznode->add_node($node, $beforekey);

$node = navigation_node::create(get_string('useroverrides', 'quiz'),
new moodle_url($url, array('mode'=>'user')),
navigation_node::TYPE_SETTING, null, 'mod_quiz_useroverrides');
$quiznode->add_node($node, $beforekey);
$url = new moodle_url('/mod/quiz/overrides.php', array('cmid' => $PAGE->cm->id));
$node = navigation_node::create(get_string('overrides', 'quiz'),
$url, navigation_node::TYPE_SETTING, null, 'mod_quiz_useroverrides');
$settingsoverride = $quiznode->add_node($node, $beforekey);
}

if (has_capability('mod/quiz:manage', $PAGE->cm->context)) {
$node = navigation_node::create(get_string('editquiz', 'quiz'),
$node = navigation_node::create(get_string('questions', 'quiz'),
new moodle_url('/mod/quiz/edit.php', array('cmid'=>$PAGE->cm->id)),
navigation_node::TYPE_SETTING, null, 'mod_quiz_edit',
new pix_icon('t/edit', ''));
Expand All @@ -1750,9 +1744,12 @@ function quiz_extend_settings_navigation($settings, $quiznode) {
$node = navigation_node::create(get_string('preview', 'quiz'), $url,
navigation_node::TYPE_SETTING, null, 'mod_quiz_preview',
new pix_icon('i/preview', ''));
$quiznode->add_node($node, $beforekey);
$previewnode = $quiznode->add_node($node, $beforekey);
$previewnode->set_show_in_secondary_navigation(false);
}

question_extend_settings_navigation($quiznode, $PAGE->cm->context)->trim_if_empty();

if (has_any_capability(array('mod/quiz:viewreports', 'mod/quiz:grade'), $PAGE->cm->context)) {
require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');
$reportlist = quiz_report_list($PAGE->cm->context);
Expand All @@ -1761,7 +1758,7 @@ function quiz_extend_settings_navigation($settings, $quiznode) {
array('id' => $PAGE->cm->id, 'mode' => reset($reportlist)));
$reportnode = $quiznode->add_node(navigation_node::create(get_string('results', 'quiz'), $url,
navigation_node::TYPE_SETTING,
null, null, new pix_icon('i/report', '')), $beforekey);
null, 'quiz_report', new pix_icon('i/report', '')));

foreach ($reportlist as $report) {
$url = new moodle_url('/mod/quiz/report.php',
Expand All @@ -1771,8 +1768,6 @@ function quiz_extend_settings_navigation($settings, $quiznode) {
null, 'quiz_report_' . $report, new pix_icon('i/item', '')));
}
}

question_extend_settings_navigation($quiznode, $PAGE->cm->context)->trim_if_empty();
}

/**
Expand Down
3 changes: 3 additions & 0 deletions mod/quiz/overrideedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@

$PAGE->set_url($url);

// Activate the secondary nav tab.
$PAGE->set_secondary_active_tab("mod_quiz_useroverrides");

require_login($course, false, $cm);

$context = context_module::instance($cm->id);
Expand Down
Loading

0 comments on commit 3458d15

Please sign in to comment.