History | Log In     View a printable version of the current page.  
We are currently focused especially on Moodle 2.0, Moodle 1.9.x bugs and Moodle 1.9.x testing.    Confused? Lost? Please read this introduction to the Tracker.
Issue Details (XML | Word | Printable)

Key: MDL-7163
Type: Improvement Improvement
Status: Open Open
Priority: Minor Minor
Assignee: Martin Dougiamas
Reporter: Anthony Borrow
Votes: 18
Watchers: 7
Operations

If you were logged in you would be able to see more operations.
Moodle

Allow sorting of people in course by lastname, firstname, and username when assigning groups

Created: 22/Oct/06 10:45 PM   Updated: 21/Sep/07 06:20 AM
Component/s: Course
Affects Version/s: 1.6.3
Fix Version/s: None

Environment: n/a

URL: /course/groups.php
Participants: A. T. Wyatt, Anthony Borrow, Brian Pool, Martin Dougiamas, Matt Tate and Ray Lawrence
Security Level: None


 Description  « Hide
Currently sorting of students (people in course) is by fullname which I find somewhat awkward as most users prefer to see firstname + lastname; however, most lists from the school (such as school rosters) are sorted by lastname. While it makes sense to me to sort by lastname, I think ideally it is best to give the users (i.e. teachers) the option to sort either by lastname, firstname, or username. This could be implemented either at the site or course level (my preference would be the course level so that each teacher can control how the names are sorted; however, AT Wyatt suggested the site level. As I envision it, the field could be added in with the group mode dropdown boxes in /course/edit.php as group members sorted by: with options of - Firstname, Lastname, Username.

I am requesting this because adding group members to the sections was a tedious process for me and my teachers because the list we had been given from the school was the student's official firstname; however, when I had pulled in the enrollment data I used the student's preferred name which means that what was on the teacher's roster as William Jones was in the group listing of people in course as Billy Jones. It was difficult to find Jones and required visually scanning the whole list. Hence, it would have been really helpful to be able to sort by lastname.

Thanks for your consideration of this improvement and let me know if there is anything I can do to support its introduction into Moodle.

Peace - Anthony

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Anthony Borrow - 23/Oct/06 06:26 AM
I looked at the code in course/groups.php (revision 1.24) earlier and at least in 1.6.3 the sort is performed on line 211 with:

    natcasesort($nonmembers);

I can produce the desired behavior by modifying /course/groups.php file

If I comment out line 174 (the original)
// $nonmembers[$student->id] = fullname($student, true);

and insert a modified version of the line:
            $nonmembers[$student->id] = $student->lastname.', '.$student->firstname;

I am able to get the behavior that I want. Similarly, if someone want to sort by username they could instead use:
            $nonmembers[$student->id] = $student->username.' ('.$student->lastname.', '.$student->firstname.')';

For consistency the same procedure should be applied to the teacher array on line 185
commenting out line 185
// $nonmembers[$teacher->id] = $prefix.fullname($teacher, true);

and replacing it with either (to sort by lastname)
            $nonmembers[$teacher->id] = $prefix.$teacher->lastname.', '.$teacher->firstname;

or (to sort by username)
// $nonmembers[$teacher->id] = $prefix.$teacher->username.' ('.$teacher->lastname.', '.$teacher->firstname.')';

It is just a matter of setting up a course variable (for example, $course->groupsortby) and adding some if statements or a case statement to it and then modifying the course edit.php file to include a dropdown box with the options for fullname, lastname, firstname or username.

Ray Lawrence - 22/Jan/07 06:03 AM
Just a quick comment on this request.

Unless I'm missing something obvious (highly likely as I've only had a quick think about this) to see a student's username a teacher would need to log in as a student (for each student) to find their username. So would the ability to be able to sort by username be useful in practice?

Anthony Borrow - 22/Jan/07 06:54 AM
We use the students school id as their username and have some lists that come sorted by it. It is admittedly not as important as being able to sort by lastname then firstname (which currently can be done if you switch the fullname to be surname+firstname; however, in practice most folks (at least here in the U.S.) prefer firstname+lastname) for display purposes but lastname, firstname for sorting purposes. I think having the ability to choose is the key point of this request. Whether or not username is part of that is not as important - it was just another option that I thought might be useful to some.

