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 {
*/
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);
}
}
......@@ -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();
}
}
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