From 7ac88172fcad1c4af8219ad163f67f8d62141ba2 Mon Sep 17 00:00:00 2001 From: skodak Date: Thu, 23 Apr 2009 20:29:30 +0000 Subject: [PATCH] MDL-18942 user selection and group support in gradebook user overview report; merged from MOODLE_19_STABLE --- grade/lib.php | 7 +- grade/report/overview/index.php | 111 ++++++++++++++++++++++---------- grade/report/user/index.php | 15 +++-- lang/en_utf8/error.php | 1 + 4 files changed, 90 insertions(+), 44 deletions(-) diff --git a/grade/lib.php b/grade/lib.php index c5c787dcc4d..2b131848109 100644 --- a/grade/lib.php +++ b/grade/lib.php @@ -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) . ")"; } diff --git a/grade/report/overview/index.php b/grade/report/overview/index.php index 7aa93baf028..708887c3d02 100644 --- a/grade/report/overview/index.php +++ b/grade/report/overview/index.php @@ -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 = '
'; + $user_selector .= print_graded_users_selector($course, 'report/overview/index.php?id=' . $course->id, $userid, $currentgroup, false, true); + $user_selector .= '
'; + $user_selector .= "

"; + + 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.'
'; + // 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 '
'.$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 '
'.$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); ?> diff --git a/grade/report/user/index.php b/grade/report/user/index.php index 241142b8422..06beca3e7c9 100644 --- a/grade/report/user/index.php +++ b/grade/report/user/index.php @@ -99,11 +99,11 @@ if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all /// Print graded user selector at the top $user_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 .= '
'; $user_selector .= "

"; - 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 "

"; } $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 '
'.$report->print_table(true); + notify(get_string('groupusernotmember', 'error')); + } else { + if ($report->fill_table()) { + echo '
'.$report->print_table(true); + } } } } else { //Students will see just their own report diff --git a/lang/en_utf8/error.php b/lang/en_utf8/error.php index 49f1cc8933d..2afdc6d16c3 100644 --- a/lang/en_utf8/error.php +++ b/lang/en_utf8/error.php @@ -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';