Ray Lawrence - 22/Jan/07 07:17 AM
Agreed. :-) Best wishes with this request.

Matt Tate - 25/Feb/07 02:27 AM
This fix does not seem to work with 1.7.1.

I have commented out the equivalent line ie ( // $nonmembers[$contextuser->id] = fullname($contextuser, true);)
and altered the suggested code to match the changes:
$nonmembers[$contextuser->id] = $contextuser->firstname.', '.$contextuser->lastname;

Doing this I can alter the order of the display but it STILL sorts by lastname ...

(ps I want to sort by firstname)

Any idea what I am missing?

Thanks

Anthony Borrow - 25/Feb/07 03:29 AM
Matt - I took a quick look at the 1.7 /course/groups.php code and I did not see the previous natcasesort($nonmembers); line that was in 1.6 around 211. I added this in to sort the list after we populate it and I think it will give you the desired functionality that you are looking for.

    if ($contextusers = get_role_users($roleid, $context)) {
        foreach ($contextusers as $contextuser) {
# $nonmembers[$contextuser->id] = fullname($contextuser, true);
             $nonmembers[$contextuser->id] = $contextuser->firstname.', '.$contextuser->lastname;
        }
    }
    natcasesort($nonmembers);
    unset($contextusers);

Matt Tate - 25/Feb/07 05:20 AM
Thank you - works spot on.

 I have now got an easy way for teachers to add pupils to their groups.

Thanks

Matt

Matt Tate - 25/Feb/07 11:06 PM
This is slightly off topic. I want to achieve the same thing in /admin/roles/assign.php but the format seems very different...

-wish i knew more about PHP :-(


Anthony Borrow - 25/Feb/07 11:29 PM
Matt - in order to avoid having non-related material on the tracker issue which IMHO only creates unnecessary reading for the developers - let's keep these types of inquires in the forums. Thanks - Anthony

Matt Tate - 25/Feb/07 11:39 PM
Apologies - thought it was worth thinking about in terms of the additional functionality of sorting by firstname/surname etc in other parts of moodle.

Anthony Borrow - 18/Mar/07 11:16 AM
Matt - not a problem, I just know how swamped the developers are and was being a little protective. As 1.8 gets ready for release I am hoping that this bug might get some attention.

Anthony Borrow - 18/Mar/07 11:36 AM
I am a little confused about how this is being implemented in 1.8. If I use the link for groups on the course page I am now taken to /group/index.php; however /course/groups.php still exists (without an obvious link to it) and without any interface for groupings. There seems to be an inconsistency here and perhaps the priority of this bug should be raised so that this question about groupings and groups and how the UI is going to be handled in 1.8 can be worked out.


Anthony Borrow - 18/Mar/07 12:54 PM
To change the order of the list of members in the group members box I changed line 63 of /group/lib/utillib.php

from:
$fullname = fullname($user, true);

to:
$fullname = $user->lastname.', '.$user->firstname;

this is significantly simpler in 1.8 which makes make think that giving the user a choice would be fairly easy

if {some condition like $sortbyfullname=true}
 then $fullname = fullname($user, true);
 else $fullname = $user->lastname.', '.$user->firstname;

I'm sure there are 100 better ways to implement this but it should be fairly simple and I could see it giving greater flexibility in terms of how names are sorted and shown.

A. T. Wyatt - 03/Jul/07 12:05 AM

Brian Pool - 21/Sep/07 05:13 AM
I have made the code change to make users list by lastname, firstname and was suprised this option was not in version 1.8. I actually like groups less now than in 1.7. 1.7 interface was simple and let you know how many groups a person was in (ie if you already had him.)

I actually think in would be useful to be able to only list users not already in a group so as you add members the list keeps getting smaller to wade through. We are now using Moodle as our K-12 online gradebook and our "Groups" are being used as our course sections, so students are only members of a single group for a particular course. I has hoped to drop the 1.7 code in 1.8 but the structure changed enough that it wasn't possible.

Anthony Borrow - 21/Sep/07 06:20 AM
Brian - Keep in mind that the group list used to get smaller as members were added to a group; however, that assumed that members were only in one group. Now members can be in multiple groups. While it may be a little more complex and/or time consuming to set them up the goal is ultimately to make the use of groups more flexible for teachers. Peace - Anthony