Skip to content

Commit

Permalink
[TASK] Add page browser values
Browse files Browse the repository at this point in the history
This brings back some of the page
browser values removed with
ec28e2d

It is useful if the built-in pagination
API of TYPO3 should not be used, e.g.
in headless context
  • Loading branch information
christianbltr committed Feb 23, 2024
1 parent 88570d6 commit df551ed
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Classes/Plugins/ResultlistPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public function main(string $content, array $conf, ServerRequestInterface $reque
$this->fluidTemplateVariables['pagination'] = new SlidingWindowPagination($paginator, $maxPages);
}

$this->fluidTemplateVariables['pagebrowser'] = $this->getPageBrowserValues();

// hook: modifyResultList
if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyResultList'] ?? null)) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyResultList'] as $_classRef) {
Expand Down Expand Up @@ -161,4 +163,37 @@ public function initFluidTemplate()
$this->resultListView->assign('extConf', $this->extConf);
$this->resultListView->assign('extConfPremium', $this->extConfPremium);
}

/**
* Get page browser variables
* Useful if the built-in pagination API of TYPO3 should not be used, e.g. in headless context
*
* @return array
*/
public function getPageBrowserValues(): array
{
$numberOfResults = $this->numberOfResults;
$resultsPerPage = $this->conf['resultsPerPage'] ?? 10;

// Show page browser only if there are more entries that are shown on one page
if ($numberOfResults <= $resultsPerPage) {
return [];
}

$start = ($this->piVars['page'] * $resultsPerPage) - $resultsPerPage;
$end = ($start + $resultsPerPage > $numberOfResults) ? $numberOfResults : ($start + $resultsPerPage);
$pagesTotal = ceil($numberOfResults / $resultsPerPage);

return [
'current' => $this->piVars['page'],
'pages_total' => $pagesTotal,
'start' => $start + 1,
'end' => $end,
'total' => $numberOfResults,
'results' => $this->pi_getLL('results'),
'until' => $this->pi_getLL('until'),
'of' => $this->pi_getLL('of'),
];
}

}

0 comments on commit df551ed

Please sign in to comment.