Skip to content
Snippets Groups Projects
Commit dffc4257 authored by Stefan Galinski's avatar Stefan Galinski :video_game:
Browse files

[BUGFIX] Fix totally stupid job teaser repository filter integration (tons of side effects)

parent 1af7639f
No related branches found
No related tags found
No related merge requests found
...@@ -54,7 +54,7 @@ class JobTeaserController extends ActionController { ...@@ -54,7 +54,7 @@ class JobTeaserController extends ActionController {
*/ */
public function indexAction(): void { public function indexAction(): void {
$allowedLocations = []; $allowedLocations = [];
if (!empty($this->settings['locations'])) { if ($this->settings['locations'] !== '') {
$allowedLocations = GeneralUtility::trimExplode(',', $this->settings['locations']); $allowedLocations = GeneralUtility::trimExplode(',', $this->settings['locations']);
} }
$totalAmountOfOffers = $this->jobRepository->countAll($allowedLocations); $totalAmountOfOffers = $this->jobRepository->countAll($allowedLocations);
...@@ -65,7 +65,7 @@ class JobTeaserController extends ActionController { ...@@ -65,7 +65,7 @@ class JobTeaserController extends ActionController {
$featuredOffers = $this->jobRepository->findByFeaturedOffer($allowedLocations); $featuredOffers = $this->jobRepository->findByFeaturedOffer($allowedLocations);
$this->view->assign('totalAmountOfOffers', $totalAmountOfOffers); $this->view->assign('totalAmountOfOffers', $totalAmountOfOffers);
$this->view->assign('filteredLocations', !empty($allowedLocations)); $this->view->assign('filteredLocations', (bool) count($allowedLocations));
$this->view->assign('featuredOffers', $featuredOffers); $this->view->assign('featuredOffers', $featuredOffers);
} }
} }
...@@ -26,7 +26,6 @@ namespace SGalinski\SgJobs\Domain\Repository; ...@@ -26,7 +26,6 @@ namespace SGalinski\SgJobs\Domain\Repository;
* This copyright notice MUST APPEAR in all copies of the script! * This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/ ***************************************************************/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings; use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
use TYPO3\CMS\Extbase\Persistence\QueryInterface; use TYPO3\CMS\Extbase\Persistence\QueryInterface;
...@@ -49,7 +48,6 @@ class JobRepository extends Repository { ...@@ -49,7 +48,6 @@ class JobRepository extends Repository {
public function __construct(ObjectManagerInterface $objectManager) { public function __construct(ObjectManagerInterface $objectManager) {
parent::__construct($objectManager); parent::__construct($objectManager);
// Appearently some of the extbase classes still need the objectManager
$querySettings = $objectManager->get(Typo3QuerySettings::class); $querySettings = $objectManager->get(Typo3QuerySettings::class);
$querySettings->setRespectStoragePage(TRUE); $querySettings->setRespectStoragePage(TRUE);
$this->setDefaultQuerySettings($querySettings); $this->setDefaultQuerySettings($querySettings);
...@@ -77,7 +75,7 @@ class JobRepository extends Repository { ...@@ -77,7 +75,7 @@ class JobRepository extends Repository {
* @param int $limit * @param int $limit
* @param int $offset * @param int $offset
* @return mixed * @return mixed
* @throws \InvalidArgumentException * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/ */
public function findBackendJobs($recordPageId, array $filters = [], $limit = 0, $offset = 0) { public function findBackendJobs($recordPageId, array $filters = [], $limit = 0, $offset = 0) {
$query = $this->createQuery(); $query = $this->createQuery();
...@@ -111,7 +109,7 @@ class JobRepository extends Repository { ...@@ -111,7 +109,7 @@ class JobRepository extends Repository {
return $query->matching($query->logicalAnd($constraints))->execute(); return $query->matching($query->logicalAnd($constraints))->execute();
} }
if(\count($constraints) > 0) { if (\count($constraints) > 0) {
return $query->matching($constraints[0])->execute(); return $query->matching($constraints[0])->execute();
} }
...@@ -146,7 +144,7 @@ class JobRepository extends Repository { ...@@ -146,7 +144,7 @@ class JobRepository extends Repository {
$constraints = []; $constraints = [];
if ($jobIds !== NULL && \is_array($jobIds) && \count($jobIds)) { if (\is_array($jobIds) && \count($jobIds)) {
$companyConstraints = []; $companyConstraints = [];
foreach ($jobIds as $jobId) { foreach ($jobIds as $jobId) {
if ($jobId) { if ($jobId) {
...@@ -261,7 +259,6 @@ class JobRepository extends Repository { ...@@ -261,7 +259,6 @@ class JobRepository extends Repository {
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/ */
public function countAll(array $companies = []): int { public function countAll(array $companies = []): int {
/** @var QueryInterface $query */
$query = $this->createQuery(); $query = $this->createQuery();
$constraints = []; $constraints = [];
...@@ -284,32 +281,30 @@ class JobRepository extends Repository { ...@@ -284,32 +281,30 @@ class JobRepository extends Repository {
* Gets the featured jobs filtered by companies * Gets the featured jobs filtered by companies
* *
* @param array $companies * @param array $companies
* @return mixed * @param int $limit
* @return array|ExtbaseQueryResultInterface
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/ */
public function findByFeaturedOffer(array $companies = []) { public function findByFeaturedOffer(array $companies = [], int $limit = 3) {
/** @var QueryInterface $query */
$query = $this->createQuery(); $query = $this->createQuery();
$constraints = [];
$storagePageIds = $query->getQuerySettings()->getStoragePageIds(); $storagePageIds = $query->getQuerySettings()->getStoragePageIds();
if (empty($storagePageIds)) { if (count($storagePageIds) <= 0) {
// if no record storage page has been selected in the plugin, ignore it // if no record storage page has been selected in the plugin, ignore it
$query->getQuerySettings()->setRespectStoragePage(FALSE); $query->getQuerySettings()->setRespectStoragePage(FALSE);
} }
if (\count($companies) !== 0) { if (\count($companies)) {
$constraints[] = $query->in('company', $companies); $query->matching($query->in('company', $companies));
$query->setOrderings(
[
'featured_offer' => QueryInterface::ORDER_DESCENDING
]
);
$query->setLimit(3);
} else {
$constraints[] = $query->equals('featured_offer', TRUE);
} }
return $query->matching($query->logicalAnd($constraints))->execute(); $query->setOrderings(
[
'featured_offer' => QueryInterface::ORDER_DESCENDING
]
);
$query->setLimit($limit);
return $query->execute();
} }
} }
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