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-08-10 09:34:50 +00:00
|
|
|
|
2012-01-06 11:52:46 +07:00
|
|
|
/**
|
|
|
|
* The gradebook overview report
|
|
|
|
*
|
|
|
|
* @package gradereport_overview
|
|
|
|
* @copyright 2007 Nicolas Connault
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2007-08-10 09:34:50 +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/overview/lib.php';
|
|
|
|
|
2015-02-05 14:22:34 +08:00
|
|
|
$courseid = optional_param('id', SITEID, PARAM_INT);
|
2007-08-10 09:34:50 +00:00
|
|
|
$userid = optional_param('userid', $USER->id, PARAM_INT);
|
|
|
|
|
2015-02-05 14:22:34 +08:00
|
|
|
$PAGE->set_url(new moodle_url('/grade/report/overview/index.php', array('id' => $courseid, 'userid' => $userid)));
|
2009-10-15 06:58:21 +00:00
|
|
|
|
2008-06-03 16:10:57 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
2007-08-10 09:34:50 +00:00
|
|
|
print_error('nocourseid');
|
|
|
|
}
|
2015-02-05 14:22:34 +08:00
|
|
|
require_login(null, false);
|
2007-08-10 09:34:50 +00:00
|
|
|
|
2012-07-24 14:04:40 +08:00
|
|
|
$context = context_course::instance($course->id);
|
|
|
|
$systemcontext = context_system::instance();
|
2015-02-05 14:22:34 +08:00
|
|
|
$personalcontext = null;
|
|
|
|
|
|
|
|
// If we are accessing the page from a site context then ignore this check.
|
|
|
|
if ($courseid != SITEID) {
|
|
|
|
require_capability('gradereport/overview:view', $context);
|
|
|
|
}
|
2007-08-10 09:34:50 +00:00
|
|
|
|
2009-04-23 20:29:30 +00:00
|
|
|
if (empty($userid)) {
|
2014-11-10 11:26:42 -05:00
|
|
|
require_capability('moodle/grade:viewall', $context);
|
2009-04-23 20:29:30 +00:00
|
|
|
|
|
|
|
} else {
|
2009-04-30 20:09:23 +00:00
|
|
|
if (!$DB->get_record('user', array('id'=>$userid, 'deleted'=>0)) or isguestuser($userid)) {
|
2009-09-30 07:20:31 +00:00
|
|
|
print_error('invaliduserid');
|
2009-04-23 20:29:30 +00:00
|
|
|
}
|
2015-02-05 14:22:34 +08:00
|
|
|
$personalcontext = context_user::instance($userid);
|
2009-04-23 20:29:30 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 13:13:07 +08:00
|
|
|
if (isset($personalcontext)) {
|
|
|
|
$PAGE->set_context($personalcontext);
|
|
|
|
} else {
|
|
|
|
$PAGE->set_context($context);
|
|
|
|
}
|
2015-03-19 10:59:27 +08:00
|
|
|
$settings = $PAGE->settingsnav->find('mygrades', null);
|
|
|
|
$settings->make_active();
|
2015-03-16 13:13:07 +08:00
|
|
|
|
2009-04-23 20:29:30 +00:00
|
|
|
$access = false;
|
2009-09-26 18:50:08 +00:00
|
|
|
if (has_capability('moodle/grade:viewall', $systemcontext)) {
|
2014-11-10 11:26:42 -05:00
|
|
|
// Ok - can view all course grades.
|
2009-04-23 20:29:30 +00:00
|
|
|
$access = true;
|
2007-08-10 09:34:50 +00:00
|
|
|
|
2014-11-10 11:26:42 -05:00
|
|
|
} else if (has_capability('moodle/grade:viewall', $context)) {
|
|
|
|
// Ok - can view any grades in context.
|
2009-09-26 18:50:08 +00:00
|
|
|
$access = true;
|
2009-11-01 12:11:29 +00:00
|
|
|
|
2015-02-05 14:22:34 +08:00
|
|
|
} else if ($userid == $USER->id and ((has_capability('moodle/grade:view', $context) and $course->showgrades)
|
|
|
|
|| $courseid == SITEID)) {
|
2014-11-10 11:26:42 -05:00
|
|
|
// Ok - can view own course grades.
|
2009-04-23 20:29:30 +00:00
|
|
|
$access = true;
|
2007-08-10 09:34:50 +00:00
|
|
|
|
2015-02-05 14:22:34 +08:00
|
|
|
} else if (has_capability('moodle/grade:viewall', $personalcontext) and $course->showgrades) {
|
|
|
|
// Ok - can view grades of this user - parent most probably.
|
|
|
|
$access = true;
|
|
|
|
} else if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and $course->showgrades) {
|
|
|
|
// Ok - can view grades of this user - parent most probably.
|
2009-04-23 20:29:30 +00:00
|
|
|
$access = true;
|
|
|
|
}
|
2007-08-10 09:34:50 +00:00
|
|
|
|
2009-04-23 20:29:30 +00:00
|
|
|
if (!$access) {
|
|
|
|
// no access to grades!
|
2009-09-30 07:20:31 +00:00
|
|
|
print_error('nopermissiontoviewgrades', 'error', $CFG->wwwroot.'/course/view.php?id='.$courseid);
|
2007-08-10 09:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// return tracking object
|
2007-08-10 14:58:21 +00:00
|
|
|
$gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'overview', 'courseid'=>$course->id, 'userid'=>$userid));
|
2007-08-10 09:34:50 +00:00
|
|
|
|
|
|
|
/// last selected report session tracking
|
|
|
|
if (!isset($USER->grade_last_report)) {
|
|
|
|
$USER->grade_last_report = array();
|
|
|
|
}
|
2007-08-10 14:58:21 +00:00
|
|
|
$USER->grade_last_report[$course->id] = 'overview';
|
2007-08-10 09:34:50 +00:00
|
|
|
|
2009-04-23 20:29:30 +00:00
|
|
|
//first make sure we have proper final grades - this must be done before constructing of the grade tree
|
|
|
|
grade_regrade_final_grades($courseid);
|
|
|
|
|
2015-02-05 14:22:34 +08:00
|
|
|
if (has_capability('moodle/grade:viewall', $context) && $courseid != SITEID) {
|
2014-11-10 11:26:42 -05:00
|
|
|
// Please note this would be extremely slow if we wanted to implement this properly for all teachers.
|
2009-04-23 20:29:30 +00:00
|
|
|
$groupmode = groups_get_course_groupmode($course); // Groups are being used
|
|
|
|
$currentgroup = groups_get_course_group($course, true);
|
2007-08-10 09:34:50 +00:00
|
|
|
|
2009-04-23 20:29:30 +00:00
|
|
|
if (!$currentgroup) { // To make some other functions work better later
|
|
|
|
$currentgroup = NULL;
|
|
|
|
}
|
2007-08-10 09:34:50 +00:00
|
|
|
|
2009-04-23 20:29:30 +00:00
|
|
|
$isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context));
|
|
|
|
|
|
|
|
if ($isseparategroups and (!$currentgroup)) {
|
2009-05-04 12:55:20 +00:00
|
|
|
// no separate group access, can view only self
|
|
|
|
$userid = $USER->id;
|
2010-05-05 03:27:22 +00:00
|
|
|
$user_selector = false;
|
2009-05-04 12:55:20 +00:00
|
|
|
} else {
|
2010-05-05 03:27:22 +00:00
|
|
|
$user_selector = true;
|
2009-04-23 20:29:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($userid)) {
|
|
|
|
// Add tabs
|
|
|
|
print_grade_page_head($courseid, 'report', 'overview');
|
2010-05-05 03:27:22 +00:00
|
|
|
|
2009-04-23 20:29:30 +00:00
|
|
|
groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0)));
|
2010-05-05 03:27:22 +00:00
|
|
|
|
|
|
|
if ($user_selector) {
|
|
|
|
$renderer = $PAGE->get_renderer('gradereport_overview');
|
|
|
|
echo $renderer->graded_users_selector('overview', $course, $userid, $currentgroup, false);
|
|
|
|
}
|
2009-04-23 20:29:30 +00:00
|
|
|
// do not list all users
|
|
|
|
|
|
|
|
} else { // Only show one user's report
|
|
|
|
$report = new grade_report_overview($userid, $gpr, $context);
|
2015-03-05 11:45:29 +08:00
|
|
|
print_grade_page_head($courseid, 'report', 'overview', get_string('pluginname', 'gradereport_overview') .
|
|
|
|
' - ' . fullname($report->user), false, false, true, null, null, $report->user);
|
2009-04-23 20:29:30 +00:00
|
|
|
groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0)));
|
|
|
|
|
2010-05-05 03:27:22 +00:00
|
|
|
if ($user_selector) {
|
|
|
|
$renderer = $PAGE->get_renderer('gradereport_overview');
|
|
|
|
echo $renderer->graded_users_selector('overview', $course, $userid, $currentgroup, false);
|
|
|
|
}
|
2009-04-23 20:29:30 +00:00
|
|
|
|
|
|
|
if ($currentgroup and !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()) {
|
|
|
|
echo '<br />'.$report->print_table(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-05 14:22:34 +08:00
|
|
|
} else { // Non-admins and users viewing from the site context can just see their own report.
|
2007-08-10 09:34:50 +00:00
|
|
|
|
|
|
|
// Create a report instance
|
|
|
|
$report = new grade_report_overview($userid, $gpr, $context);
|
2009-04-23 20:29:30 +00:00
|
|
|
|
2015-02-05 14:22:34 +08:00
|
|
|
// If the course id matches the site id then we don't have a course context to work with.
|
|
|
|
// Display a standard page.
|
|
|
|
if ($courseid == SITEID) {
|
|
|
|
$PAGE->set_pagelayout('standard');
|
2015-03-16 13:13:07 +08:00
|
|
|
$header = get_string('mygrades', 'grades') . ' - ' . fullname($report->user);
|
2015-02-05 14:22:34 +08:00
|
|
|
$PAGE->set_title($header);
|
2015-03-16 13:13:07 +08:00
|
|
|
$PAGE->set_heading(fullname($report->user));
|
2015-02-05 14:22:34 +08:00
|
|
|
|
|
|
|
if ($USER->id != $report->user->id) {
|
|
|
|
$PAGE->navigation->extend_for_user($report->user);
|
|
|
|
if ($node = $PAGE->settingsnav->get('userviewingsettings'.$report->user->id)) {
|
|
|
|
$node->forceopen = true;
|
|
|
|
}
|
|
|
|
} else if ($node = $PAGE->settingsnav->get('usercurrentsettings', navigation_node::TYPE_CONTAINER)) {
|
|
|
|
$node->forceopen = true;
|
|
|
|
}
|
2007-08-10 09:34:50 +00:00
|
|
|
|
2015-02-05 14:22:34 +08:00
|
|
|
echo $OUTPUT->header();
|
|
|
|
if ($report->fill_table(true)) {
|
|
|
|
echo '<br />'.$report->print_table(true);
|
|
|
|
}
|
|
|
|
} else { // We have a course context. We must be navigating from the gradebook.
|
|
|
|
print_grade_page_head($courseid, 'report', 'overview', get_string('pluginname', 'gradereport_overview')
|
|
|
|
. ' - ' . fullname($report->user));
|
|
|
|
if ($report->fill_table()) {
|
|
|
|
echo '<br />'.$report->print_table(true);
|
|
|
|
}
|
2007-08-10 09:34:50 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-23 20:29:30 +00:00
|
|
|
|
2014-08-05 19:40:03 -07:00
|
|
|
$event = \gradereport_overview\event\grade_report_viewed::create(
|
2014-06-13 16:03:54 +08:00
|
|
|
array(
|
|
|
|
'context' => $context,
|
|
|
|
'courseid' => $courseid,
|
|
|
|
'relateduserid' => $userid,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$event->trigger();
|
|
|
|
|
2009-08-06 14:12:17 +00:00
|
|
|
echo $OUTPUT->footer();
|
2007-08-10 09:34:50 +00:00
|
|
|
|
2009-09-26 18:50:08 +00:00
|
|
|
|