2009-07-07 02:26:36 +00:00
|
|
|
<?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/>.
|
2007-06-15 08:24:45 +00:00
|
|
|
|
2012-01-06 11:52:46 +07:00
|
|
|
/**
|
|
|
|
* The gradebook user report
|
|
|
|
*
|
|
|
|
* @package gradereport_user
|
|
|
|
* @copyright 2007 Moodle Pty Ltd (http://moodle.com)
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2007-07-23 22:20:07 +00:00
|
|
|
require_once '../../../config.php';
|
|
|
|
require_once $CFG->libdir.'/gradelib.php';
|
|
|
|
require_once $CFG->dirroot.'/grade/lib.php';
|
|
|
|
require_once $CFG->dirroot.'/grade/report/user/lib.php';
|
2007-07-14 03:46:24 +00:00
|
|
|
|
2009-04-23 19:27:21 +00:00
|
|
|
$courseid = required_param('id', PARAM_INT);
|
2022-09-16 16:14:22 +02:00
|
|
|
$userid = optional_param('userid', null, PARAM_INT);
|
2016-10-10 09:03:11 -04:00
|
|
|
$userview = optional_param('userview', 0, PARAM_INT);
|
2007-07-23 22:20:07 +00:00
|
|
|
|
2022-09-13 11:01:31 +02:00
|
|
|
$PAGE->set_url(new moodle_url('/grade/report/user/index.php', ['id' => $courseid]));
|
2009-10-15 06:58:21 +00:00
|
|
|
|
2016-10-10 09:03:11 -04:00
|
|
|
if ($userview == 0) {
|
|
|
|
$userview = get_user_preferences('gradereport_user_view_user', GRADE_REPORT_USER_VIEW_USER);
|
|
|
|
} else {
|
|
|
|
set_user_preference('gradereport_user_view_user', $userview);
|
|
|
|
}
|
|
|
|
|
2022-09-12 06:29:55 +02:00
|
|
|
// Basic access checks.
|
|
|
|
if (!$course = $DB->get_record('course', ['id' => $courseid])) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('invalidcourseid');
|
2007-07-23 22:20:07 +00:00
|
|
|
}
|
|
|
|
require_login($course);
|
2010-11-05 02:53:47 +00:00
|
|
|
$PAGE->set_pagelayout('report');
|
2007-07-23 22:20:07 +00:00
|
|
|
|
2012-07-24 14:04:40 +08:00
|
|
|
$context = context_course::instance($course->id);
|
2008-01-17 16:25:48 +00:00
|
|
|
require_capability('gradereport/user:view', $context);
|
2008-01-17 15:08:09 +00:00
|
|
|
|
2022-10-21 09:56:19 +03:00
|
|
|
if ($userid === 0) {
|
2008-01-17 16:25:48 +00:00
|
|
|
require_capability('moodle/grade:viewall', $context);
|
2022-09-16 16:14:22 +02:00
|
|
|
} else if ($userid) {
|
2022-09-13 11:01:31 +02:00
|
|
|
if (!$DB->get_record('user', ['id' => $userid, 'deleted' => 0]) || isguestuser($userid)) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('invaliduser');
|
2009-04-23 19:27:21 +00:00
|
|
|
}
|
2008-01-17 16:25:48 +00:00
|
|
|
}
|
2007-07-23 22:20:07 +00:00
|
|
|
|
2009-04-23 19:27:21 +00:00
|
|
|
$access = false;
|
2007-07-23 22:20:07 +00:00
|
|
|
if (has_capability('moodle/grade:viewall', $context)) {
|
2022-09-12 06:29:55 +02:00
|
|
|
// User can view all course grades.
|
2009-04-23 19:27:21 +00:00
|
|
|
$access = true;
|
2022-09-16 16:14:22 +02:00
|
|
|
} else if (($userid == $USER->id || is_null($userid)) && has_capability('moodle/grade:view', $context) && $course->showgrades) {
|
2022-09-12 06:29:55 +02:00
|
|
|
// User can view own grades.
|
2009-04-23 19:27:21 +00:00
|
|
|
$access = true;
|
2022-09-13 11:01:31 +02:00
|
|
|
} else if (has_capability('moodle/grade:viewall', context_user::instance($userid)) && $course->showgrades) {
|
2022-09-12 06:29:55 +02:00
|
|
|
// User can view grades of this user, The user is an parent most probably.
|
2009-04-23 19:27:21 +00:00
|
|
|
$access = true;
|
|
|
|
}
|
2007-07-24 07:45:15 +00:00
|
|
|
|
2009-04-23 19:27:21 +00:00
|
|
|
if (!$access) {
|
2022-09-12 06:29:55 +02:00
|
|
|
// The user has no access to grades.
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('nopermissiontoviewgrades', 'error', $CFG->wwwroot.'/course/view.php?id='.$courseid);
|
2007-06-15 09:13:13 +00:00
|
|
|
}
|
|
|
|
|
2022-09-12 06:29:55 +02:00
|
|
|
// Initialise the grade tracking object.
|
2022-09-13 11:01:31 +02:00
|
|
|
$gpr = new grade_plugin_return(['type' => 'report', 'plugin' => 'user', 'courseid' => $courseid, 'userid' => $userid]);
|
2007-07-23 22:20:07 +00:00
|
|
|
|
2022-09-12 06:29:55 +02:00
|
|
|
// Infer the users previously selected report via session tracking.
|
2007-07-23 22:20:07 +00:00
|
|
|
if (!isset($USER->grade_last_report)) {
|
2022-09-12 06:29:55 +02:00
|
|
|
$USER->grade_last_report = [];
|
2007-07-23 22:20:07 +00:00
|
|
|
}
|
|
|
|
$USER->grade_last_report[$course->id] = 'user';
|
|
|
|
|
2015-02-27 16:33:54 +08:00
|
|
|
// First make sure we have proper final grades.
|
2016-01-29 14:02:03 +08:00
|
|
|
grade_regrade_final_grades_if_required($course);
|
2007-07-23 22:20:07 +00:00
|
|
|
|
2022-10-10 12:15:37 +08:00
|
|
|
$gradesrenderer = $PAGE->get_renderer('core_grades');
|
|
|
|
|
2022-09-12 06:29:55 +02:00
|
|
|
// Teachers will see all student reports.
|
|
|
|
if (has_capability('moodle/grade:viewall', $context)) {
|
|
|
|
// Verify if we are using groups or not.
|
2022-09-16 16:14:22 +02:00
|
|
|
$groupmode = groups_get_course_groupmode($course);
|
2017-10-18 10:19:50 +13:00
|
|
|
$currentgroup = $gpr->groupid;
|
2023-05-16 15:29:55 +08:00
|
|
|
// Conditionally add the group JS if we have groups enabled.
|
|
|
|
if ($groupmode) {
|
|
|
|
$PAGE->requires->js_call_amd('gradereport_user/group', 'init');
|
|
|
|
}
|
2007-07-23 22:20:07 +00:00
|
|
|
|
2022-09-12 06:29:55 +02:00
|
|
|
// To make some other functions work better later.
|
|
|
|
if (!$currentgroup) {
|
2022-09-13 11:01:31 +02:00
|
|
|
$currentgroup = null;
|
2009-04-23 19:27:21 +00:00
|
|
|
}
|
2008-02-04 14:29:45 +00:00
|
|
|
|
2022-09-13 11:01:31 +02:00
|
|
|
$isseparategroups = ($course->groupmode == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $context));
|
2009-02-09 10:49:41 +00:00
|
|
|
|
2022-09-13 11:01:31 +02:00
|
|
|
if ($isseparategroups && (!$currentgroup)) {
|
2022-09-12 06:29:55 +02:00
|
|
|
// No separate group access, The user can view only themselves.
|
2009-05-04 12:55:20 +00:00
|
|
|
$userid = $USER->id;
|
2009-04-23 19:27:21 +00:00
|
|
|
}
|
|
|
|
|
2023-03-29 12:44:39 +08:00
|
|
|
// If there is a stored (last viewed) user in a session variable, bypass the user select zero state and display the
|
|
|
|
// report for that user.
|
|
|
|
$lastvieweduserid = $SESSION->gradereport_user["useritem-{$context->id}"] ?? null;
|
|
|
|
if (is_null($userid) && !is_null($lastvieweduserid)) {
|
|
|
|
$userid = $lastvieweduserid;
|
|
|
|
}
|
|
|
|
|
2023-10-26 12:55:04 +08:00
|
|
|
$gradableusers = grade_report::get_gradable_users($courseid, $currentgroup);
|
2023-03-29 12:44:39 +08:00
|
|
|
// Validate whether the requested user is a valid gradable user in this course. If, not display the user select
|
|
|
|
// zero state.
|
|
|
|
if (empty($gradableusers) || ($userid && !array_key_exists($userid, $gradableusers))) {
|
|
|
|
$userid = null;
|
|
|
|
}
|
|
|
|
|
2013-03-27 10:14:10 +08:00
|
|
|
$defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
|
|
|
|
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
|
|
|
|
$showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context);
|
2016-10-10 09:03:11 -04:00
|
|
|
|
|
|
|
if ($userview == GRADE_REPORT_USER_VIEW_USER) {
|
|
|
|
$viewasuser = true;
|
|
|
|
} else {
|
|
|
|
$viewasuser = false;
|
|
|
|
}
|
|
|
|
|
2022-10-10 12:15:37 +08:00
|
|
|
$gui = new graded_users_iterator($course, null, $currentgroup);
|
|
|
|
$gui->require_active_enrolment($showonlyactiveenrol);
|
|
|
|
$gui->init();
|
|
|
|
|
|
|
|
if (is_null($userid)) { // Zero state.
|
|
|
|
$actionbar = new \gradereport_user\output\action_bar($context, $userview, null, $currentgroup);
|
2022-09-16 16:14:22 +02:00
|
|
|
// Print header.
|
2023-05-09 10:36:00 +10:00
|
|
|
print_grade_page_head($courseid, 'report', 'user', false, false, null, true,
|
2022-10-10 12:15:37 +08:00
|
|
|
null, null, null, $actionbar);
|
2022-09-16 16:14:22 +02:00
|
|
|
|
2023-03-29 12:44:39 +08:00
|
|
|
if (empty($gradableusers)) { // There are no available gradable users, display a notification.
|
|
|
|
$message = $currentgroup ? get_string('nostudentsingroup') : get_string('nostudentsyet');
|
|
|
|
echo $OUTPUT->notification($message, 'warning', false);
|
|
|
|
} else { // Otherwise, display the zero state template.
|
|
|
|
$report = new gradereport_user\report\user($courseid, $gpr, $context, $USER->id, $viewasuser);
|
|
|
|
echo $report->output_report_zerostate();
|
|
|
|
}
|
2022-10-10 12:15:37 +08:00
|
|
|
} else if ($userid == 0) { // Show all reports.
|
2023-03-29 12:44:39 +08:00
|
|
|
// Store the id of the current user item in a session variable which represents the last viewed item.
|
|
|
|
$SESSION->gradereport_user["useritem-{$context->id}"] = $userid;
|
|
|
|
|
2022-10-10 12:15:37 +08:00
|
|
|
$actionbar = new \gradereport_user\output\action_bar($context, $userview, 0, $currentgroup);
|
2023-05-09 10:36:00 +10:00
|
|
|
print_grade_page_head($courseid, 'report', 'user', false, false, null, true,
|
2022-10-10 12:15:37 +08:00
|
|
|
null, null, null, $actionbar);
|
2016-10-10 09:03:11 -04:00
|
|
|
|
2009-04-23 19:27:21 +00:00
|
|
|
while ($userdata = $gui->next_user()) {
|
|
|
|
$user = $userdata->user;
|
2022-09-10 20:46:52 +08:00
|
|
|
$report = new gradereport_user\report\user($courseid, $gpr, $context, $user->id, $viewasuser);
|
2022-10-10 12:15:37 +08:00
|
|
|
$userheading = $gradesrenderer->user_heading($report->user, $courseid, false);
|
2011-12-20 16:02:55 +08:00
|
|
|
|
2023-08-30 20:21:53 +08:00
|
|
|
echo $userheading;
|
2009-02-09 10:49:41 +00:00
|
|
|
|
2008-01-17 15:08:09 +00:00
|
|
|
if ($report->fill_table()) {
|
2022-10-07 23:54:58 +08:00
|
|
|
echo $report->print_table(true);
|
2008-06-03 16:10:57 +00:00
|
|
|
}
|
2008-01-17 15:08:09 +00:00
|
|
|
}
|
2022-10-10 12:15:37 +08:00
|
|
|
} else { // Show one user's report.
|
2023-03-29 12:44:39 +08:00
|
|
|
// Store the id of the current user item in a session variable which represents the last viewed item.
|
|
|
|
$SESSION->gradereport_user["useritem-{$context->id}"] = $userid;
|
|
|
|
|
2022-09-10 20:46:52 +08:00
|
|
|
$report = new gradereport_user\report\user($courseid, $gpr, $context, $userid, $viewasuser);
|
2022-10-10 12:15:37 +08:00
|
|
|
$actionbar = new \gradereport_user\output\action_bar($context, $userview, $report->user->id, $currentgroup);
|
2011-12-12 15:57:04 +08:00
|
|
|
|
2023-08-30 20:21:53 +08:00
|
|
|
print_grade_page_head($courseid, 'report', 'user', false, false, false, true, null, null, $report->user, $actionbar);
|
2016-10-10 09:03:11 -04:00
|
|
|
|
2022-09-13 11:01:31 +02:00
|
|
|
if ($currentgroup && !groups_is_member($currentgroup, $userid)) {
|
2009-08-18 04:59:57 +00:00
|
|
|
echo $OUTPUT->notification(get_string('groupusernotmember', 'error'));
|
2009-04-23 20:29:30 +00:00
|
|
|
} else {
|
|
|
|
if ($report->fill_table()) {
|
2022-10-07 23:54:58 +08:00
|
|
|
echo $report->print_table(true);
|
2009-04-23 20:29:30 +00:00
|
|
|
}
|
2008-01-17 15:08:09 +00:00
|
|
|
}
|
2022-10-10 12:15:37 +08:00
|
|
|
$userreportrenderer = $PAGE->get_renderer('gradereport_user');
|
2023-05-17 22:03:41 +08:00
|
|
|
// Render the user report (previous/next) navigation in a sticky footer.
|
|
|
|
$stickyfooter = new core\output\sticky_footer($userreportrenderer->user_navigation($gui, $userid, $courseid));
|
|
|
|
echo $OUTPUT->render($stickyfooter);
|
2007-07-23 22:20:07 +00:00
|
|
|
}
|
2024-03-15 14:10:28 +00:00
|
|
|
|
|
|
|
$gui->close();
|
2022-09-12 06:29:55 +02:00
|
|
|
} else {
|
2022-09-13 11:01:31 +02:00
|
|
|
// Students will see just their own report.
|
2022-09-12 06:29:55 +02:00
|
|
|
// Create a report instance.
|
2022-09-16 16:14:22 +02:00
|
|
|
$report = new gradereport_user\report\user($courseid, $gpr, $context, $userid ?? $USER->id);
|
2009-04-23 19:27:21 +00:00
|
|
|
|
2022-09-12 06:29:55 +02:00
|
|
|
// Print the page.
|
2023-08-30 20:21:53 +08:00
|
|
|
print_grade_page_head($courseid, 'report', 'user', false, false, false, true, null, null, $report->user);
|
2009-04-23 19:27:21 +00:00
|
|
|
|
|
|
|
if ($report->fill_table()) {
|
2022-10-07 23:54:58 +08:00
|
|
|
echo $report->print_table(true);
|
2009-04-23 19:27:21 +00:00
|
|
|
}
|
2007-07-14 03:46:24 +00:00
|
|
|
}
|
2009-04-23 19:27:21 +00:00
|
|
|
|
2015-08-31 14:48:31 +09:30
|
|
|
if (isset($report)) {
|
2015-10-16 14:28:38 +08:00
|
|
|
// Trigger report viewed event.
|
2015-08-31 14:48:31 +09:30
|
|
|
$report->viewed();
|
|
|
|
}
|
2014-06-13 16:03:54 +08:00
|
|
|
|
2011-01-18 16:24:41 +08:00
|
|
|
echo $OUTPUT->footer();
|