mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-18942 user selection and group support in gradebook user overview report; merged from MOODLE_19_STABLE
This commit is contained in:
parent
81f4918e0c
commit
7ac88172fc
@ -266,10 +266,11 @@ class graded_users_iterator {
|
||||
* @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 int $includeall bool include all option
|
||||
* @param bool $return If true, will return the HTML, otherwise, will print directly
|
||||
* @return null
|
||||
*/
|
||||
function print_graded_users_selector($course, $actionpage, $userid=null, $groupid=0, $return=false) {
|
||||
function print_graded_users_selector($course, $actionpage, $userid=0, $groupid=0, $includeall=true, $return=false) {
|
||||
global $CFG, $USER;
|
||||
|
||||
if (is_null($userid)) {
|
||||
@ -283,7 +284,7 @@ function print_graded_users_selector($course, $actionpage, $userid=null, $groupi
|
||||
$gui = new graded_users_iterator($course, null, $groupid);
|
||||
$gui->init();
|
||||
|
||||
if ($userid !== 0) {
|
||||
if ($includeall) {
|
||||
$menu[0] = get_string('allusers', 'grades');
|
||||
}
|
||||
|
||||
@ -296,7 +297,7 @@ function print_graded_users_selector($course, $actionpage, $userid=null, $groupi
|
||||
|
||||
$gui->close();
|
||||
|
||||
if ($userid !== 0) {
|
||||
if ($includeall) {
|
||||
$menu[0] .= " (" . (count($menu) - 1) . ")";
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ require_once $CFG->libdir.'/gradelib.php';
|
||||
require_once $CFG->dirroot.'/grade/lib.php';
|
||||
require_once $CFG->dirroot.'/grade/report/overview/lib.php';
|
||||
|
||||
$courseid = optional_param('id', $COURSE->id, PARAM_INT);
|
||||
$courseid = required_param('id', PARAM_INT);
|
||||
$userid = optional_param('userid', $USER->id, PARAM_INT);
|
||||
|
||||
/// basic access checks
|
||||
@ -36,26 +36,35 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
||||
}
|
||||
require_login($course);
|
||||
|
||||
if (!$user = get_complete_user_data('id', $userid)) {
|
||||
print_error('invaliduser');
|
||||
}
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $user->id);
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
require_capability('gradereport/overview:view', $context);
|
||||
|
||||
$access = true;
|
||||
if (has_capability('moodle/grade:viewall', $context)) {
|
||||
//ok - can view all course grades
|
||||
|
||||
} else if ($user->id == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades) {
|
||||
//ok - can view own grades
|
||||
|
||||
} else if (has_capability('moodle/grade:viewall', $usercontext) and $course->showgrades) {
|
||||
// ok - can view grades of this user- parent most probably
|
||||
if (empty($userid)) {
|
||||
require_capability('moodle/grade:viewall', $context);
|
||||
|
||||
} else {
|
||||
$access = false;
|
||||
if (!get_complete_user_data('id', $userid) or isguestuser($userid)) {
|
||||
error("Incorrect userid");
|
||||
}
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
if (!$access) {
|
||||
// no access to grades!
|
||||
error("Can not view grades.", $CFG->wwwroot.'/course/view.php?id='.$courseid); //TODO: localize
|
||||
}
|
||||
|
||||
/// return tracking object
|
||||
@ -67,33 +76,67 @@ if (!isset($USER->grade_last_report)) {
|
||||
}
|
||||
$USER->grade_last_report[$course->id] = 'overview';
|
||||
|
||||
//first make sure we have proper final grades - this must be done before constructing of the grade tree
|
||||
grade_regrade_final_grades($courseid);
|
||||
|
||||
if ($access) {
|
||||
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);
|
||||
|
||||
//first make sure we have proper final grades - this must be done before constructing of the grade tree
|
||||
grade_regrade_final_grades($course->id);
|
||||
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)) {
|
||||
print_grade_page_head($courseid, 'report', 'overview', get_string('modulename', 'gradereport_overview'));
|
||||
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/overview/index.php?id=' . $course->id, $userid, $currentgroup, false, true);
|
||||
$user_selector .= '</div>';
|
||||
$user_selector .= "<p style = 'page-break-after: always;'></p>";
|
||||
|
||||
if (empty($userid)) {
|
||||
// Add tabs
|
||||
print_grade_page_head($courseid, 'report', 'overview');
|
||||
groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0)));
|
||||
echo $user_selector.'<br />';
|
||||
// do not list all users
|
||||
|
||||
} else { // Only show one user's report
|
||||
$report = new grade_report_overview($userid, $gpr, $context);
|
||||
print_grade_page_head($courseid, 'report', 'overview', get_string('modulename', 'gradereport_overview'). ' - '.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)) {
|
||||
notify(get_string('groupusernotmember', 'error'));
|
||||
} else {
|
||||
if ($report->fill_table()) {
|
||||
echo '<br />'.$report->print_table(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { //Students will see just their own report
|
||||
|
||||
// Create a report instance
|
||||
$report = new grade_report_overview($userid, $gpr, $context);
|
||||
|
||||
// print the page
|
||||
print_grade_page_head($courseid, 'report', 'overview', get_string('modulename', 'gradereport_overview'). ' - '.fullname($report->user));
|
||||
|
||||
if ($report->fill_table()) {
|
||||
echo $report->print_table(true);
|
||||
echo '<br />'.$report->print_table(true);
|
||||
}
|
||||
|
||||
} else {
|
||||
// no access to grades!
|
||||
/// Print header
|
||||
/// Build navigation
|
||||
$strgrades = get_string('grades');
|
||||
$reportname = get_string('modulename', 'gradereport_overview');
|
||||
|
||||
$navigation = grade_build_nav(__FILE__, $reportname, $course->id);
|
||||
print_header_simple($strgrades.': '.$reportname, ': '.$strgrades, $navigation,
|
||||
'', '', true, '', navmenu($course));
|
||||
|
||||
echo "Can not view grades."; //TODO: localize
|
||||
}
|
||||
|
||||
print_footer($course);
|
||||
|
||||
?>
|
||||
|
@ -99,11 +99,11 @@ if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all
|
||||
|
||||
/// 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 .= print_graded_users_selector($course, 'report/user/index.php?id=' . $course->id, $userid, $currentgroup, true, true);
|
||||
$user_selector .= '</div>';
|
||||
$user_selector .= "<p style = 'page-break-after: always;'></p>";
|
||||
|
||||
if ($userid === 0) {
|
||||
if (empty($userid)) {
|
||||
$gui = new graded_users_iterator($course, null, $currentgroup);
|
||||
$gui->init();
|
||||
// Add tabs
|
||||
@ -122,7 +122,7 @@ if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all
|
||||
echo "<p style = 'page-break-after: always;'></p>";
|
||||
}
|
||||
$gui->close();
|
||||
} elseif ($userid) { // Only show one user's report
|
||||
} else { // 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));
|
||||
groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0)));
|
||||
@ -130,10 +130,11 @@ if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all
|
||||
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);
|
||||
notify(get_string('groupusernotmember', 'error'));
|
||||
} else {
|
||||
if ($report->fill_table()) {
|
||||
echo '<br />'.$report->print_table(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { //Students will see just their own report
|
||||
|
@ -237,6 +237,7 @@ $string['groupiddoesntexistcannotdelete'] = 'Cannot delete group: group id doesn
|
||||
$string['groupexistforcourse'] = 'Group \"$a\" already exists for this course';
|
||||
$string['groupnotaddederror'] = 'Group \"$a\" not added';
|
||||
$string['groupunknown'] = 'Group $a not associated to specified course';
|
||||
$string['groupusernotmember'] = 'User is not member of this group.';
|
||||
$string['guestnocomment'] = 'Guests are not allowed to post comments!';
|
||||
$string['guestnoeditprofile'] = 'The guest user cannot edit their profile';
|
||||
$string['guestnoeditprofileother'] = 'The guest user profile cannot be edited';
|
||||
|
Loading…
x
Reference in New Issue
Block a user