Skip to content

Commit

Permalink
MDL-75423 gradereport_singleview: Next/previous user/item links
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ilyatregubov authored and Mihail Geshoski committed Nov 10, 2022
1 parent 678a2bc commit 6ae4e00
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 42 deletions.
58 changes: 16 additions & 42 deletions grade/report/singleview/index.php
Expand Up @@ -148,54 +148,28 @@
// Make sure we have proper final grades.
grade_regrade_final_grades_if_required($course);

$graderrightnav = $graderleftnav = null;

$options = $report->screen->options();
echo $report->output();

if (!empty($options)) {
if (($itemtype !== 'select') && ($itemtype !== 'grade_select') &&($itemtype !== 'user_select')) {
$item = (isset($userid)) ? $userid : $itemid;

$optionkeys = array_keys($options);
$optionitemid = array_shift($optionkeys);
$defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
$showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context);

$relreport = new gradereport_singleview\report\singleview(
$courseid, $gpr, $context,
$report->screen->item_type(), $optionitemid
);
$reloptions = $relreport->screen->options();
$reloptionssorting = array_keys($relreport->screen->options());
$currentgroup = $gpr->groupid;

$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']);
// To make some other functions work better later.
if (!$currentgroup) {
$currentgroup = null;
}
}

if ($report->screen->supports_paging()) {
echo $report->screen->pager();
}
$gui = new graded_users_iterator($course, null, $currentgroup);
$gui->require_active_enrolment($showonlyactiveenrol);
$gui->init();

echo $report->output();

if ($report->screen->supports_paging()) {
echo $report->screen->perpage_select();
echo $report->screen->pager();
}

if (!is_null($graderleftnav)) {
echo $graderleftnav;
}
if (!is_null($graderrightnav)) {
echo $graderrightnav;
$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(
Expand Down
2 changes: 2 additions & 0 deletions grade/report/singleview/lang/en/gradereport_singleview.php
Expand Up @@ -43,6 +43,8 @@
$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';
Expand Down
65 changes: 65 additions & 0 deletions grade/report/singleview/renderer.php
Expand Up @@ -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.
*
Expand Down Expand Up @@ -86,4 +88,67 @@ public function grade_items_selector(object $course, ?int $gradeitemid = null):
$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;
}

}
5 changes: 5 additions & 0 deletions grade/report/singleview/styles.css
Expand Up @@ -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;
Expand Down
65 changes: 65 additions & 0 deletions grade/report/singleview/templates/report_navigation.mustache
@@ -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>

0 comments on commit 6ae4e00

Please sign in to comment.