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