]> git.mjollnir.org Git - moodle.git/commitdiff
New feature based on code from Gustav Delius
authormoodler <moodler>
Tue, 4 Nov 2003 12:09:52 +0000 (12:09 +0000)
committermoodler <moodler>
Tue, 4 Nov 2003 12:09:52 +0000 (12:09 +0000)
  -> A-Z subsets on the participant list.

http://moodle.org/mod/forum/discuss.php?d=3162

I also made a new datalib function called count_course_students()

lang/en/moodle.php
lib/datalib.php
user/index.php

index f1cdb560f5b16d731bbc4e5886707935e3a9a209..1105e226ebf51253ee2992c565073700f9a872f5 100644 (file)
@@ -56,6 +56,7 @@ $string['allow'] = "Allow";
 $string['allowguests'] = "This course allows guest users to enter";
 $string['allownot'] = "Do not allow";
 $string['allparticipants'] = "All participants";
+$string['alphabet'] = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
 $string['alphanumerical'] = "Can only contain alphabetical letters or numbers";
 $string['alreadyconfirmed'] = "Registration has already been confirmed";
 $string['answer'] = "Answer";
@@ -565,6 +566,7 @@ $string['nopotentialcreators'] = "No potential course creators";
 $string['nopotentialstudents'] = "No potential students";
 $string['nopotentialteachers'] = "No potential teachers";
 $string['normal'] = "Normal";
+$string['nostudentsfound'] = "No \$a found";
 $string['nostudentsyet'] = "No students enrolled in this course yet";
 $string['nosuchemail'] = "No such email address";
 $string['notavailable'] = "Not available";
