Skip to Content Skip to Menu

Sort List

  • galanopd
  • galanopd
  • OFFLINE
  • Posts: 374
  • Thanks: 49
  • Karma: 8
3 years 1 month ago - 3 years 3 weeks 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.
Last edit: 3 years 3 weeks ago by galanopd.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48536
  • Thanks: 8290
  • Karma: 1445
3 years 1 month 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.

Code:
( 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
Code:
( ( SELECT COUNT(*) FROM `#__cbsubs_subscriptions` AS sub WHERE sub.`user_id` = u.`id` AND sub.`status` = 'A' ) >= 1 )

Expired
Code:
( ( 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
Code:
( ( 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
Code:
( ( 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 or Create an account to join the conversation.

  • galanopd
  • galanopd
  • OFFLINE
  • Posts: 374
  • Thanks: 49
  • Karma: 8
3 years 1 month ago - 3 years 1 month 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
Last edit: 3 years 1 month ago by galanopd.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48536
  • Thanks: 8290
  • Karma: 1445
3 years 1 month 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 or Create an account to join the conversation.

  • galanopd
  • galanopd
  • OFFLINE
  • Posts: 374
  • Thanks: 49
  • Karma: 8
3 years 1 month ago - 3 years 1 month 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
Last edit: 3 years 1 month ago by galanopd.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48536
  • Thanks: 8290
  • Karma: 1445
3 years 1 month 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 or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum