Okay, I’ve gotten the sorting issue figured out.
Recap : what I wanted to do was sort the user list not by username but by another field, in this case fullname. But I didn’t want everything on one page either. The Taff code seems to sort things once they’re on a page, rather than sort and then divide everything up into pages.
To fix this I needed to edit the function "ViewAllUsers". (Note : this is in the webloginpe.class.php code and the version I was working from was an early beta, not the current one)
- adding the two lines here with my initials near the beginning of the function :
$web_users = $modx->getFullTableName('web_users');
$web_user_attributes = $modx->getFullTableName('web_user_attributes'); //MattC
$web_user_attributes_extended = $modx->getFullTableName('web_user_attributes_extended'); //MattC
$allRows = $modx->db->query("SELECT id FROM ".$web_users);
- commenting out these two lines with my initials a bit further down :
echo $output;
//$fetchUsers = $modx->db->query("SELECT `username` FROM ".$web_users."ORDER BY `username` LIMIT ".$positionInList.",".$pagination);//MattC
//$allUsers = $this->FetchAll($fetchUsers);//MattC
if ($listUsers == '')
- and moving them down further, adding an edit at the same time :
// Filters.
if ($format[5] == '')
{
$format[5] = 'username()';
}
$fetchUsers = $modx->db->query("SELECT `username` FROM ".$web_users." left join ".$web_user_attributes." ON ".$web_users.".`id`=".$web_user_attributes.".`internalKey` ORDER BY ".$web_user_attributes.".`".$listSortBy."` LIMIT ".$positionInList.",".$pagination);//MattC
$allUsers = $this->FetchAll($fetchUsers);//MattC
$CompleteUserList = array();
Two things to note. I added a variable to point to the "extended" table because we might want to sort on a field there. But that is not used in my edit above.
Which brings up the second issue. As written, this now allows me to select based on username but sort based on fullname. (Username is in the web_users table while fullname is in the web_users_attributes table.) But that’s not very flexible.
Seeing as I’m no whiz with SQL syntax, can someone suggest a general query formulation that would allow for the user list to be sorted on any field in the web_users, web_user_attributes and web_user_attributes_extended table? Or is there a better place to make the changes such that sorting-with-pagination works?
Matt