mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-18941 group support in user gradebook report; merged from MOODLE_19_STABLE
This commit is contained in:
parent
7b58fb4179
commit
772229f345
@ -265,10 +265,11 @@ class graded_users_iterator {
|
||||
* @param int $courseid id of the course
|
||||
* @param string $actionpage The page receiving the data from the popoup form
|
||||
* @param int $userid id of the currently selected user (or 'all' if they are all selected)
|
||||
* @param int $groupid id of requested group, 0 means all
|
||||
* @param bool $return If true, will return the HTML, otherwise, will print directly
|
||||
* @return null
|
||||
*/
|
||||
function print_graded_users_selector($course, $actionpage, $userid=null, $return=false) {
|
||||
function print_graded_users_selector($course, $actionpage, $userid=null, $groupid=0, $return=false) {
|
||||
global $CFG, $USER;
|
||||
|
||||
if (is_null($userid)) {
|
||||
@ -279,7 +280,7 @@ function print_graded_users_selector($course, $actionpage, $userid=null, $return
|
||||
|
||||
$menu = array(); // Will be a list of userid => user name
|
||||
|
||||
$gui = new graded_users_iterator($course);
|
||||
$gui = new graded_users_iterator($course, null, $groupid);
|
||||
$gui->init();
|
||||
|
||||
if ($userid !== 0) {
|
||||
|
@ -27,7 +27,7 @@ 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');
|
||||
$courseid = required_param('id', PARAM_INT);
|
||||
$userid = optional_param('userid', $USER->id, PARAM_INT);
|
||||
|
||||
/// basic access checks
|
||||
@ -36,31 +36,35 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
||||
}
|
||||
require_login($course);
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
require_capability('gradereport/user:view', $context);
|
||||
|
||||
if (empty($userid)) {
|
||||
require_capability('moodle/grade:viewall', $context);
|
||||
|
||||
} else {
|
||||
if (!get_complete_user_data('id', $userid)) {
|
||||
print_error('invaliduser');
|
||||
if (!get_complete_user_data('id', $userid) or isguestuser($userid)) {
|
||||
print_error('invaliduser');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$access = true;
|
||||
$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', get_context_instance(CONTEXT_USER, $userid)) and $course->showgrades) {
|
||||
// ok - can view grades of this user- parent most probably
|
||||
$access = true;
|
||||
}
|
||||
|
||||
} else {
|
||||
$access = false;
|
||||
if (!$access) {
|
||||
// no access to grades!
|
||||
error("Can not view grades.", $CFG->wwwroot.'/course/view.php?id='.$courseid); //TODO: localize
|
||||
}
|
||||
|
||||
/// return tracking object
|
||||
@ -73,61 +77,78 @@ if (!isset($USER->grade_last_report)) {
|
||||
$USER->grade_last_report[$course->id] = 'user';
|
||||
|
||||
|
||||
if ($access) {
|
||||
//first make sure we have proper final grades - this must be done before constructing of the grade tree
|
||||
grade_regrade_final_grades($courseid);
|
||||
|
||||
//first make sure we have proper final grades - this must be done before constructing of the grade tree
|
||||
grade_regrade_final_grades($courseid);
|
||||
if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all student reports
|
||||
$groupmode = groups_get_course_groupmode($course); // Groups are being used
|
||||
$currentgroup = groups_get_course_group($course, true);
|
||||
|
||||
if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all student reports
|
||||
/// Print graded user selector at the top
|
||||
$user_selector = '<div id="graded_users_selector">';
|
||||
$user_selector .= print_graded_users_selector($course, 'report/user/index.php?id=' . $course->id, $userid, true);
|
||||
$user_selector .= '</div>';
|
||||
$user_selector .= "<p style = 'page-break-after: always;'></p>";
|
||||
if (!$currentgroup) { // To make some other functions work better later
|
||||
$currentgroup = NULL;
|
||||
}
|
||||
|
||||
if ($userid === 0) {
|
||||
$gui = new graded_users_iterator($course);
|
||||
$gui->init();
|
||||
// Add tabs
|
||||
print_grade_page_head($courseid, 'report', 'user');
|
||||
$isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context));
|
||||
|
||||
echo $user_selector.'<br />';
|
||||
while ($userdata = $gui->next_user()) {
|
||||
$user = $userdata->user;
|
||||
$report = new grade_report_user($courseid, $gpr, $context, $user->id);
|
||||
print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user));
|
||||
if ($isseparategroups and (!$currentgroup)) {
|
||||
print_grade_page_head($courseid, 'report', 'user', get_string('modulename', 'gradereport_user'));
|
||||
print_heading(get_string("notingroup"));
|
||||
print_footer($course);
|
||||
exit;
|
||||
}
|
||||
|
||||
/// Print graded user selector at the top
|
||||
$user_selector = '<div id="graded_users_selector">';
|
||||
$user_selector .= print_graded_users_selector($course, 'report/user/index.php?id=' . $course->id, $userid, $currentgroup, true);
|
||||
$user_selector .= '</div>';
|
||||
$user_selector .= "<p style = 'page-break-after: always;'></p>";
|
||||
|
||||
if ($userid === 0) {
|
||||
$gui = new graded_users_iterator($course, null, $currentgroup);
|
||||
$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)));
|
||||
|
||||
echo $user_selector.'<br />';
|
||||
while ($userdata = $gui->next_user()) {
|
||||
$user = $userdata->user;
|
||||
$report = new grade_report_user($courseid, $gpr, $context, $user->id);
|
||||
print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user));
|
||||
|
||||
if ($report->fill_table()) {
|
||||
echo '<br />'.$report->print_table(true);
|
||||
}
|
||||
echo "<p style = 'page-break-after: always;'></p>";
|
||||
}
|
||||
$gui->close();
|
||||
} elseif ($userid) { // Only show one user's report
|
||||
$report = new grade_report_user($courseid, $gpr, $context, $userid);
|
||||
print_grade_page_head($courseid, 'report', 'user', get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user));
|
||||
echo $user_selector;
|
||||
if ($report->fill_table()) {
|
||||
echo '<br />'.$report->print_table(true);
|
||||
}
|
||||
echo "<p style = 'page-break-after: always;'></p>";
|
||||
}
|
||||
} else { //Students will see just their own report
|
||||
|
||||
// Create a report instance
|
||||
$gui->close();
|
||||
} elseif ($userid) { // Only show one user's report
|
||||
$report = new grade_report_user($courseid, $gpr, $context, $userid);
|
||||
|
||||
// print the page
|
||||
print_grade_page_head($courseid, 'report', 'user', get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user));
|
||||
groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0)));
|
||||
|
||||
echo $user_selector;
|
||||
|
||||
if ($currentgroup and !groups_is_member($currentgroup, $userid)) {
|
||||
error('User not member of current group.'); //TODO: localize
|
||||
}
|
||||
if ($report->fill_table()) {
|
||||
echo '<br />'.$report->print_table(true);
|
||||
}
|
||||
}
|
||||
} else { //Students will see just their own report
|
||||
|
||||
} else {
|
||||
// no access to grades!
|
||||
echo "Can not view grades."; //TODO: localize
|
||||
// Create a report instance
|
||||
$report = new grade_report_user($courseid, $gpr, $context, $userid);
|
||||
|
||||
// print the page
|
||||
print_grade_page_head($courseid, 'report', 'user', get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user));
|
||||
|
||||
if ($report->fill_table()) {
|
||||
echo '<br />'.$report->print_table(true);
|
||||
}
|
||||
}
|
||||
|
||||
print_footer($course);
|
||||
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user