index 436a22b8c352f281bb61263a5f7fc5410595514b..c5dc1ba7f46287cfc1deb4be803e5ffca45b9c04 100644 (file)
@@ -1112,29 +1112,77 @@ function get_recent_enrolments($courseid, $timestart) {
 * 
 * @param       type description
 */
-function get_course_students($courseid, $sort="s.timeaccess", $dir="", $page=0, $recordsperpage=99999) {
+function get_course_students($courseid, $sort="s.timeaccess", $dir="", $page=0, $recordsperpage=99999,
+                             $firstinitial="", $lastinitial="") {
 
     global $CFG;
 
     switch ($CFG->dbtype) {
         case "mysql":
              $limit = "LIMIT $page,$recordsperpage";
+             $LIKE = "LIKE";
              break;
         case "postgres7":
              $limit = "LIMIT $recordsperpage OFFSET ".($page);
+             $LIKE = "ILIKE";
              break;
         default: 
              $limit = "LIMIT $recordsperpage,$page";
+             $LIKE = "ILIKE";
+    }
+
+    $select = "s.course = '$courseid' AND s.userid = u.id AND u.deleted = '0' ";
+
+    if ($firstinitial) {
+        $select .= " AND u.firstname $LIKE '$firstinitial%' ";
+    }
+
+    if ($lastinitial) {
+        $select .= " AND u.lastname $LIKE '$lastinitial%' ";
     }
 
     return get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat,
                             u.email, u.city, u.country, u.lastlogin, u.picture, s.timeaccess as lastaccess
                             FROM {$CFG->prefix}user u, 
                                  {$CFG->prefix}user_students s
-                            WHERE s.course = '$courseid' AND s.userid = u.id AND u.deleted = '0'
+                            WHERE $select
                             ORDER BY $sort $dir $limit");
 }
 
+/**
+* Counts the students in a given course, or a subset of them
+* 
+* @param       type description
+*/
+function count_course_students($course, $search="", $firstinitial="", $lastinitial="") {
+
+    global $CFG;
+
+    switch ($CFG->dbtype) {
+        case "mysql":
+             $LIKE = "LIKE";
+             break;
+        default: 
+             $LIKE = "ILIKE";
+    }
+
+    $select = "s.course = '$course->id' AND s.userid = u.id AND u.deleted = '0'";
+
+    if ($search) {
+        $select .= " AND u.firstname $LIKE '%$search%' OR u.lastname $LIKE '%$search%'";
+    } 
+    if ($firstinitial) {
+        $select .= " AND u.firstname $LIKE '$firstinitial%'";
+    } 
+    if ($lastinitial) {
+        $select .= " AND u.lastname $LIKE '$lastinitial%'";
+    } 
+
+    return count_records_sql("SELECT COUNT(*) FROM {$CFG->prefix}user u,{$CFG->prefix}user_students s WHERE $select");
+
+}
+
+
 /**
 * Returns list of all teachers in this course
 * 
index d4d2750f1d46530fdc230842c1a2d97e5a14223c..8cfc2a23826e090edd4da2f5cbb660ebb7a7e331 100644 (file)
@@ -9,6 +9,8 @@
     optional_variable($sort, "lastaccess");  //how to sort students
     optional_variable($dir,"desc");          //how to sort students
     optional_variable($page, "0");           // which page to show
+    optional_variable($lastinitial, "");     // only show students with this last initial
+    optional_variable($firstinitial, "");    // only show students with this first initial
     optional_variable($perpage, "20");       // how many per page
 
 
@@ -38,6 +40,7 @@
     $string->mins        = get_string("mins");
     $string->sec         = get_string("sec");
     $string->secs        = get_string("secs");
+    $string->all         = get_string("all");
 
     $countries = get_list_of_countries();
 
         $dsort = "u.$sort";
     }
 
-    $totalcount = count_records("user_students", "course", $course->id);
+    $students = get_course_students($course->id, $dsort, $dir, $page*$perpage, 
+                                    $perpage, $firstinitial, $lastinitial);
+
+    $totalcount = $matchcount = count_records("user_students", "course", $course->id);
 
     echo "<h2 align=center>$totalcount $course->students</h2>";
 
-    if ($CFG->longtimenosee < 500) {
+    if (($CFG->longtimenosee < 500) and (!$page) and ($sort == "lastaccess")) {
         echo "<center><p><font size=1>(";
         print_string("unusedaccounts","",$CFG->longtimenosee);
         echo ")</font></p></center>";
     }
 
-    if (0 < $totalcount and $totalcount < USER_SMALL_CLASS) {    // Print simple listing
+    /// Print paging bars if necessary
 
-        if ($students = get_course_students($course->id, $dsort, $dir)) {
-            foreach ($students as $student) {
-                print_user($student, $course, $string, $countries);
+    if ($totalcount > $perpage) {
+        $alphabet = explode(',', get_string('alphabet'));
+
+        /// Bar of first initials
+
+        echo "<center><p align=\"center\">";
+        echo get_string("firstname")." : ";
+        if ($firstinitial) {
+            echo " <a href=\"index.php?id=$course->id&sort=firstname&dir=ASC&".
+                   "perpage=$perpage&lastinitial=$lastinitial\">$string->all</a> ";
+        } else {
+            echo " <b>$string->all</b> ";
+        }
+        foreach ($alphabet as $letter) {
+            if ($letter == $firstinitial) {
+                echo " <b>$letter</b> ";
+            } else {
+                echo " <a href=\"index.php?id=$course->id&sort=firstname&dir=ASC&".
+                       "perpage=$perpage&lastinitial=$lastinitial&firstinitial=$letter\">$letter</a> ";
             }
         }
+        echo "<br />";
 
-    } else if ($students = get_course_students($course->id, $dsort, $dir, $page*$perpage, $perpage)) {
+        /// Bar of last initials
 
-        print_paging_bar($totalcount, $page, $perpage, 
-                         "index.php?id=$course->id&sort=$sort&dir=$dir&perpage=$perpage&");
+        echo get_string("lastname")." : ";
+        if ($lastinitial) {
+            echo " <a href=\"index.php?id=$course->id&sort=lastname&dir=ASC&".
+                   "perpage=$perpage&firstinitial=$firstinitial\">$string->all</a> ";
+        } else {
+            echo " <b>$string->all</b> ";
+        }
+        foreach ($alphabet as $letter) {
+            if ($letter == $lastinitial) {
+                echo " <b>$letter</b> ";
+            } else {
+                echo " <a href=\"index.php?id=$course->id&sort=lastname&dir=ASC&".
+                       "perpage=$perpage&firstinitial=$firstinitial&lastinitial=$letter\">$letter</a> ";
+            }
+        }
+        echo "</p>";
+        echo "</center>";
+
+        $matchcount = count_course_students($course, "", $firstinitial, $lastinitial);
+
+        print_paging_bar($matchcount, $page, $perpage, 
+                         "index.php?id=$course->id&sort=$sort&dir=$dir&perpage=$perpage&firstinitial=$firstinitial&lastinitial=$lastinitial&");
+
+    }
+
+    if ($matchcount == 0) {
+        print_heading(get_string("nostudentsfound", "", $course->students));
+
+    } if (0 < $matchcount and $matchcount < USER_SMALL_CLASS) {    // Print simple listing
+        foreach ($students as $student) {
+            print_user($student, $course, $string, $countries);
+        }
+
+    } else if ($matchcount > 0) {
 
         // Print one big table with abbreviated info
         $columns = array("firstname", "lastname", "city", "country", "lastaccess");
             $students = $nstudents;
         }
 
+
         $table->head = array ("&nbsp;", "$firstname / $lastname", $city, $country, $lastaccess);
         $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT", "LEFT");
         $table->size = array ("10",  "*", "*", "*", "*");
         }
         print_table($table);
 
-        print_paging_bar($totalcount, $page, $perpage, 
+        print_paging_bar($matchcount, $page, $perpage, 
                          "index.php?id=$course->id&sort=$sort&dir=$dir&perpage=$perpage&");
 
         if ($perpage != 99999) {
             echo "<a href=\"index.php?id=$course->id&sort=$sort&dir=$dir&perpage=99999\">".get_string("showall", "", $totalcount)."</a>";
             echo "</p></center>";
         }
-
-    } 
+    }
 
     print_footer($course);