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 |
/**
|
|
|
18 |
* Renderer for the grade user report
|
|
|
19 |
*
|
|
|
20 |
* @package gradereport_user
|
|
|
21 |
* @copyright 2010 Sam Hemelryk
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
use core\output\comboboxsearch;
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Custom renderer for the user grade report
|
|
|
29 |
*
|
|
|
30 |
* To get an instance of this use the following code:
|
|
|
31 |
* $renderer = $PAGE->get_renderer('gradereport_user');
|
|
|
32 |
*
|
|
|
33 |
* @copyright 2010 Sam Hemelryk
|
|
|
34 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
35 |
*/
|
|
|
36 |
class gradereport_user_renderer extends plugin_renderer_base {
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* Small rendering function that helps with outputting the relevant user selector.
|
|
|
40 |
*
|
|
|
41 |
* @param string $report
|
|
|
42 |
* @param stdClass $course
|
|
|
43 |
* @param int $userid
|
|
|
44 |
* @param null|int $groupid
|
|
|
45 |
* @param bool $includeall
|
|
|
46 |
* @return string The raw HTML to render.
|
|
|
47 |
* @throws coding_exception
|
|
|
48 |
*/
|
|
|
49 |
public function graded_users_selector(string $report, stdClass $course, int $userid, ?int $groupid, bool $includeall): string {
|
|
|
50 |
|
|
|
51 |
$select = grade_get_graded_users_select($report, $course, $userid, $groupid, $includeall);
|
|
|
52 |
$output = html_writer::tag('div', $this->output->render($select), ['id' => 'graded_users_selector']);
|
|
|
53 |
$output .= html_writer::tag('p', '', ['style' => 'page-break-after: always;']);
|
|
|
54 |
|
|
|
55 |
return $output;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
* Creates and renders the single select box for the user view.
|
|
|
60 |
*
|
|
|
61 |
* @param int $userid The selected userid
|
|
|
62 |
* @param int $userview The current view user setting constant
|
|
|
63 |
* @return string
|
|
|
64 |
*/
|
|
|
65 |
public function view_user_selector(int $userid, int $userview): string {
|
|
|
66 |
global $USER;
|
|
|
67 |
$url = $this->page->url;
|
|
|
68 |
if ($userid != $USER->id) {
|
|
|
69 |
$url->param('userid', $userid);
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
$options = [
|
|
|
73 |
GRADE_REPORT_USER_VIEW_USER => get_string('otheruser', 'grades'),
|
|
|
74 |
GRADE_REPORT_USER_VIEW_SELF => get_string('myself', 'grades')
|
|
|
75 |
];
|
|
|
76 |
$select = new single_select($url, 'userview', $options, $userview, null);
|
|
|
77 |
|
|
|
78 |
$select->label = get_string('viewas', 'grades');
|
|
|
79 |
|
|
|
80 |
$output = html_writer::tag('div', $this->output->render($select), ['class' => 'view_users_selector']);
|
|
|
81 |
|
|
|
82 |
return $output;
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
/**
|
|
|
86 |
* Renders the user selector trigger element.
|
|
|
87 |
*
|
|
|
88 |
* @param object $course The course object.
|
|
|
89 |
* @param int|null $userid The user ID.
|
|
|
90 |
* @param int|null $groupid The group ID.
|
|
|
91 |
* @return string The raw HTML to render.
|
|
|
92 |
* @throws coding_exception
|
|
|
93 |
*/
|
|
|
94 |
public function users_selector(object $course, ?int $userid = null, ?int $groupid = null): string {
|
|
|
95 |
$resetlink = new moodle_url('/grade/report/user/index.php', ['id' => $course->id, 'group' => 0]);
|
|
|
96 |
$submitteduserid = optional_param('userid', '', PARAM_INT);
|
|
|
97 |
|
|
|
98 |
if ($submitteduserid) {
|
|
|
99 |
$user = core_user::get_user($submitteduserid);
|
|
|
100 |
$currentvalue = fullname($user);
|
|
|
101 |
} else {
|
|
|
102 |
$currentvalue = '';
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
$data = [
|
|
|
106 |
'currentvalue' => $currentvalue,
|
|
|
107 |
'instance' => rand(),
|
|
|
108 |
'resetlink' => $resetlink->out(false),
|
|
|
109 |
'name' => 'userid',
|
|
|
110 |
'value' => $submitteduserid ?? '',
|
|
|
111 |
'courseid' => $course->id,
|
|
|
112 |
'group' => $groupid ?? 0,
|
|
|
113 |
];
|
|
|
114 |
|
|
|
115 |
$searchdropdown = new comboboxsearch(
|
|
|
116 |
true,
|
|
|
117 |
$this->render_from_template('core_user/comboboxsearch/user_selector', $data),
|
|
|
118 |
null,
|
|
|
119 |
'user-search d-flex',
|
|
|
120 |
null,
|
|
|
121 |
'usersearchdropdown overflow-auto',
|
|
|
122 |
null,
|
|
|
123 |
false,
|
|
|
124 |
);
|
|
|
125 |
$this->page->requires->js_call_amd('gradereport_user/user', 'init');
|
|
|
126 |
return $this->render_from_template($searchdropdown->get_template(), $searchdropdown->export_for_template($this));
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
/**
|
|
|
130 |
* Creates and renders previous/next user navigation.
|
|
|
131 |
*
|
|
|
132 |
* @param graded_users_iterator $gui Objects that is used to iterate over a list of gradable users in the course.
|
|
|
133 |
* @param int $userid The ID of the current user.
|
|
|
134 |
* @param int $courseid The course ID.
|
|
|
135 |
* @return string The raw HTML to render.
|
|
|
136 |
*/
|
|
|
137 |
public function user_navigation(graded_users_iterator $gui, int $userid, int $courseid): string {
|
|
|
138 |
|
|
|
139 |
$navigationdata = [];
|
|
|
140 |
|
|
|
141 |
$users = [];
|
|
|
142 |
while ($userdata = $gui->next_user()) {
|
|
|
143 |
$users[$userdata->user->id] = $userdata->user;
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
$arraykeys = array_keys($users);
|
|
|
147 |
$keynumber = array_search($userid, $arraykeys);
|
|
|
148 |
|
|
|
149 |
// Without a valid user or users list, there's nothing to render.
|
|
|
150 |
if ($keynumber === false) {
|
|
|
151 |
return '';
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
// Determine directionality so that icons can be modified to suit language.
|
|
|
155 |
$previousarrow = right_to_left() ? 'right' : 'left';
|
|
|
156 |
$nextarrow = right_to_left() ? 'left' : 'right';
|
|
|
157 |
|
|
|
158 |
// If the current user is not the first one in the list, find and render the previous user.
|
|
|
159 |
if ($keynumber !== 0) {
|
|
|
160 |
$previoususer = $users[$arraykeys[$keynumber - 1]];
|
|
|
161 |
$navigationdata['previoususer'] = [
|
|
|
162 |
'name' => fullname($previoususer),
|
|
|
163 |
'url' => (new moodle_url('/grade/report/user/index.php', ['id' => $courseid, 'userid' => $previoususer->id]))
|
|
|
164 |
->out(false),
|
|
|
165 |
'previousarrow' => $previousarrow
|
|
|
166 |
];
|
|
|
167 |
}
|
|
|
168 |
// If the current user is not the last one in the list, find and render the last user.
|
|
|
169 |
if ($keynumber < count($users) - 1) {
|
|
|
170 |
$nextuser = $users[$arraykeys[$keynumber + 1]];
|
|
|
171 |
$navigationdata['nextuser'] = [
|
|
|
172 |
'name' => fullname($nextuser),
|
|
|
173 |
'url' => (new moodle_url('/grade/report/user/index.php', ['id' => $courseid, 'userid' => $nextuser->id]))
|
|
|
174 |
->out(false),
|
|
|
175 |
'nextarrow' => $nextarrow
|
|
|
176 |
];
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
return $this->render_from_template('gradereport_user/user_navigation', $navigationdata);
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
/**
|
|
|
183 |
* Creates and renders 'view report as' selector element.
|
|
|
184 |
*
|
|
|
185 |
* @param int $userid The selected userid
|
|
|
186 |
* @param int $userview The current view user setting constant
|
|
|
187 |
* @param int $courseid The course ID.
|
|
|
188 |
* @return string The raw HTML to render.
|
|
|
189 |
*/
|
|
|
190 |
public function view_mode_selector(int $userid, int $userview, int $courseid): string {
|
|
|
191 |
|
|
|
192 |
$viewasotheruser = new moodle_url('/grade/report/user/index.php', ['id' => $courseid, 'userid' => $userid,
|
|
|
193 |
'userview' => GRADE_REPORT_USER_VIEW_USER]);
|
|
|
194 |
$viewasmyself = new moodle_url('/grade/report/user/index.php', ['id' => $courseid, 'userid' => $userid,
|
|
|
195 |
'userview' => GRADE_REPORT_USER_VIEW_SELF]);
|
|
|
196 |
|
|
|
197 |
$selectoroptions = [
|
|
|
198 |
$viewasotheruser->out(false) => get_string('otheruser', 'core_grades'),
|
|
|
199 |
$viewasmyself->out(false) => get_string('myself', 'core_grades')
|
|
|
200 |
];
|
|
|
201 |
|
|
|
202 |
$selectoractiveurl = $userview === GRADE_REPORT_USER_VIEW_USER ? $viewasotheruser : $viewasmyself;
|
|
|
203 |
|
|
|
204 |
$viewasselect = new \core\output\select_menu('viewas', $selectoroptions, $selectoractiveurl->out(false));
|
|
|
205 |
$viewasselect->set_label(get_string('viewas', 'core_grades'));
|
|
|
206 |
|
|
|
207 |
return $this->render_from_template('gradereport_user/view_mode_selector',
|
|
|
208 |
$viewasselect->export_for_template($this));
|
|
|
209 |
}
|
|
|
210 |
}
|