Page List Object getTotalResults() method

I’m using the following method to get page numbers for html ol lists in reverse order, with pagination. Works like a charm when logged in. As soon as I log out, from what I can find, the permissionsChecker clause of the getTotalResults() method fails and the return value becomes -1 (unknown). This sets my $start to -1 and my list is -1, -2, -3, -4 etc for logged out users as opposed to 27, 26, 25, 24 like it should be.

Should we really be checking for logged in users to be able to get/display/use the total number of results in a page list? Or am I missing something else completely obvious here ?? :smiley:

public function getPagingStartPositionReverse() {
		$items = $this->list->getItemsPerPage();
		$results = $this->list->getTotalResults();
		$param = $this->list->getQueryPaginationPageParameter();
		$paging = $this->request->request($param);
		$start = $results;
		if ($paging && $paging >= 2) {
			$i = $items * ($paging - 1);
			$start = $results - $i;
		return $start;

There is an ignorePermissions() method you can call on the list. Take care not to expose anything that should be protected.

Checking to ignore permissions works, yet remains completely illogical to me. Why should I need to expose pages that are otherwise unavailable to logged out users, just to do something as simple as display the total number of pages in a list. The total number of pages my logged out users should see is 26. Ignoring permissions to get the proper total now renders the 27th page in the list for users who shouldn’t see it. As is, I would expect the method to return 26 being there’s 26 pages logged out users can view and it doesn’t seem to work that way…

AFAIK, the counting of pages for a front end page list was a compromise between performance and detail.

If you look at the core block and how it shows a paginated list, when logged in you see a list in the paginator because you can see everything. When guest the paginator is a simple page number and prev/next.

For exactly the same reasons you are running into.

It appears the detail end of things actually working, for those who want to implement it, may have been overlooked… Nothing like cooking up my own working solution in the mean time :slight_smile:

Interestingly enough, if I change the getTotalResults() methoid as such, everything works as it should… Some core team input on this would be nifty :wink: @frz @Myq @EvanCooper

public function getTotalResults()
        //if ($this->permissionsChecker === -1) {
            $query = $this->deliverQueryObject();
            // We need to reset the potential custom order by here because otherwise, if we've added
            // items to the select parts, and we're ordering by them, we get a SQL error
            // when we get total results, because we're resetting the select
            return $query->resetQueryParts(['groupBy', 'orderBy'])->select('count(distinct p.cID)')->setMaxResults(1)->execute()->fetchColumn();

        //return -1; // unknown

I take that back. Still stuck needing to manually exclude pages from list that are normally permissioned out…

Of course, the simple solution comes to me after I post to the forums :wink:

$results = count($this->list->getResults());
1 Like