Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
<?php
// 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/>.

/**
 * Displays the Single view
 *
 * @package   gradereport_singleview
 * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

define('NO_OUTPUT_BUFFERING', true);

require_once('../../../config.php');
require_once($CFG->dirroot.'/lib/gradelib.php');
require_once($CFG->dirroot.'/grade/lib.php');
< require_once($CFG->dirroot.'/grade/report/singleview/lib.php');
> require_once($CFG->dirroot.'/grade/report/lib.php');
$courseid = required_param('id', PARAM_INT); $groupid = optional_param('group', null, PARAM_INT); // Making this work with profile reports. $userid = optional_param('userid', null, PARAM_INT);
< < $defaulttype = $userid ? 'user' : 'select'; <
$itemid = optional_param('itemid', null, PARAM_INT);
< $itemtype = optional_param('item', $defaulttype, PARAM_TEXT);
> $itemtype = optional_param('item', null, PARAM_TEXT);
$page = optional_param('page', 0, PARAM_INT); $perpage = optional_param('perpage', 100, PARAM_INT);
< if (empty($itemid)) { < $itemid = $userid; < $itemtype = $defaulttype; < }
> $edit = optional_param('edit', -1, PARAM_BOOL); // Sticky editing mode.
< $courseparams = array('id' => $courseid); < $pageparams = array( < 'id' => $courseid, < 'group' => $groupid, < 'userid' => $userid, < 'itemid' => $itemid, < 'item' => $itemtype, < 'page' => $page, < 'perpage' => $perpage, < ); < $PAGE->set_url(new moodle_url('/grade/report/singleview/index.php', $pageparams)); < $PAGE->set_pagelayout('incourse');
> $courseparams = ['id' => $courseid]; > > $PAGE->set_pagelayout('report'); > $PAGE->set_other_editing_capability('moodle/grade:edit');
if (!$course = $DB->get_record('course', $courseparams)) {
< print_error('invalidcourseid');
> throw new \moodle_exception('invalidcourseid');
} require_login($course);
< if (!in_array($itemtype, gradereport_singleview::valid_screens())) { < print_error('notvalid', 'gradereport_singleview', '', $itemtype); < } <
$context = context_course::instance($course->id); // This is the normal requirements. require_capability('gradereport/singleview:view', $context); require_capability('moodle/grade:viewall', $context); require_capability('moodle/grade:edit', $context);
< $gpr = new grade_plugin_return(array(
> $gpr = new grade_plugin_return([
'type' => 'report', 'plugin' => 'singleview', 'courseid' => $courseid
< ));
> ]);
// Last selected report session tracking. if (!isset($USER->grade_last_report)) {
< $USER->grade_last_report = array();
> $USER->grade_last_report = [];
} $USER->grade_last_report[$course->id] = 'singleview';
> // If the item type is not explicitly defined or not valid, try to use the last viewed one (obtain in from the session) > // or fallback to the user select (zero) state. $report = new gradereport_singleview($courseid, $gpr, $context, $itemtype, $itemid); > if (!$itemtype || !in_array($itemtype, \gradereport_singleview\report\singleview::valid_screens())) { > $itemtype = isset($SESSION->gradereport_singleview["itemtype-{$context->id}"]) ? $reportname = $report->screen->heading(); > $SESSION->gradereport_singleview["itemtype-{$context->id}"] : 'user_select'; > } $pluginname = get_string('pluginname', 'gradereport_singleview'); > > $currentgroup = $gpr->groupid; $pageparams = array( > // To make some other functions work better later. 'id' => $courseid, > if (!$currentgroup) { 'itemid' => $itemid, > $currentgroup = null; 'item' => $itemtype, > } 'userid' => $userid, > 'group' => $groupid, > $lastvieweduseritemid = $SESSION->gradereport_singleview["useritem-{$context->id}"] ?? null; 'page' => $page, > $lastviewedgradeitemid = $SESSION->gradereport_singleview["gradeitem-{$context->id}"] ?? null; 'perpage' => $perpage > ); > switch ($itemtype) { > case 'user_select': $PAGE->set_pagelayout('report'); > // If there is a stored user item (last viewed) in a session variable, bypass the user select zero state > // and display this user item. Also, make sure that the stored last viewed user is part of the current $actionbar = new \core_grades\output\general_action_bar($context, > // list of gradable users in this course. new moodle_url('/grade/report/singleview/index.php', ['id' => $courseid]), 'report', 'singleview'); > if ($lastvieweduseritemid && > array_key_exists($lastvieweduseritemid, grade_report::get_gradable_users($courseid, $currentgroup))) { if ($itemtype == 'user') { > $itemtype = 'user'; print_grade_page_head($course->id, 'report', 'singleview', $reportname, false, false, > $itemid = $lastvieweduseritemid; true, null, null, $report->screen->item, $actionbar); > } else { } else { > $itemid = null; print_grade_page_head($course->id, 'report', 'singleview', $reportname, false, false, > } true, null, null, null, $actionbar); > break; } > case 'user': > if (is_null($itemid)) { if ($data = data_submitted()) { > $itemid = $userid ?? $lastvieweduseritemid; // Must have a sesskey for all actions. > } require_sesskey(); > // If the item id (user id) cannot be defined or the user id is not part of the list of gradable users, $result = $report->process_data($data); > // display the user select zero state. > if (is_null($itemid) || !array_key_exists($itemid, grade_report::get_gradable_users($courseid, $currentgroup))) { // If result is not null (because somedata was processed), warnings and success message should be displayed. > $itemtype = 'user_select'; if (!is_null($result)) { > } if (!empty($result->warnings)) { > break; foreach ($result->warnings as $warning) { > case 'grade_select': \core\notification::add($warning); > // If there is a stored grade item (last viewed) in a session variable, bypass the grade item select zero state } > // and display this grade item. } > if ($lastviewedgradeitemid) { > $itemtype = 'grade'; // And notify the user of the success result. > $itemid = $lastviewedgradeitemid; \core\notification::add( > } else { get_string('savegradessuccess', 'gradereport_singleview', count ((array)$result->changecount)), > $itemid = null; \core\notification::SUCCESS > } ); > break; } > case 'grade': } > // If there is a stored grade item (last viewed) in a session variable, use it. > if (is_null($itemid) && $lastviewedgradeitemid) { // Make sure we have proper final grades. > $itemid = $lastviewedgradeitemid; grade_regrade_final_grades_if_required($course); > } > $gtree = new grade_tree($courseid, false, false, null, !$CFG->enableoutcomes); $graderrightnav = $graderleftnav = null; > $gradeableitems = $gtree->get_items(); > // The item id (grade item id) cannot be defined, display the grade select zero state. $options = $report->screen->options(); > if (is_null($itemid) || !array_key_exists($itemid, $gtree->get_items())) { > $itemtype = 'grade_select'; if (!empty($options)) { > } > break; $optionkeys = array_keys($options); > }
< $report = new gradereport_singleview($courseid, $gpr, $context, $itemtype, $itemid); < < $reportname = $report->screen->heading(); < < $pluginname = get_string('pluginname', 'gradereport_singleview');
> $report = new gradereport_singleview\report\singleview($courseid, $gpr, $context, $itemtype, $itemid);
< $pageparams = array(
> $pageparams = [
$reloptions = $relreport->screen->options();
> 'userid' => $userid,
< 'userid' => $userid, < 'group' => $groupid,
< 'perpage' => $perpage < );
> 'perpage' => $perpage, > ];
< $PAGE->set_pagelayout('report');
> if (!is_null($groupid)) { > $pageparams['group'] = $groupid; > }
< $actionbar = new \core_grades\output\general_action_bar($context, < new moodle_url('/grade/report/singleview/index.php', ['id' => $courseid]), 'report', 'singleview');
> $PAGE->set_url(new moodle_url('/grade/report/singleview/index.php', $pageparams)); > > // Build editing on/off button for themes that need it. > $button = ''; > if ($PAGE->user_allowed_editing() && !$PAGE->theme->haseditswitch) { > if ($edit != - 1) { > $USER->editing = $edit; > } > > // Page params for the turn editing on button. > $options = $gpr->get_options(); > $button = $OUTPUT->edit_button(new moodle_url($PAGE->url, $options), 'get'); > } > > $reportname = $report->screen->heading(); > > if ($itemtype == 'user' || $itemtype == 'user_select') { > $actionbar = new \gradereport_singleview\output\action_bar($context, $report, 'user'); > } else if ($itemtype == 'grade' || $itemtype == 'grade_select') { > $actionbar = new \gradereport_singleview\output\action_bar($context, $report, 'grade'); > } else { > $actionbar = new \core_grades\output\general_action_bar($context, new moodle_url('/grade/report/singleview/index.php', > ['id' => $courseid]), 'report', 'singleview'); > }
< print_grade_page_head($course->id, 'report', 'singleview', $reportname, false, false,
> print_grade_page_head($course->id, 'report', 'singleview', $reportname, false, $button,
< print_grade_page_head($course->id, 'report', 'singleview', $reportname, false, false,
> print_grade_page_head($course->id, 'report', 'singleview', $reportname, false, $button,
< $graderrightnav = $graderleftnav = null; < < $options = $report->screen->options(); < < if (!empty($options)) { < < $optionkeys = array_keys($options); < $optionitemid = array_shift($optionkeys); < < $relreport = new gradereport_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 = array('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, array('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, array('class' => 'itemnav nextitem')); < } < } < < if (!is_null($graderleftnav)) { < echo $graderleftnav; < } < if (!is_null($graderrightnav)) { < echo $graderrightnav; < } < < if ($report->screen->supports_paging()) { < echo $report->screen->pager(); < } < < if ($report->screen->display_group_selector()) { < echo $report->group_selector; < } <
< < 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;
> // Save the screen state in a session variable as last viewed state. > $SESSION->gradereport_singleview["itemtype-{$context->id}"] = $itemtype; > if ($itemid) { > $SESSION->gradereport_singleview["{$itemtype}item-{$context->id}"] = $itemid; > } > > if (($itemtype !== 'select') && ($itemtype !== 'grade_select') &&($itemtype !== 'user_select')) { > $item = (isset($userid)) ? $userid : $itemid; > > $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol); > $showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol); > $showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context); > > $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);
< array(
> [
< )
> ]