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

[TASK] Fixing backend filter

parent 1bd6f5ed
No related branches found
No related tags found
No related merge requests found
......@@ -79,7 +79,7 @@ class BackendController extends ActionController {
$this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent());
// get all jobs
/** @var ObjectStorage $jobs */
$jobs = $this->jobRepository->findJobs($pageUid, $filters);
$jobs = $this->jobRepository->findBackendJobs($pageUid, $filters);
$totalJobCount = \count($jobs);
......
......@@ -26,6 +26,7 @@ namespace SGalinski\SgJobs\Domain\Repository;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use Doctrine\DBAL\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer;
......@@ -52,7 +53,7 @@ class JobRepository extends Repository {
}
/**
* Queries the job records based on filters (for the backend)
* Queries the job records based on filters
*
* @param int $recordPageId
* @param array $filters
......@@ -122,6 +123,73 @@ class JobRepository extends Repository {
return $this->findByJobIds($recordPageId, $result, $limit, $offset);
}
/**
* Queries the job records based on filters (for the backend)
*
* @param int $recordPageId
* @param array $filters
* @param int $limit
* @param int $offset
* @return mixed
* @throws \InvalidArgumentException
*/
public function findBackendJobs($recordPageId, array $filters = [], $limit = 0, $offset = 0) {
// get all company ids
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
'tx_sgjobs_domain_model_company'
);
$statement = $queryBuilder->select('a.uid')
->from('tx_sgjobs_domain_model_job', 'a')
->join(
'a', 'tx_sgjobs_domain_model_company', 'b'
, $queryBuilder->expr()->eq('a.company', 'b.uid')
);
if (\is_array($filters['locations'])) {
$quotedLocationNames = $queryBuilder->createNamedParameter(
$filters['locations'], Connection::PARAM_STR_ARRAY
);
$statement->andWhere($queryBuilder->expr()->in('b.city', $quotedLocationNames));
} elseif ($filters['locations'] !== '' && $filters['locations'] !== NULL) {
$statement->andWhere(
$queryBuilder->expr()->eq(
'b.city', $queryBuilder->createNamedParameter($filters['locations'])
)
);
}
if ($filters['search'] !== '' && $filters['search'] !== NULL) {
$statement->andWhere(
$queryBuilder->expr()->like(
'a.title', $queryBuilder->createNamedParameter('%' . $filters['search'] . '%')
)
);
}
$statement->andWhere(
$queryBuilder->expr()->eq(
'b.pid', $queryBuilder->createNamedParameter($recordPageId)
)
);
$companies = $statement->execute()->fetchAll();
$result = [];
$result[0] = '';
foreach ($companies as $company) {
$result[$company['uid']] = $company['uid'];
}
// when filters are set, but there are no companies found, return an empty result
if (empty(!$filters) && empty($companies)) {
return $companies;
}
// return the filtered jobs
return $this->findByJobIds($recordPageId, $result, $limit, $offset);
}
/**
* Returns all areas filtered by page id
*
......
......@@ -5,7 +5,7 @@
<label for="filter-locations">
<f:translate key="backend.filters.locations" />
</label>
<f:form.select class="form-control" multiple="1" size="4" property="locations" optionLabelField="name" options="{locationOptions}" id="filter-locations" />
<f:form.select class="form-control" multiple="1" size="4" property="locations" optionLabelField="name" optionValueField="city" options="{locationOptions}" id="filter-locations" />
<small>
<f:format.raw><f:translate key="backend.filters.locations.description" />
</f:format.raw>
......
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