mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-75513 core_grades: Renderer for the prev/next user navigation
This commit is contained in:
parent
1046e06e83
commit
ba80b78119
@ -26,6 +26,8 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$string['allusersnum'] = 'All users ({$a})';
|
||||
$string['eventgradereportviewed'] = 'Grade user report viewed';
|
||||
$string['gotonextreport'] = 'Go to next user report';
|
||||
$string['gotopreviousreport'] = 'Go to previous user report';
|
||||
$string['pluginname'] = 'User report';
|
||||
$string['user:view'] = 'View your own grade report';
|
||||
$string['privacy:metadata:preference:gradereport_user_view_user'] = 'Whether to view report as current user or another user in the gradebook reports';
|
||||
|
@ -129,4 +129,46 @@ class gradereport_user_renderer extends plugin_renderer_base {
|
||||
$this->page->requires->js_call_amd('gradereport_user/user', 'init');
|
||||
return $this->render_from_template('gradereport_user/user_selector', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and renders previous/next user navigation.
|
||||
*
|
||||
* @param graded_users_iterator $gui Objects that is used to iterate over a list of gradable users in the course.
|
||||
* @param int $userid The ID of the current user.
|
||||
* @param int $courseid The course ID.
|
||||
* @return string The raw HTML to render.
|
||||
*/
|
||||
public function user_navigation(graded_users_iterator $gui, int $userid, int $courseid): string {
|
||||
|
||||
$navigationdata = [];
|
||||
|
||||
while ($userdata = $gui->next_user()) {
|
||||
$users[$userdata->user->id] = $userdata->user;
|
||||
}
|
||||
$gui->close();
|
||||
|
||||
$arraykeys = array_keys($users);
|
||||
$keynumber = array_search($userid, $arraykeys);
|
||||
|
||||
// If the current user is not the first one in the list, find and render the previous user.
|
||||
if ($keynumber !== 0) {
|
||||
$previoususer = $users[$arraykeys[$keynumber - 1]];
|
||||
$navigationdata['previoususer'] = [
|
||||
'name' => fullname($previoususer),
|
||||
'url' => (new moodle_url('/grade/report/user/index.php', ['id' => $courseid, 'userid' => $previoususer->id]))
|
||||
->out(false)
|
||||
];
|
||||
}
|
||||
// If the current user is not the last one in the list, find and render the last user.
|
||||
if ($keynumber < count($users) - 1) {
|
||||
$nextuser = $users[$arraykeys[$keynumber + 1]];
|
||||
$navigationdata['nextuser'] = [
|
||||
'name' => fullname($nextuser),
|
||||
'url' => (new moodle_url('/grade/report/user/index.php', ['id' => $courseid, 'userid' => $nextuser->id]))
|
||||
->out(false)
|
||||
];
|
||||
}
|
||||
|
||||
return $this->render_from_template('gradereport_user/user_navigation', $navigationdata);
|
||||
}
|
||||
}
|
||||
|
@ -132,6 +132,10 @@
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.path-grade-report-user .user-navigation .container {
|
||||
max-width: 767px;
|
||||
}
|
||||
|
||||
@media print {
|
||||
.path-grade-report-user .user-grade td.category {
|
||||
border-left: none;
|
||||
|
61
grade/report/user/templates/user_navigation.mustache
Normal file
61
grade/report/user/templates/user_navigation.mustache
Normal file
@ -0,0 +1,61 @@
|
||||
{{!
|
||||
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/>.
|
||||
}}
|
||||
{{!
|
||||
@template gradereport_user/user_navigation
|
||||
|
||||
The previous/next user navigation for the user report view.
|
||||
|
||||
Context variables required for this template:
|
||||
* previoususer - (optional) The object containing information about the previous user.
|
||||
* name - The name of the previous user.
|
||||
* url - The URL to the previous user report.
|
||||
* nextuser - (optional) The object containing information about the next user.
|
||||
* name - The name of the next user.
|
||||
* url - The URL to the next user report.
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"previoususer": {
|
||||
"name": "John Smith",
|
||||
"url": "https://example.com/grade/report/user/index.php?id=2&userid=3"
|
||||
},
|
||||
"previoususer": {
|
||||
"name": "Jane Doe",
|
||||
"url": "https://example.com/grade/report/user/index.php?id=2&userid=5"
|
||||
}
|
||||
}
|
||||
}}
|
||||
<div class="user-navigation w-100">
|
||||
<div class="container w-100 d-flex">
|
||||
{{#previoususer}}
|
||||
<div class="previous d-flex">
|
||||
<a href="{{url}}" aria-label="{{#str}} gotopreviousreport, gradereport_user {{/str}}">
|
||||
<i class="fa fa-caret-left fa-lg pr-1"></i>
|
||||
{{name}}
|
||||
</a>
|
||||
</div>
|
||||
{{/previoususer}}
|
||||
{{#nextuser}}
|
||||
<div class="next d-flex ml-auto">
|
||||
<a href="{{url}}" aria-label="{{#str}} gotonextreport, gradereport_user {{/str}}">
|
||||
{{name}}
|
||||
<i class="fa fa-caret-right fa-lg pl-1"></i>
|
||||
</a>
|
||||
</div>
|
||||
{{/nextuser}}
|
||||
</div>
|
||||
</div>
|
Loading…
x
Reference in New Issue
Block a user