From: nicolasconnault Date: Fri, 20 Jul 2007 09:34:35 +0000 (+0000) Subject: MDL-9633 Fixed ranking in user report. Also enabled group mode on/off to alter total... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=90d3960c6d4fde7c5c9c66eba3720965a13bb09f;p=moodle.git MDL-9633 Fixed ranking in user report. Also enabled group mode on/off to alter total users. This required a refactoring of the grouping code into grade_report abstract class. --- diff --git a/grade/report/grader/lib.php b/grade/report/grader/lib.php index f8686395b5..b0dede1fad 100644 --- a/grade/report/grader/lib.php +++ b/grade/report/grader/lib.php @@ -51,33 +51,6 @@ class grade_report_grader extends grade_report { */ var $userselect; -//// GROUP VARIABLES (including SQL) - - /** - * The current group being displayed. - * @var int $currentgroup - */ - var $currentgroup; - - /** - * A HTML select element used to select the current group. - * @var string $group_selector - */ - var $group_selector; - - /** - * An SQL fragment used to add linking information to the group tables. - * @var string $groupsql - */ - var $groupsql; - - /** - * An SQL constraint to append to the queries used by this object to build the report. - * @var string $groupwheresql - */ - var $groupwheresql; - - /** * Constructor. Sets local copies of user preferences and initialises grade_tree. * @param int $courseid @@ -99,6 +72,7 @@ class grade_report_grader extends grade_report { $this->pbarurl = 'report.php?id='.$this->courseid.'&perpage='.$this->get_pref('studentsperpage') .'&report=grader&'; + // Setup groups if requested if ($this->get_pref('showgroups')) { $this->setup_groups(); } @@ -178,28 +152,6 @@ class grade_report_grader extends grade_report { return true; } - /** - * Sets up this object's group variables, mainly to restrict the selection of users to display. - */ - function setup_groups() { - global $CFG; - - /// find out current groups mode - $course = get_record('course', 'id', $this->courseid); - $groupmode = $course->groupmode; - ob_start(); - $this->currentgroup = setup_and_print_groups($course, $groupmode, $this->pbarurl); - $this->group_selector = ob_get_clean(); - - // update paging after group - $this->baseurl .= 'group='.$this->currentgroup.'&'; - $this->pbarurl .= 'group='.$this->currentgroup.'&'; - - if ($this->currentgroup) { - $this->groupsql = " LEFT JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id "; - $this->groupwheresql = " AND gm.groupid = $this->currentgroup "; - } - } /** * Setting the sort order, this depends on last state @@ -287,7 +239,7 @@ class grade_report_grader extends grade_report { } /** - * Fetches and returns a count of all the users that will be shows on this page. + * Fetches and returns a count of all the users that will be shown on this page. * @return int Count of users */ function get_numusers() { diff --git a/grade/report/lib.php b/grade/report/lib.php index 5c97991031..f540c9aa64 100755 --- a/grade/report/lib.php +++ b/grade/report/lib.php @@ -69,6 +69,33 @@ class grade_report { */ var $lang_strings = array(); +//// GROUP VARIABLES (including SQL) + + /** + * The current group being displayed. + * @var int $currentgroup + */ + var $currentgroup; + + /** + * A HTML select element used to select the current group. + * @var string $group_selector + */ + var $group_selector; + + /** + * An SQL fragment used to add linking information to the group tables. + * @var string $groupsql + */ + var $groupsql; + + /** + * An SQL constraint to append to the queries used by this object to build the report. + * @var string $groupwheresql + */ + var $groupwheresql; + + /** * Constructor. Sets local copies of user preferences and initialises grade_tree. * @param int $courseid @@ -89,6 +116,7 @@ class grade_report { // Grab the grade_tree for this course $this->gtree = new grade_tree($this->courseid, true, $this->get_pref('aggregationposition')); + } /** @@ -320,5 +348,46 @@ class grade_report { } return $letters; } + + /** + * Fetches and returns a count of all the users that will be shown on this page. + * @return int Count of users + */ + function get_numusers() { + global $CFG; + + $countsql = "SELECT COUNT(DISTINCT u.id) + FROM {$CFG->prefix}grade_grades g RIGHT OUTER JOIN + {$CFG->prefix}user u ON u.id = g.userid + LEFT JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid + $this->groupsql + WHERE ra.roleid in ($this->gradebookroles) + $this->groupwheresql + AND ra.contextid ".get_related_contexts_string($this->context); + return count_records_sql($countsql); + } + + /** + * Sets up this object's group variables, mainly to restrict the selection of users to display. + */ + function setup_groups() { + global $CFG; + + /// find out current groups mode + $course = get_record('course', 'id', $this->courseid); + $groupmode = $course->groupmode; + ob_start(); + $this->currentgroup = setup_and_print_groups($course, $groupmode, $this->pbarurl); + $this->group_selector = ob_get_clean(); + + // update paging after group + $this->baseurl .= 'group='.$this->currentgroup.'&'; + $this->pbarurl .= 'group='.$this->currentgroup.'&'; + + if ($this->currentgroup) { + $this->groupsql = " LEFT JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id "; + $this->groupwheresql = " AND gm.groupid = $this->currentgroup "; + } + } } ?> diff --git a/grade/report/user/lib.php b/grade/report/user/lib.php index deca3792ae..3d5fc38dd2 100644 --- a/grade/report/user/lib.php +++ b/grade/report/user/lib.php @@ -42,9 +42,14 @@ class grade_report_user extends grade_report { // base url for sorting by first/last name $this->baseurl = $CFG->wwwroot.'/grade/report?id='.$courseid.'&userid='.$userid; + $this->pbarurl = $this->baseurl; - $this->setup_table(); + // Setup groups if requested + if ($this->get_pref('showgroups')) { + $this->setup_groups(); + } + $this->setup_table(); } /** @@ -87,6 +92,7 @@ class grade_report_user extends grade_report { function fill_table() { global $CFG; + $numusers = $this->get_numusers(); if ($all_grade_items = grade_item::fetch_all(array('courseid'=>$this->courseid))) { $grade_items = array(); @@ -226,14 +232,5 @@ class grade_report_user extends grade_report { function process_data($data) { } - /** - * Fetches and returns a count of all the users that will be shows on this page. - * @return int Count of users - */ - function get_numusers() { - global $CFG; - return count(get_role_users(@implode(',', $CFG->gradebookroles), $this->context)); - } - } ?>