Skip to content
Snippets Groups Projects
Commit 7052b117 authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Fixed offset filtering for ajax filter requests

parent 5d4a8493
No related branches found
No related tags found
No related merge requests found
......@@ -69,11 +69,24 @@ class JoblistController extends AbstractAjaxController {
$this->assignFilterValues($recordPageId);
// set all filtered jobs
$jobs = FrontendFilterService::getJobs($filters, $recordPageId);
$this->view->assign('jobs', $jobs);
$this->view->assign('numberOfPages', \count($jobs));
// pagination logic
$jobLimit = (int) $this->settings['jobLimit'];
$offset = 0;
$currentPageBrowserPage = (int) GeneralUtility::_GP('tx_sgjobs_pagebrowser')['currentPage'];
if ($currentPageBrowserPage && $jobLimit) {
$offset = $currentPageBrowserPage * $jobLimit;
}
// get all jobs for the current page
$jobs = FrontendFilterService::getJobs($filters, $recordPageId, $jobLimit, $offset);
// get the amount of all filtered jobs
$jobsCount = \count(FrontendFilterService::getJobs($filters, $recordPageId));
$numberOfPages = ($jobLimit <= 0 ? 0 : ceil($jobsCount / $jobLimit));
$this->view->assign('jobs', $jobs);
$this->view->assign('numberOfPages', $numberOfPages);
// set default selected values
$this->view->assign('selectedCountry', $filters['country']);
......
......@@ -61,13 +61,6 @@ class BackendController extends ActionController {
*/
private $jobRepository;
/**
* The uid of the current root page
*
* @var int
*/
private $rootPageUid = 0;
/**
* Show all job offers and options to manage them
*
......
......@@ -159,9 +159,12 @@ class JobRepository extends Repository {
*
* @param int $pageUid
* @param array $companyIds
* @param int $limit
* @param int $offset
* @return QueryResultInterface
*/
public function findByCompanyId($pageUid, array $companyIds = []): ExtbaseQueryResultInterface {
public function findByCompanyId($pageUid, array $companyIds = [], $limit = 0, $offset = 0
): ExtbaseQueryResultInterface {
/** @var QueryInterface $query */
$query = $this->createQuery();
$querySettings = $query->getQuerySettings();
......@@ -192,6 +195,14 @@ class JobRepository extends Repository {
$query->matching($query->logicalAnd($constraints));
}
if ($limit > 0) {
$query->setLimit($limit);
}
if ($offset > 0) {
$query->setOffset($offset);
}
return $query->execute();
}
}
......@@ -290,10 +290,12 @@ class FrontendFilterService {
*
* @param array $filters
* @param int $recordPageId
* @param int $limit
* @param int $offset
* @return mixed
* @throws \InvalidArgumentException
*/
public static function getJobs(array $filters = [], $recordPageId): array {
public static function getJobs(array $filters = [], $recordPageId, $limit = 0, $offset = 0): array {
// get all company ids
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
'tx_sgjobs_domain_model_company'
......@@ -363,6 +365,6 @@ class FrontendFilterService {
}
// return the filtered jobs
return $jobRepository->findByCompanyId($recordPageId, $result)->toArray();
return $jobRepository->findByCompanyId($recordPageId, $result, $limit, $offset)->toArray();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment