Jump to content

Adding pagination after merging two PageArrays?


landitus
 Share

Recommended Posts

Is it possible to add pagination limit after merging to PageArrays? I'm querying pages for an event calendar where there are two conditions:

  • Events that are starting in the future
  • Events that started in the past but are ending in the future (aka are current)

I've coded the following but I want to limit the results to trigger the pagination, but my code is not working.

What can I do?

$events = $pages->find("template=event, date>=today, sort=date");
$events = $events->append($pages->find("template=event, date<=today, date_end>=today,sort=date"));
$events = $events->find("limit=15");
Link to comment
Share on other sites

I like this solution:

$events1 = $pages->find("template=event, date>=today");
$events2 = $pages->find("template=event, date<=today, date_end>=today");
$events = $pages->find("id=$events1|$events2, sort=date, limit=15");

// now you can paginate $events
 
  • Like 10
Link to comment
Share on other sites

Also depending how many events there are you'll run into a max length of selector with digo solution no? Isn't it limited to a length?

I tried with more than 5000 IDs and it worked (they were the same IDs repeated, but I don't think it makes a difference)

Edit: With 8000 still works, but with short more than that it breaks :P

Edit2: false alarm, it was a mistake in my code. With more than 25.000 IDs it takes long but still works. With much more than that it doesn't, but I'm guessing it's because of PHP time limit.

Edit3: "Maximum execution time of 30 seconds exceeded" :)

  • Like 2
Link to comment
Share on other sites

  • 2 months later...

Funny, today I stumbled on a similar issue.... 

"show me 15 messages where end date is greater then today, or if there's no end date, give me the ones created at least month ago"

in another cms you could do something like this:

$events = $pages->find("template=event,(date>=$today)|(created>=$lastmonth,date=''),sort=-created,limit=15)");

seems 'date' in this case is not unique, which results in an error...

IF that would work, pagination should work as supposed, no?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...