Assign Rolse - How to list students in alphabetical order

Assign Rolse - How to list students in alphabetical order

by Steve Bilton -
Number of replies: 8
Hi All,

I have noticed that when manually assigning students to a course in a 1.8.4 moodle that they do not appear in alphabetical order like they used to in previous moodle versions.
From the course menu - Administration / Assign Roles / Student or anywhere with the assign roles menu it appears that the list of users do not list alphabetically according to their first name. This is proving to be very awkward for our admin people trying to locate a user to enrole on a particular course. We have many international students and some have very long unusual names that we are just not familiar with, sometimes the user does not provide their full name and its pot luck whether they refer to themselves with a different name to what is on our records>

My question is this: How can I re-order the assign roles list to display users in alphabetical order according to their first name?

Also on another module - QUICKMAIL also seems to not be in alphabetical order according to their first name in moodle 1.8.4. Is there a workaround for quick mail to list users alphabetically also ??

I'd be very greatful for some assistance smile
Cheers
Steve
Average of ratings: -
In reply to Steve Bilton

Re: Assign Rolse - How to list students in alphabetical order

by Matt Campbell -
I haven't looked at this yet for quickmail - heading into a meeting but will look at it shortly.

For Assign roles, there are two places in the code you need to make this change:

For the box on the left (already assigned users), you need to modify /lib/accesslib.php - look for 'function get_role_users'.

This is where the sort order is defined. Reading along the line, you'll see $sort='u.lastname ASC'. Change this to $sort='u.firstname ASC' and save the file.

To sort the list on the right (potential users), you need to modify /admin/roles/assign.php - search for '$availableusers = get_recordset_sql('SELECT id, firstname, lastname, email' (line 381 in Moodle 1.9, not sure in 1.8.4)

At the bottom of that SQL statement you'll see ORDER BY lastname ASC, firstname ASC - just change this to ORDER BY firstname ASC, lastname ASC.

Thanks,
Matt
Average of ratings: Useful (2)
In reply to Matt Campbell

Re: Assign Roles - How to list students in alphabetical order

by Steve Bilton -
Hello Matt,

Your a Star! That exactly what i needed. Thank you very much.
I've just upgraded my moodle to a 1.8.4 from a 1.6 and there are a huge number of differences, glad you were on hand to assist me, i'd have been trawling for ages without your help.

Many Thanks

It'd be great if you manage to suss out the quickmail block sort order. I look forward to hearing from you.

Thanks again
Steve
In reply to Steve Bilton

Re: Assign Roles - How to list students in alphabetical order

by Matt Campbell -
Glad I could help, Steve. Unfortunately, I had several non-Moodle sad projects cycle in on me and I haven't had time to take a look at Quickmail yet. I will take a look at it over the weekend and get back to you with what I find.

Thanks,
Matt
In reply to Steve Bilton

Re: Assign Roles - How to list students in alphabetical order

by Matt Campbell -
Okay, the order for quickmail is defined in /blocks/quickmail/email.php. Look for:

if (!$courseusers = get_users_by_capability($context, 'moodle/course:view', 'u.*', 'u.lastname, u.firstname', '', '', '', '', false)) {

My version of quickmail is dated 8/30/2007, and in this version, this is line 56. Simply swap u.lastname and u.firstname in this line, so you have:

if (!$courseusers = get_users_by_capability($context, 'moodle/course:view', 'u.*', 'u.firstname, u.lastname', '', '', '', '', false)) {

Thanks,
Matt

P.S. There is a discussion about lastname, firstname ordering as opposed to firstname, lastname ordering in 1.8.x, along with some fixes and tracker issues at http://moodle.org/mod/forum/discuss.php?d=76855 - it may have some information I haven't given you.


Average of ratings: Useful (1)
In reply to Matt Campbell

Re: Assign Roles - How to list students in alphabetical order

by Steve Bilton -
Hello Matt,

Thank you again for being so helpful.

I have a moodle 1.8.4 and use quickmail dated : 2007/04/05 09:55:18

I altered this line around line 76:
//Get list of users enrolled in the course including teachers and students
if (!$courseusers = get_course_users($course->id, 'lastname')) {
error('No course users found to email');
}
to this :
//Get list of users enrolled in the course including teachers and students
if (!$courseusers = get_course_users($course->id, 'firstname')) {
error('No course users found to email');
}

All I changed was the lastname and replaced with firstname.

I also changed these lines:
around line 183:
$form->usersfail['emailfail'][] = $courseusers[$userid]->lastname.', '.$courseusers[$userid]->firstname;
$failedTo[] = $userid;
to
$form->usersfail['emailfail'][] = $courseusers[$userid]->firstname.', '.$courseusers[$userid]->lastname;
$failedTo[] = $userid;
I just replaced firstname for last name and vice versa for both highlighted.

I also changed this around line 191:
$form->usersfail['emailstop'][] = $courseusers[$userid]->lastname.', '.$courseusers[$userid]->firstname;
to
$form->usersfail['emailstop'][] = $courseusers[$userid]->firstname.', '.$courseusers[$userid]->lastname;

Jobs done, with these changes.

Thank you for your assistance, it's much appriciated.

Steve

In reply to Steve Bilton

Re: Assign Roles - How to list students in alphabetical order

by Steve Bilton -
I should have probably mentioned the file to edit for this re-order of users in course -> assign roles to firstname lastname alphabetical ascending order
/lib/accesslib.php

For QUICKMAIL
I should have probably mentioned the file to edit for this block is blocks/quickmail/email.php

Steve
In reply to Matt Campbell

Re: Assign Rolse - How to list students in alphabetical order

by Debbie Kay -

Thanks so much for this Matt!! smile

As a non coder, your instructions were great and allowed me to make the changes I needed - much appreciated!!!

Debbie

In reply to Debbie Kay

Re: Assign Rolse - How to list students in alphabetical order

by Debbie Kay -

Can anyone help point me in the right direction, i.e. file and section to achieve this in Group lists as well, when viewing members and potential members?

I'm using 1.8

Many thanks in advance! smile