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.

This commit is contained in:
nicolasconnault
2007-07-20 09:34:35 +00:00
parent 830ba6ea46
commit 90d3960c6d
3 changed files with 78 additions and 60 deletions
+2 -50
View File
@@ -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() {
+69
View File
@@ -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 ";
}
}
}
?>
+7 -10
View File
@@ -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;
// 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));
}
}
?>