.
/**
* 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
*/
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';
$courseid = required_param('id', PARAM_INT);
$userid = optional_param('userid', $USER->id, PARAM_INT);
$userview = optional_param('userview', 0, PARAM_INT);
$PAGE->set_url(new moodle_url('/grade/report/user/index.php', array('id'=>$courseid)));
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);
}
/// basic access checks
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('invalidcourseid');
}
require_login($course);
$PAGE->set_pagelayout('report');
$context = context_course::instance($course->id);
require_capability('gradereport/user:view', $context);
if (empty($userid)) {
require_capability('moodle/grade:viewall', $context);
} else {
if (!$DB->get_record('user', array('id'=>$userid, 'deleted'=>0)) or isguestuser($userid)) {
print_error('invaliduser');
}
}
$access = false;
if (has_capability('moodle/grade:viewall', $context)) {
//ok - can view all course grades
$access = true;
} else if ($userid == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades) {
//ok - can view own grades
$access = true;
} else if (has_capability('moodle/grade:viewall', context_user::instance($userid)) and $course->showgrades) {
// ok - can view grades of this user- parent most probably
$access = true;
}
if (!$access) {
// no access to grades!
print_error('nopermissiontoviewgrades', 'error', $CFG->wwwroot.'/course/view.php?id='.$courseid);
}
/// return tracking object
$gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'user', 'courseid'=>$courseid, 'userid'=>$userid));
/// last selected report session tracking
if (!isset($USER->grade_last_report)) {
$USER->grade_last_report = array();
}
$USER->grade_last_report[$course->id] = 'user';
// First make sure we have proper final grades.
grade_regrade_final_grades_if_required($course);
if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all student reports
$groupmode = groups_get_course_groupmode($course); // Groups are being used
$currentgroup = $gpr->groupid;
if (!$currentgroup) { // To make some other functions work better later
$currentgroup = NULL;
}
$isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context));
if ($isseparategroups and (!$currentgroup)) {
// no separate group access, can view only self
$userid = $USER->id;
$user_selector = false;
} else {
$user_selector = true;
}
$defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
$showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context);
$renderer = $PAGE->get_renderer('gradereport_user');
if ($userview == GRADE_REPORT_USER_VIEW_USER) {
$viewasuser = true;
} else {
$viewasuser = false;
}
if (empty($userid)) {
$gui = new graded_users_iterator($course, null, $currentgroup);
$gui->require_active_enrolment($showonlyactiveenrol);
$gui->init();
// Add tabs
print_grade_page_head($courseid, 'report', 'user');
groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0)));
if ($user_selector) {
echo $renderer->graded_users_selector('user', $course, $userid, $currentgroup, true);
}
echo $renderer->view_user_selector($userid, $userview);
while ($userdata = $gui->next_user()) {
$user = $userdata->user;
$report = new grade_report_user($courseid, $gpr, $context, $user->id, $viewasuser);
$studentnamelink = html_writer::link(new moodle_url('/user/view.php', array('id' => $report->user->id, 'course' => $courseid)), fullname($report->user));
echo $OUTPUT->heading(get_string('pluginname', 'gradereport_user') . ' - ' . $studentnamelink);
if ($report->fill_table()) {
echo '
'.$report->print_table(true);
}
echo "