Skip to Content Skip to Menu

CB - How to build up a CB (sorted) user list

5 years 2 months ago - 5 years 2 months ago #313864 by erichburkhard
CB - How to build up a CB (sorted) user list was created by erichburkhard
I wanted to sort my CB user list according to certain criteria. The criteria is as follows:

Sorting Priority 1: Users who have an approved avatar should be listed in front of users who have no approved avatar
Sorting Priority 2: Users who have visited their profile recently sould be listed in front of users who visited their profile later
Sorting Priority 3. Users who have registered recently should be listed in front of users who registered later

I tried to implement this requirement by the help of the sorting tab. This looks as follwows:



I tested this sorting configuration.The Sorting Priority 1 seems to work. But then I think the 'last visit date' or 'register date' seems to have no impact in the sorting order. Whats wrong here?

Regards
Attachments:
Last edit: 5 years 2 months ago by erichburkhard.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48435
  • Thanks: 8275
  • Karma: 1443
5 years 2 months ago #313868 by krileon
Replied by krileon on topic CB - How to build up a CB (sorted) user list
The sorting is applied to the database query so if you don't understand how the ORDER BY statement in a database query works then it's likely not behaving how you'd expect. Your usage would result in the following ORDER BY statement.

Code:
ORDER BY `avatar` DESC, `lastvisitDate` DESC, `registerDate` DESC

See the below in regards to ORDER BY in SQL.

dev.mysql.com/doc/refman/5.7/en/sorting-rows.html

The reason it's not working is because the first sorting on avatar is creating the first sub group. That sub group is then sorted by your other criteria. The problem with this is avatar tends to be unique per person there's no further sorting to be done. Instead you likely need to use the Advanced filtering usage since you just want to sort on whether they have an avatar or not and not on the actual value of the avatar column. The below should work for that.

Advanced
Code:
IF( `avatar` = '' OR `avatar` IS NULL, 0, 1 ) DESC, `lastvisitDate` DESC

Note registerDate sorting was removed as it's only going to be applied to users who've never logged in since the lastvisitDate sub group is unlikely to be the same for multiple users at once beyond those without a lastvisitDate. You could also use the below, but it maybe unreliable depending on the avatarapproved column value.

Basic
1: avatar (avatarapproved) - descending
2: lastvisitDate - descending


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.
The following user(s) said Thank You: erichburkhard

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum