XF 2.1 Total and items per page help

AndrewSimm

Well-known member
I am creating an addon to list polls. The problem I am running into is when removing threads that users don't have permission to view the total doesn't change and the threads still show on their original page. This means that instead of showing 40 per page it shows however many the user has permission to view out of that group of 40. So if a user can only view one poll in the 40 - 80 range then only one will show on that page.

TLDR; my total and page count always shows the same regardless if a user only has permission to view a small percentage fo the results.

PHP:
$pollsPerPage =  $this->options()->andrewEnhanchedPollsPerPage;
$page = $this->filterPage();
$perPage = $pollsPerPage;

$threadFinder = \XF::finder('XF:Thread')
    ->with('Poll', true)
    ->with('Forum', true)
    ->with('Forum.Node.Permissions|' . $visitor->permission_combination_id)
    ->order('post_date','DESC')
    ->limitByPage($page, $perPage);

$threads = $threadFinder->fetch();
$threads = $threads->filterViewable();

$total = $threads->count();

edit: simplified a few things but still the same issue.
 
Last edited:
This means that instead of showing 40 per page it shows however many the user has permission to view out of that group of 40. So if a user can only view one poll in the 40 - 80 range then only one will show on that page.
That's really to be expected. If you're fetching 40 results and then removing 39 of them, then only one will be displayed. This is how most paginated multi-node thread lists (such as the 'Find threads' pages) behave. There's not really a good way around this as you can't over-fetch to compensate when using traditional pagination, as then the set of threads to display can't be easily derived from the page number alone.
 
Back
Top Bottom