mirror of
https://github.com/werkraum-media/events.git
synced 2024-11-10 03:56:09 +01:00
Add query callback to date demand
This allows 3rd party to alter the query of dates when demand is used. E.g. allow more complex filters specific for some situations like CEs. Relates: #9505
This commit is contained in:
parent
30f030aab6
commit
ce3863619e
3 changed files with 43 additions and 1 deletions
|
@ -80,6 +80,11 @@ class DateDemand
|
|||
*/
|
||||
protected $considerDate = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $queryCallback = '';
|
||||
|
||||
public static function createFromRequestValues(
|
||||
array $submittedValues,
|
||||
array $settings
|
||||
|
@ -110,6 +115,7 @@ class DateDemand
|
|||
|
||||
$instance->setSortBy($settings['sortByDate'] ?? '');
|
||||
$instance->setSortOrder($settings['sortOrder'] ?? '');
|
||||
$instance->setQueryCallback($settings['queryCallback'] ?? '');
|
||||
|
||||
if (!empty($settings['limit'])) {
|
||||
$instance->setLimit($settings['limit']);
|
||||
|
@ -275,4 +281,14 @@ class DateDemand
|
|||
{
|
||||
$this->considerDate = $considerDate;
|
||||
}
|
||||
|
||||
public function getQueryCalback(): string
|
||||
{
|
||||
return $this->queryCallback;
|
||||
}
|
||||
|
||||
public function setQueryCallback(string $queryCallback): void
|
||||
{
|
||||
$this->queryCallback = $queryCallback;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ class DateDemandFactory
|
|||
): void {
|
||||
$this->contentObjectRenderer = $contentObjectRenderer;
|
||||
}
|
||||
|
||||
public function fromSettings(array $settings): DateDemand
|
||||
{
|
||||
$demand = new DateDemand();
|
||||
|
@ -75,6 +76,9 @@ class DateDemandFactory
|
|||
if (!empty($settings['limit'])) {
|
||||
$demand->setLimit($settings['limit']);
|
||||
}
|
||||
if (!empty($settings['queryCallback'])) {
|
||||
$demand->setQueryCallback($settings['queryCallback']);
|
||||
}
|
||||
|
||||
return $demand;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Wrm\Events\Domain\Repository;
|
||||
|
||||
use TYPO3\CMS\Core\Context\Context;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface;
|
||||
|
@ -14,6 +15,16 @@ use Wrm\Events\Service\CategoryService;
|
|||
|
||||
class DateRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* @var Context
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
public function injectContext(Context $context): void
|
||||
{
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
public function findByUids(string $uids): QueryResult
|
||||
{
|
||||
$uids = explode(',', $uids);
|
||||
|
@ -80,7 +91,12 @@ class DateRepository extends Repository
|
|||
}
|
||||
|
||||
if ($demand->getStart() === null && $demand->getEnd() === null) {
|
||||
$now = new \DateTime('now', new \DateTimeZone('Europe/Berlin'));
|
||||
$now = $this->context->getPropertyFromAspect(
|
||||
'date',
|
||||
'full',
|
||||
new \DateTimeImmutable()
|
||||
);
|
||||
$now = $now->modify('midnight');
|
||||
$constraints['nowAndFuture'] = $query->logicalOr([
|
||||
$query->greaterThanOrEqual('start', $now),
|
||||
$query->greaterThanOrEqual('end', $now)
|
||||
|
@ -97,6 +113,12 @@ class DateRepository extends Repository
|
|||
|
||||
$query->setOrderings([$demand->getSortBy() => $demand->getSortOrder()]);
|
||||
|
||||
$callback = $demand->getQueryCalback();
|
||||
if ($callback !== '') {
|
||||
$params = ['query' => &$query];
|
||||
GeneralUtility::callUserFunction($callback, $params, $this);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue