]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9633 Fixed ranking in user report. Also enabled group mode on/off to alter total...
authornicolasconnault <nicolasconnault>
Fri, 20 Jul 2007 09:34:35 +0000 (09:34 +0000)
committernicolasconnault <nicolasconnault>
Fri, 20 Jul 2007 09:34:35 +0000 (09:34 +0000)
grade/report/grader/lib.php
grade/report/lib.php
grade/report/user/lib.php

index f8686395b5f6fff1ea4d1c339754de11da326ae2..b0dede1fad6354c39c17b9b63547c1b1fe06fe64 100644 (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.'&amp;perpage='.$this->get_pref('studentsperpage')
                         .'&amp;report=grader&amp;';
 
+        // 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.'&amp;';
-        $this->pbarurl .= 'group='.$this->currentgroup.'&amp;';
-
-        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() {
index 5c9799103173d1ae3d65f5606966d9a0dd200b12..f540c9aa6417fb49ea4f169ee809d9659475c33e 100755 (executable)
@@ -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.'&amp;';
+        $this->pbarurl .= 'group='.$this->currentgroup.'&amp;';
+
+        if ($this->currentgroup) {
+            $this->groupsql = " LEFT JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id ";
+            $this->groupwheresql = " AND gm.groupid = $this->currentgroup ";
+        }
+    }
 }
 ?>
index deca3792ae3054d2ca0815c455da890509497127..3d5fc38dd2e2f1fac30a6fb9677bef9142f4caab 100644 (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.'&amp;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));
-    }
-
 }
 ?>