Skip to content

Commit

Permalink
MDL-74276 report: Render a new 'Reports Overview' page
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Dias committed Apr 1, 2022
1 parent 7ce003b commit 3eb80e7
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 10 deletions.
8 changes: 8 additions & 0 deletions lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4665,6 +4665,10 @@ protected function load_course_settings($forceopen = false) {
foreach ($reports as $reportfunction) {
$reportfunction($reportnav, $course, $coursecontext);
}

if (!$reportnav->has_children()) {
$reportnav->remove();
}
}

// Check if we can view the gradebook's setup page.
Expand Down Expand Up @@ -5633,6 +5637,10 @@ protected function load_front_page_settings($forceopen = false) {
foreach ($reports as $reportfunction) {
$reportfunction($frontpagenav, $course, $coursecontext);
}

if (!$frontpagenav->has_children()) {
$frontpagenav->remove();
}
}

// Backup this course
Expand Down
51 changes: 51 additions & 0 deletions lib/templates/report_link_page.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{!
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 core/report_link_page
Display the report page with a list of available reports.
Example context (json):
{
"node": {
"text": "Root of menu",
"key": "test0",
"display": true,
"children": [
{
"text": "Child of menu",
"key": "test1",
"display": true,
"children": []
}
]
}
}
}}
{{#node}}
<div class="container-fluid">
<div class="row">
<ul class="list-unstyled ml-0">
{{#node.children}}
{{#display}}
<li><a href="{{{action}}}">{{text}}</a></li>
{{/display}}
{{/node.children}}
</ul>
</div>
</div>
{{/node}}
28 changes: 18 additions & 10 deletions report/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,30 @@
}
require_login($course);

// Get all course reports from the settings navigation.
if ($reportsnode = $PAGE->settingsnav->find('coursereports', \navigation_node::TYPE_CONTAINER)) {
// If there are available course reports to the user.
if ($reportsnode->children->count() > 0) {
// Redirect to the first course report from the list.
$firstreportnode = $reportsnode->children->getIterator()[0];
redirect($firstreportnode->action()->out(false));
}
}
// Otherwise, output the page with a notification stating that there are no available course reports.
$PAGE->set_title(get_string('reports'));
$PAGE->set_pagelayout('incourse');
$PAGE->set_heading($course->fullname);
$PAGE->set_pagetype('course-view-' . $course->format);
$PAGE->add_body_class('limitedwidth');

echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('reports'));
echo html_writer::div($OUTPUT->notification(get_string('noreports', 'debug'), 'error'), 'mt-3');

// Check if there is at least one displayable report.
$hasreports = false;
if ($reportnode = $PAGE->settingsnav->find('coursereports', \navigation_node::TYPE_CONTAINER)) {
foreach ($reportnode->children as $child) {
if ($child->display) {
$hasreports = true;
break;
}
}
}

if ($hasreports) {
echo $OUTPUT->render_from_template('core/report_link_page', ['node' => $reportnode]);
} else {
echo html_writer::div($OUTPUT->notification(get_string('noreports', 'debug'), 'error'), 'mt-3');
}
echo $OUTPUT->footer();

0 comments on commit 3eb80e7

Please sign in to comment.