Jump to content

Recommended Posts

Posted

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");
Posted

There's a couple threads about this. This is where my solutions are: https://gist.github.com/somatonic/5420536

Pagination module works only for a single find. You can set the start limit and total yourself to get a working pager, but you have to load all pages everytime. Means it works better for smaller amounts.

  • Like 3
Posted

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
Posted

Well, what can say... What an awesome amount of responses!! I was able to do it Diogo's way but all 3 are excellent answers. You all saved my day, so thank you!

Posted

That's also a nice solution by diogo. But will increase loading all pages even more along with memory.

  • Like 1
Posted

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?

Posted
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?

hm, not sure... is it?

Posted

I will be displaying all events in the future and there will be 150/200 for the current year. It only has events for the current year. Do you think this will be a problem? 

Posted
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
  • 2 months later...
Posted

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?

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
×
×
  • Create New...