Sort User List by online status

13 years 5 months ago #145682 by SAlexson
Sort User List by online status was created by SAlexson
Is it possible to sort a user list by online status?

I currently have a user list setup as such:
col1=Online Status
col2=Profile Image
col3=Formatted Name
col4=Last Online

The list is currently sorted by "Last Name ASC, First Name ASC". I would like to sort by Online Status first, therefore grouping the list by Status, then sorting by names.

I can't seem to find a way to do this since "Online Status" is not a field, but a query to the user session time. Couldn't a field be added the the user table called "online_status" which is toggled between 1/0 when the user logs on and off? Then we could sort by this field. I couldn't see this a being an overly complicated modification.

Please Log in to join the conversation.

13 years 5 months ago #145743 by krileon
Replied by krileon on topic Re:Sort User List by online status
No it's not possible to sort by the online status. Sorting and Filtering are direct additions to the database. The online field not being an actual stored database row means you can't use it in a query. It is possible to FILTER a userlist by online status with the below queries that I've carefully developed for my own site.

ONLINE ONLY:
[code:1]
( ( SELECT MAX( s.time ) FROM #__session AS s WHERE s.userid = u.id AND s.guest = 0 ) IS NOT NULL )
[/code:1]

OFFLINE ONLY:
[code:1]
( ( SELECT MAX( s.time ) FROM #__session AS s WHERE s.userid = u.id AND s.guest = 0 ) IS NULL )
[/code:1]

These are ADVANCED filters. You could just create 2 userlists 1 for online and 1 for offline. Then have your users simply select which one they want from the drop-down userlist select at the top right.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

13 years 5 months ago #145782 by SAlexson
Replied by SAlexson on topic Re:Sort User List by online status
Thank you for the reply, but I already understood and knew how to do this with 2 lists. What I am looking for is a way to do it in one list, which I know isn't possible at this time.

The real goal of my post was to suggest the incorporation of a new field (i.e. is_online) in the user database table that tracks each user's online status as they log on and off. The field would just be a flipped bit that you could then sort against.

The only caveat then would users that close their browser without logging out. This would cause a misrepresentation in the user list. It actually appears that the current method of determining online status suffers from this as well.

However, this could possibly be accounted for by simply checking the session time and updating the proposed "is_online" field of the database if "Online Status" is an item included in the list. This update would obviously occur prior to the query to grab/display the user list. Of course, their may be no way to account for this condition, and a simply sticky bit field in the DB would be sufficient.

Just my thoughts. As I said, more of an enhancement consideration at this point. Not really expecting guidance on hacking the core system. I know that this kind of enhancement won't be introduced unless enough users express an interest in it (typical software development supply and demand), so perhaps this thread could act as a user petition for such an enhancement.

Post edited by: SAlexson, at: 2010/11/09 01:01

Post edited by: SAlexson, at: 2010/11/09 01:02

Please Log in to join the conversation.

13 years 5 months ago #145837 by krileon
Replied by krileon on topic Re:Sort User List by online status
You could create an integer field that is read only. You could then use documentation subscriber incubator project CB Queries to perform a query on after login to set the field to 1 then use the trigger on after logout to 0. This would allow you to now sort by the integer field. It won't be 100% accurate but for the most part should get the job done.

Not much more I can suggest other then creating a new fieldtype to actually store the online status in database, but keep in mind such a field could be very heavy for your site as it would require constantly updating.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.221 seconds

Facebook Twitter LinkedIn