mirror of
https://github.com/moodle/moodle.git
synced 2025-02-15 05:15:07 +01:00
MDL-75423 gradereport_singleview: Next/previous user/item links
Added navigation links similar to user report page. Removed top paging bar. Bottom paging bar and select per page are moved on same level with next/previous links.
This commit is contained in:
parent
678a2bc29b
commit
6ae4e00d72
@ -148,54 +148,28 @@ if ($data = data_submitted()) {
|
||||
// Make sure we have proper final grades.
|
||||
grade_regrade_final_grades_if_required($course);
|
||||
|
||||
$graderrightnav = $graderleftnav = null;
|
||||
|
||||
$options = $report->screen->options();
|
||||
|
||||
if (!empty($options)) {
|
||||
|
||||
$optionkeys = array_keys($options);
|
||||
$optionitemid = array_shift($optionkeys);
|
||||
|
||||
$relreport = new gradereport_singleview\report\singleview(
|
||||
$courseid, $gpr, $context,
|
||||
$report->screen->item_type(), $optionitemid
|
||||
);
|
||||
$reloptions = $relreport->screen->options();
|
||||
$reloptionssorting = array_keys($relreport->screen->options());
|
||||
|
||||
$i = array_search($itemid, $reloptionssorting);
|
||||
$navparams = ['item' => $itemtype, 'id' => $courseid, 'group' => $groupid];
|
||||
if ($i > 0) {
|
||||
$navparams['itemid'] = $reloptionssorting[$i - 1];
|
||||
$link = new moodle_url('/grade/report/singleview/index.php', $navparams);
|
||||
$navprev = html_writer::link($link, $OUTPUT->larrow() . ' ' . $reloptions[$reloptionssorting[$i - 1]]);
|
||||
$graderleftnav = html_writer::tag('div', $navprev, ['class' => 'itemnav previtem']);
|
||||
}
|
||||
if ($i < count($reloptionssorting) - 1) {
|
||||
$navparams['itemid'] = $reloptionssorting[$i + 1];
|
||||
$link = new moodle_url('/grade/report/singleview/index.php', $navparams);
|
||||
$navnext = html_writer::link($link, $reloptions[$reloptionssorting[$i + 1]] . ' ' . $OUTPUT->rarrow());
|
||||
$graderrightnav = html_writer::tag('div', $navnext, ['class' => 'itemnav nextitem']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($report->screen->supports_paging()) {
|
||||
echo $report->screen->pager();
|
||||
}
|
||||
|
||||
echo $report->output();
|
||||
|
||||
if ($report->screen->supports_paging()) {
|
||||
echo $report->screen->perpage_select();
|
||||
echo $report->screen->pager();
|
||||
}
|
||||
if (($itemtype !== 'select') && ($itemtype !== 'grade_select') &&($itemtype !== 'user_select')) {
|
||||
$item = (isset($userid)) ? $userid : $itemid;
|
||||
|
||||
if (!is_null($graderleftnav)) {
|
||||
echo $graderleftnav;
|
||||
}
|
||||
if (!is_null($graderrightnav)) {
|
||||
echo $graderrightnav;
|
||||
$defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
|
||||
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
|
||||
$showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context);
|
||||
|
||||
$currentgroup = $gpr->groupid;
|
||||
|
||||
// To make some other functions work better later.
|
||||
if (!$currentgroup) {
|
||||
$currentgroup = null;
|
||||
}
|
||||
$gui = new graded_users_iterator($course, null, $currentgroup);
|
||||
$gui->require_active_enrolment($showonlyactiveenrol);
|
||||
$gui->init();
|
||||
|
||||
$userreportrenderer = $PAGE->get_renderer('gradereport_singleview');
|
||||
// Add previous/next user navigation.
|
||||
echo $userreportrenderer->report_navigation($gpr, $courseid, $context, $report, $groupid, $itemtype, $itemid);
|
||||
}
|
||||
|
||||
$event = \gradereport_singleview\event\grade_report_viewed::create(
|
||||
|
@ -43,6 +43,8 @@ $string['feedbackfor'] = 'Feedback for {$a}';
|
||||
$string['gradefor'] = 'Grade for {$a}';
|
||||
$string['gradeitem'] = 'Grade item: {$a}';
|
||||
$string['gradeuser'] = 'Grade user: {$a}';
|
||||
$string['gotonextreport'] = 'Go to next user report';
|
||||
$string['gotopreviousreport'] = 'Go to previous user report';
|
||||
$string['noscreens'] = 'Could not find a suitable single view screen.';
|
||||
$string['gradeitemcannotbeoverridden'] = 'This grade item cannot be overridden.';
|
||||
$string['itemsperpage'] = 'Items per page';
|
||||
|
@ -22,6 +22,8 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use gradereport_singleview\report\singleview;
|
||||
|
||||
/**
|
||||
* Custom renderer for the single view report.
|
||||
*
|
||||
@ -86,4 +88,67 @@ class gradereport_singleview_renderer extends plugin_renderer_base {
|
||||
$this->page->requires->js_call_amd('gradereport_singleview/grade', 'init');
|
||||
return $this->render_from_template('gradereport_singleview/grade_item_selector', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and renders previous/next user/grade item navigation.
|
||||
*
|
||||
* @param object $gpr grade plugin return tracking object
|
||||
* @param int $courseid The course ID.
|
||||
* @param \context_course $context Context of the report.
|
||||
* @param singleview $report The single view report class.
|
||||
* @param int|null $groupid Group ID
|
||||
* @param string $itemtype User or Grade item type
|
||||
* @param int $itemid Either User ID or Grade item ID
|
||||
* @return string The raw HTML to render.
|
||||
* @throws moodle_exception
|
||||
*/
|
||||
public function report_navigation(object $gpr, int $courseid, \context_course $context, singleview $report,
|
||||
?int $groupid, string $itemtype, int $itemid): string {
|
||||
|
||||
$navigation = '';
|
||||
$options = $report->screen->options();
|
||||
|
||||
$optionkeys = array_keys($options);
|
||||
$optionitemid = array_shift($optionkeys);
|
||||
|
||||
$relreport = new gradereport_singleview\report\singleview(
|
||||
$courseid, $gpr, $context,
|
||||
$report->screen->item_type(), $optionitemid
|
||||
);
|
||||
$reloptions = $relreport->screen->options();
|
||||
$reloptionssorting = array_keys($relreport->screen->options());
|
||||
|
||||
$i = array_search($itemid, $reloptionssorting);
|
||||
$navparams = ['item' => $itemtype, 'id' => $courseid, 'group' => $groupid];
|
||||
|
||||
if ($i > 0) {
|
||||
$navparams['itemid'] = $reloptionssorting[$i - 1];
|
||||
$link = (new moodle_url('/grade/report/singleview/index.php', $navparams))
|
||||
->out(false);
|
||||
$navigationdata['previoususer'] = [
|
||||
'name' => $reloptions[$navparams['itemid']],
|
||||
'url' => $link
|
||||
];
|
||||
}
|
||||
if ($i < count($reloptionssorting) - 1) {
|
||||
$navparams['itemid'] = $reloptionssorting[$i + 1];
|
||||
$link = (new moodle_url('/grade/report/singleview/index.php', $navparams))
|
||||
->out(false);
|
||||
$navigationdata['nextuser'] = [
|
||||
'name' => $reloptions[$navparams['itemid']],
|
||||
'url' => $link
|
||||
];
|
||||
}
|
||||
|
||||
if ($report->screen->supports_paging()) {
|
||||
$navigationdata['perpageselect'] = $report->screen->perpage_select();
|
||||
$navigationdata['pager'] = $report->screen->pager();
|
||||
}
|
||||
|
||||
if (isset($navigationdata)) {
|
||||
$navigation = $this->render_from_template('gradereport_singleview/report_navigation', $navigationdata);
|
||||
}
|
||||
return $navigation;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -42,6 +42,11 @@
|
||||
color: #2ca14f;
|
||||
}
|
||||
|
||||
.path-grade-report-singleview .report-navigation .container {
|
||||
max-width: 1060px;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.path-grade-report-singleview .reporttable tbody th,
|
||||
.path-grade-report-singleview .reporttable tbody td.range {
|
||||
white-space: nowrap;
|
||||
|
65
grade/report/singleview/templates/report_navigation.mustache
Normal file
65
grade/report/singleview/templates/report_navigation.mustache
Normal file
@ -0,0 +1,65 @@
|
||||
{{!
|
||||
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="report-navigation w-100">
|
||||
<div class="container w-100 d-flex">
|
||||
{{#perpageselect}}
|
||||
<div class="d-flex report-paging">
|
||||
{{{perpageselect}}}
|
||||
{{{pager}}}
|
||||
</div>
|
||||
{{/perpageselect}}
|
||||
<div class="d-flex ml-auto">
|
||||
{{#previoususer}}
|
||||
<div class="previous d-flex">
|
||||
<a href="{{url}}" aria-label="{{#str}} gotopreviousreport, gradereport_singleview {{/str}}">
|
||||
<i class="fa fa-caret-left fa-lg pr-1"></i>
|
||||
{{name}}
|
||||
</a>
|
||||
</div>
|
||||
{{/previoususer}}
|
||||
</div>
|
||||
<div class="d-flex ml-auto">
|
||||
{{#nextuser}}
|
||||
<div class="next d-flex ml-auto">
|
||||
<a href="{{url}}" aria-label="{{#str}} gotonextreport, gradereport_singleview {{/str}}">
|
||||
{{name}}
|
||||
<i class="fa fa-caret-right fa-lg pl-1"></i>
|
||||
</a>
|
||||
</div>
|
||||
{{/nextuser}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Loading…
x
Reference in New Issue
Block a user