XF 2.2 $finder / pagenav / total() / fetch() / unset some rows and normalize the pagenav and results

Scandal

Well-known member
Well, we have the well known finder: $this->finder('XF:Thread').

Finder includes methods to separate results into pages for the <xf:pagenav>, like:
PHP:
        $total = $finder->total();
        $threads = $finder->limitByPage($page, $perPage)->fetch();

My question: AFTER $finder->fetch(); I need to unset some "rows" based on some checks which cannot be applied on the $finder query / where.

The basic thing is to not break the display on the results on the $threads and on <xf:pagenav>.

So these unset's will decrease the $total and will make some rows to not display when I use the <xf:foreach loop="$threads" value="$thread"> on a template for some pages.

How could I normalize the show of the threads and the pagenav after those unset's ?

For example, if $perpage = 5;, every page should show 5 $threads in any case. Not 4 or 3 in case we had unset them.

Got it? :) Any idea? :)
 
If you can't filter them out in the query then it's not possible to display a consistent number of results with traditional pagination techniques.

You could fetch an entire result set, filter it, store the remaining IDs, and paginate over that instead. This is how the search and "what's new" results are paginated, for example. Or you could over-fetch the results by some factor and use cursor-based pagination (no page numbers, just next/previous links based on the ID of the first and last displayed results on the page).
 
Top Bottom