Sort List

2 years 6 months ago - 2 years 5 months ago #326807 by galanopd
[SOLVED] Sort List was created by galanopd
Is it possible to order list results according to #__cbsubs_plans table e.g. SELECT `name` WHERE `name`=Basic, `name`=SuperBasic, etc

As far as I understand List->Sorting->Advanced doesn't accept a full SQL statement like SELECT `name` FROM #__cbsubs_plans etc., is that correct?

Should it be somehow directly stated as ue.`name` or something?

Also, I don't see the EMPTY, NOT EMPTY operator for the fields.

Please Log in to join the conversation.

2 years 6 months ago #326810 by krileon
Replied by krileon on topic Sort List
Yes, that's possible but it won't be very efficient performance wise. So depending on how large your userbase gets it could end up being quite slow. I assume you want to sort the userlist based off users subscription to your plans? The below should do this fine.

( SELECT sub.`subscription_date` FROM `#__cbsubs_subscriptions` AS sub WHERE sub.`user_id` = u.`id` AND sub.`status` = 'A' ) DESC, u.`name` ASC

This should for example sort them based off their subscription date if they have an active subscription it will then sort by their name. If you want to filter the userlist so it only shows users subscribed to a specific plan then the below should also work.

Active
( ( SELECT COUNT(*) FROM `#__cbsubs_subscriptions` AS sub WHERE sub.`user_id` = u.`id` AND sub.`status` = 'A' ) >= 1 )

Expired
( ( SELECT COUNT(*) FROM `#__cbsubs_subscriptions` AS sub WHERE sub.`user_id` = u.`id` AND sub.`status` = 'X' ) >= 1 )

This isn't filtered to a specific plan. If you only want to show from a specific plan you'd use the below for example.

Active
( ( SELECT COUNT(*) FROM `#__cbsubs_subscriptions` AS sub WHERE sub.`user_id` = u.`id` AND sub.`status` = 'A' AND sub.`plan_id` = PLAN_ID_HERE ) >= 1 )

Expired
( ( SELECT COUNT(*) FROM `#__cbsubs_subscriptions` AS sub WHERE sub.`user_id` = u.`id` AND sub.`status` = 'X' AND sub.`plan_id` = PLAN_ID_HERE ) >= 1 )

Be sure to replace PLAN_ID_HERE with your actual plan id.


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.

2 years 6 months ago - 2 years 6 months ago #326812 by galanopd
Replied by galanopd on topic Sort List
I will try exactly as you described.

Actually what I am trying to achieve are 2 things.

1. to have a list showing the users with a specific plan order e.g. first users ASC by Plan1, then users ASC by Plan2, etc
2. in order to narrow down the results, in Search options I need to make all fields required to have a value

Please Log in to join the conversation.

2 years 6 months ago #326815 by krileon
Replied by krileon on topic Sort List

1. to have a list showing the users with a specific plan order e.g. first users ASC by Plan1, then users ASC by Plan2, etc

You should be able to do that by adjusting the query provided above. Example as follows.

( SELECT sub.`plan_id` FROM `#__cbsubs_subscriptions` AS sub WHERE sub.`user_id` = u.`id` AND sub.`status` = 'A' ) DESC, u.`name` ASC


That should sort by plan id instead of by subscription date. You could sort by plan name as well I suppose. Basically just need to adjust that subquery as needed.


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.

2 years 6 months ago - 2 years 6 months ago #326818 by galanopd
Replied by galanopd on topic Sort List

( SELECT sub.`plan_id` FROM `#__cbsubs_subscriptions` AS sub WHERE sub.`user_id` = u.`id` AND sub.`status` = 'A' ) DESC, u.`name` ASC


1242
Subquery returns more than 1 row

EDIT: disregard
EDIT2: I thought I fixed it but no

Please Log in to join the conversation.

2 years 6 months ago #326819 by krileon
Replied by krileon on topic Sort List
They've multiple active subscriptions then. You'll need to further limit the query to prevent that. Either using GROUP BY and concating the results or adding LIMIT 1 to the query or by adding additional WHERE statements to limit what it queries for.


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: galanopd

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.358 seconds