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

[TASK] Creation of job repository with filters

parent 1d8ddd0b
No related branches found
No related tags found
No related merge requests found
<?php
namespace SGalinski\SgJobs\Domain\Repository;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;
/**
* Job Repository
*/
class JobRepository extends Repository {
/**
* initializes the object
*/
public function initializeObject() {
$querySettings = $this->createQuery()->getQuerySettings();
$querySettings->setIgnoreEnableFields(TRUE);
$querySettings->setEnableFieldsToBeIgnored(['disabled']);
$this->setDefaultQuerySettings($querySettings);
}
/**
* Queries the job records based on filters
*
* @param int $pageUid
* @param array $filters
* @param boolean $raw
* @return mixed
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @throws \InvalidArgumentException
*/
public function findJobs($pageUid, array $filters = [], $raw = FALSE) {
$query = $this->createQuery();
$querySettings = $query->getQuerySettings();
$querySettings->setStoragePageIds([$pageUid]);
$query->setQuerySettings($querySettings);
$query->setOrderings(
[
'sorting' => QueryInterface::ORDER_ASCENDING,
]
);
$constraints = [];
if (isset($filters['locations']) && is_array($filters['locations']) && count($filters['locations'])) {
$locationConstraints = [];
foreach ($filters['locations'] as $location) {
if ((int) $location) {
$locationConstraints[] = $query->contains('location', $location);
}
}
if (count($locationConstraints)) {
$constraints[] = $query->logicalOr($locationConstraints);
}
}
if (isset($filters['search']) && $filters['search'] !== '') {
$searchConstraints = [];
$searchConstraints[] = $query->equals('uid', $filters['search']);
$searchConstraints[] = $query->like('title', '%' . $filters['search'] . '%');
$searchConstraints[] = $query->like('subtitle', '%' . $filters['search'] . '%');
$searchConstraints[] = $query->like('description', '%' . $filters['search'] . '%');
$constraints[] = $query->logicalOr($searchConstraints);
}
if (count($constraints) > 1) {
$query->matching($query->logicalAnd($constraints));
} elseif (count($constraints)) {
$query->matching($constraints[0]);
}
return $query->execute($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