1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace mod_quiz\output;
|
|
|
18 |
|
|
|
19 |
use moodle_url;
|
|
|
20 |
use renderable;
|
|
|
21 |
use renderer_base;
|
|
|
22 |
use templatable;
|
|
|
23 |
use url_select;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Render overrides action in the quiz secondary navigation
|
|
|
27 |
*
|
|
|
28 |
* The user/group overrides are now handled in the secondary navigation.
|
|
|
29 |
* This class provides the data for the templates to handle the data for
|
|
|
30 |
* overrides tab.
|
|
|
31 |
*
|
|
|
32 |
* @package mod_quiz
|
|
|
33 |
* @copyright 2021 Sujith Haridasan <sujith@moodle.com>
|
|
|
34 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
35 |
*/
|
|
|
36 |
class overrides_actions implements renderable, templatable {
|
|
|
37 |
/** @var int The course module ID. */
|
|
|
38 |
private $cmid;
|
|
|
39 |
|
|
|
40 |
/** @var string The mode passed for the overrides url. */
|
|
|
41 |
private $mode;
|
|
|
42 |
|
|
|
43 |
/** @var bool Check if the user have capabilities to list overrides. */
|
|
|
44 |
private $canedit;
|
|
|
45 |
|
|
|
46 |
/** @var bool Should the add override button be enabled or disabled. */
|
|
|
47 |
private $addenabled;
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* overrides_action constructor.
|
|
|
51 |
*
|
|
|
52 |
* @param int $cmid The course module id.
|
|
|
53 |
* @param string $mode The mode passed for the overrides url.
|
|
|
54 |
* @param bool $canedit Does the user have capabilities to list overrides.
|
|
|
55 |
* @param bool $addenabled Whether the add button should be enabled or disabled.
|
|
|
56 |
*/
|
|
|
57 |
public function __construct(int $cmid, string $mode, bool $canedit, bool $addenabled) {
|
|
|
58 |
$this->cmid = $cmid;
|
|
|
59 |
$this->mode = $mode;
|
|
|
60 |
$this->canedit = $canedit;
|
|
|
61 |
$this->addenabled = $addenabled;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
* Create the add override button.
|
|
|
66 |
*
|
|
|
67 |
* @param \renderer_base $output an instance of the quiz renderer.
|
|
|
68 |
* @return \single_button the button, ready to reander.
|
|
|
69 |
*/
|
|
|
70 |
public function create_add_button(\renderer_base $output): \single_button {
|
|
|
71 |
$addoverrideurl = new moodle_url('/mod/quiz/overrideedit.php',
|
|
|
72 |
['cmid' => $this->cmid, 'action' => 'add' . $this->mode]);
|
|
|
73 |
|
|
|
74 |
if ($this->mode === 'group') {
|
|
|
75 |
$label = get_string('addnewgroupoverride', 'quiz');
|
|
|
76 |
} else {
|
|
|
77 |
$label = get_string('addnewuseroverride', 'quiz');
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
$addoverridebutton = new \single_button($addoverrideurl, $label, 'get', \single_button::BUTTON_PRIMARY);
|
|
|
81 |
if (!$this->addenabled) {
|
|
|
82 |
$addoverridebutton->disabled = true;
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
return $addoverridebutton;
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
public function export_for_template(renderer_base $output): array {
|
|
|
89 |
global $PAGE;
|
|
|
90 |
$templatecontext = [];
|
|
|
91 |
|
|
|
92 |
// Build the navigation drop-down.
|
|
|
93 |
$useroverridesurl = new moodle_url('/mod/quiz/overrides.php', ['cmid' => $this->cmid, 'mode' => 'user']);
|
|
|
94 |
$groupoverridesurl = new moodle_url('/mod/quiz/overrides.php', ['cmid' => $this->cmid, 'mode' => 'group']);
|
|
|
95 |
|
|
|
96 |
$menu = [
|
|
|
97 |
$useroverridesurl->out(false) => get_string('useroverrides', 'quiz'),
|
|
|
98 |
$groupoverridesurl->out(false) => get_string('groupoverrides', 'quiz')
|
|
|
99 |
];
|
|
|
100 |
|
|
|
101 |
$overridesnav = new url_select($menu, $PAGE->url->out(false), null, 'quizoverrides');
|
|
|
102 |
$templatecontext['overridesnav'] = $overridesnav->export_for_template($output);
|
|
|
103 |
|
|
|
104 |
// Build the add button - but only if the user can edit.
|
|
|
105 |
if ($this->canedit) {
|
|
|
106 |
$templatecontext['addoverridebutton'] = $this->create_add_button($output)->export_for_template($output);
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
return $templatecontext;
|
|
|
110 |
}
|
|
|
111 |
}
|