]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12122 Completed the change to a more useful user report for the admin, with a...
authornicolasconnault <nicolasconnault>
Thu, 17 Jan 2008 15:08:09 +0000 (15:08 +0000)
committernicolasconnault <nicolasconnault>
Thu, 17 Jan 2008 15:08:09 +0000 (15:08 +0000)
grade/lib.php
grade/report/user/index.php
grade/report/user/styles.php
lang/en_utf8/grades.php

index a5a6ace97acf67534ffd705d999791fa20d5a837..244e360ee5ddd0f4f7cb44d6ac8efb3d5b845f47 100644 (file)
@@ -36,17 +36,29 @@ class graded_users_iterator {
     var $users_rs;
     var $grades_rs;
     var $gradestack;
+    var $sortfield1;
+    var $sortorder1;
+    var $sortfield2;
+    var $sortorder2;
 
     /**
      * Constructor
-     * @param $coruse object
+     * @param $course object
      * @param array grade_items array of grade items, if not specified only user info returned
      * @param int $groupid iterate only group users if present
+     * @param string $sortfield1 The first field of the users table by which the array of users will be sorted
+     * @param string $sortorder1 The order in which the first sorting field will be sorted (ASC or DESC)
+     * @param string $sortfield2 The second field of the users table by which the array of users will be sorted
+     * @param string $sortorder2 The order in which the second sorting field will be sorted (ASC or DESC)
      */
-    function graded_users_iterator($course, $grade_items=null, $groupid=0) {
+    function graded_users_iterator($course, $grade_items=null, $groupid=0, $sortfield1='lastname', $sortorder1='ASC', $sortfield2='firstname', $sortorder2='ASC') {
         $this->course      = $course;
         $this->grade_items = $grade_items;
         $this->groupid     = $groupid;
+        $this->sortfield1  = $sortfield1;
+        $this->sortorder1  = $sortorder1;
+        $this->sortfield2  = $sortfield2;
+        $this->sortorder2  = $sortorder2;
 
         $this->gradestack  = array();
     }
@@ -89,8 +101,16 @@ class graded_users_iterator {
                              $groupsql
                        WHERE ra.roleid $gradebookroles
                              AND ra.contextid $relatedcontexts
-                             $groupwheresql
-                    ORDER BY u.id ASC";
+                             $groupwheresql";
+        
+        // If only sortfield2 is given, it will be ignored
+        if (!empty($this->sortfield1)) {
+            $users_sql .= "ORDER BY u.$this->sortfield1 $this->sortorder1";
+            if (!empty($this->sortfield2)) {
+                $users_sql .= ", $this->sortfield2 $this->sortorder2";
+            }
+        } 
+
         $this->users_rs  = get_recordset_sql($users_sql);
 
         if (!empty($this->grade_items)) {
@@ -109,10 +129,21 @@ class graded_users_iterator {
                          ORDER BY g.userid ASC, g.itemid ASC";
             $this->grades_rs = get_recordset_sql($grades_sql);
         }
-
         return true;
     }
 
+    /**
+     * Returns the number of graded users in the course. Needs to be called after init(), otherwise returns null.
+     * @return int Number of users in course
+     */
+    function users_count() {
+        if (method_exists($this->users_rs, 'RecordCount')) {
+            return $this->users_rs->RecordCount();
+        } else {
+            return null;
+        }
+    }
+
     /**
      * Returns information about the next user
      * @return mixed array of user info, all grades and feedback or null when no more users found
@@ -149,6 +180,7 @@ class graded_users_iterator {
         $grades = array();
         $feedbacks = array();
 
+        if (!empty($this->grade_items)) {
         foreach ($this->grade_items as $grade_item) {
             if (array_key_exists($grade_item->id, $grade_records)) {
                 $feedbacks[$grade_item->id]->feedback       = $grade_records[$grade_item->id]->feedback;
@@ -162,6 +194,7 @@ class graded_users_iterator {
                 $grades[$grade_item->id] = new grade_grade(array('userid'=>$user->id, 'itemid'=>$grade_item->id), false);
             }
         }
+        }
 
         $result = new object();
         $result->user      = $user;
@@ -214,6 +247,40 @@ class graded_users_iterator {
     }
 }
 
+/**
+ * Print a selection popup form of the graded users in a course.
+ *
+ * @param int $courseid id of the course
+ * @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 bool $return If true, will return the HTML, otherwise, will print directly
+ * @return null
+ */
+function print_graded_users_selector($course, $actionpage, $userid='all', $return=false) {
+    global $CFG;
+
+    $context = get_context_instance(CONTEXT_COURSE, $course->id);
+
+    $menu = array(); // Will be a list of userid => user name
+
+    $gui = new graded_users_iterator($course);
+    $gui->init();
+    
+    if ($userid != 'all') {
+        $menu['all'] = get_string('allusers', 'grades') . ' (' . $gui->users_count() . ')';
+    }
+    
+    while ($userdata = $gui->next_user()) {
+        $user = $userdata->user;
+        $menu[$user->id] = fullname($user);
+    }
+
+    $gui->close();
+
+    return popup_form($CFG->wwwroot.'/grade/' . $actionpage . '&amp;userid=', $menu, 'choosegradeduser', $userid, 'choose', '', '', 
+                        $return, 'self', get_string('selectalloroneuser', 'grades')); 
+}
+
 /**
  * Print grading plugin selection popup form.
  *
index d08f7019673c6e97b64cbb54b832f03269c79d2c..498b626a08e40a53f50b9931eae92a968eae9347 100644 (file)
@@ -28,7 +28,7 @@ require_once $CFG->dirroot.'/grade/lib.php';
 require_once $CFG->dirroot.'/grade/report/user/lib.php';
 
 $courseid = required_param('id');
-$userid   = optional_param('userid', $USER->id, PARAM_INT);
+$userid   = optional_param('userid', $USER->id, PARAM_ALPHANUM);
 
 /// basic access checks
 if (!$course = get_record('course', 'id', $courseid)) {
@@ -36,19 +36,20 @@ if (!$course = get_record('course', 'id', $courseid)) {
 }
 require_login($course);
 
-if (!$user = get_complete_user_data('id', $userid)) {
+
+if ($userid != 'all' && !$user = get_complete_user_data('id', $userid)) {
     error("Incorrect userid");
 }
 
 $context     = get_context_instance(CONTEXT_COURSE, $course->id);
-$usercontext = get_context_instance(CONTEXT_USER, $user->id);
+$usercontext = get_context_instance(CONTEXT_USER, $userid);
 require_capability('gradereport/user: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) {
+} else if ($userid == $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) {
@@ -85,6 +86,34 @@ if ($access) {
     //first make sure we have proper final grades - this must be done before constructing of the grade tree
     grade_regrade_final_grades($courseid);
 
+    if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all student reports
+        /// Print graded user selector at the top
+        echo '<div id="graded_users_selector">';
+        print_graded_users_selector($course, 'report/user/index.php?id=' . $course->id, $userid);
+        echo '</div>';
+        
+        if ($userid == 'all') {
+            $gui = new graded_users_iterator($course);
+            $gui->init();
+            while ($userdata = $gui->next_user()) {
+                $user = $userdata->user;
+                $report = new grade_report_user($courseid, $gpr, $context, $user->id);
+                print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user));
+                if ($report->fill_table()) {
+                    echo $report->print_table(true);
+                }
+                echo "<p style = 'page-break-after: always;'></p>";
+            }
+            $gui->close();
+        } elseif ($userid) { // Only show one user's report
+            $report = new grade_report_user($courseid, $gpr, $context, $userid);
+            print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user));
+            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_user($courseid, $gpr, $context, $userid);
 
@@ -93,6 +122,7 @@ if ($access) {
 
     if ($report->fill_table()) {
         echo $report->print_table(true);
+        }
     }
 
 } else {
index 53a8b8eb81cf5e3c098a1e09fcc251a2239c415f..6a0b7cd319002cfaae9e1e707009ea7b5ec0a1b5 100644 (file)
   padding-right: 5px;
 }
 
+#graded_users_selector {
+  float: right;
+  text-align: right;
+}
+
 /* this must be last if we want to override other category and course item colors */
 .grade-report-user table#user-grade .hidden,
 .grade-report-user table#user-grade .hidden a {
index bd7ef4a8d81b0d5a060e9d7d2a39d7f1253679a7..abf9d0f5726ea977b05197fbac4880281ac809f2 100644 (file)
@@ -38,6 +38,7 @@ $string['aggregationposition'] = 'Aggregation position';
 $string['aggregationview'] = 'Aggregation view';
 $string['allgrades'] = 'All grades by category';
 $string['allstudents'] = 'All students';
+$string['allusers'] = 'All users';
 $string['autosort'] = 'Auto-sort';
 $string['availableidnumbers'] = 'Available id numbers';
 $string['average'] = 'Average';
@@ -398,6 +399,7 @@ $string['scaledpct'] = 'Scaled %%';
 $string['scaleidhelp'] = 'The scale to which this $a is linked.';
 $string['scalestandardhelp'] = 'A standard scale is one that is available site-wide, for all courses.';
 $string['selectdestination'] = 'Select destination of $a';
+$string['selectalloroneuser'] = 'Select all or one user';
 $string['septab'] = 'Tab';
 $string['sepcomma'] = 'Comma';
 $string['separator'] = 'Separator';