2019-07-18 13:44:19 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wrm\Events\Domain\Model\Dto;
|
|
|
|
|
2021-07-13 12:11:47 +02:00
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
|
|
|
2021-01-07 08:50:43 +01:00
|
|
|
class DateDemand
|
|
|
|
{
|
2019-07-18 13:44:19 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $sortBy = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $sortOrder = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $categories = '';
|
|
|
|
|
2021-07-13 15:50:14 +02:00
|
|
|
/**
|
2022-06-28 11:38:55 +02:00
|
|
|
* @var int[]
|
2021-07-13 15:50:14 +02:00
|
|
|
*/
|
|
|
|
protected $userCategories = [];
|
|
|
|
|
2019-07-18 13:44:19 +02:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $includeSubCategories = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $categoryCombination = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
2022-06-28 11:38:55 +02:00
|
|
|
* Legacy, superceeded by regions which allows multi select / filter.
|
2019-07-18 13:44:19 +02:00
|
|
|
*/
|
2019-08-14 17:22:01 +02:00
|
|
|
protected $region = '';
|
2019-07-18 13:44:19 +02:00
|
|
|
|
2022-06-28 11:38:55 +02:00
|
|
|
/**
|
|
|
|
* @var int[]
|
|
|
|
*/
|
|
|
|
protected $regions = [];
|
|
|
|
|
2019-07-18 13:44:19 +02:00
|
|
|
/**
|
2019-08-14 17:22:01 +02:00
|
|
|
* @var bool
|
2019-07-18 13:44:19 +02:00
|
|
|
*/
|
2021-09-07 09:52:14 +02:00
|
|
|
protected $highlight = false;
|
2019-07-18 13:44:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $limit = '';
|
|
|
|
|
2019-08-14 17:22:01 +02:00
|
|
|
/**
|
2021-09-07 09:52:14 +02:00
|
|
|
* @var int|null
|
2019-08-14 17:22:01 +02:00
|
|
|
*/
|
2021-09-07 09:52:14 +02:00
|
|
|
protected $start = null;
|
2019-08-14 17:22:01 +02:00
|
|
|
|
|
|
|
/**
|
2021-09-07 09:52:14 +02:00
|
|
|
* @var int|null
|
2019-08-14 17:22:01 +02:00
|
|
|
*/
|
2021-09-07 09:52:14 +02:00
|
|
|
protected $end = null;
|
2019-08-14 17:22:01 +02:00
|
|
|
|
2022-05-16 13:24:39 +02:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $useMidnight = true;
|
|
|
|
|
2019-08-14 17:22:01 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $searchword = '';
|
|
|
|
|
2021-07-13 12:11:47 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*
|
|
|
|
* Synonym1 => ['word1', 'word2', …],
|
|
|
|
* Synonym2 => ['word3', 'word4', …],
|
|
|
|
* …
|
|
|
|
*/
|
|
|
|
protected $synonyms = [];
|
|
|
|
|
2019-11-13 10:46:21 +01:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
2021-09-07 09:52:14 +02:00
|
|
|
protected $considerDate = false;
|
2019-11-13 10:46:21 +01:00
|
|
|
|
2021-12-07 15:26:25 +01:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $queryCallback = '';
|
|
|
|
|
2021-07-13 15:50:14 +02:00
|
|
|
public static function createFromRequestValues(
|
|
|
|
array $submittedValues,
|
|
|
|
array $settings
|
|
|
|
): self {
|
|
|
|
$instance = new self();
|
|
|
|
$instance->setSearchword($submittedValues['searchword'] ?? '');
|
|
|
|
$instance->setSynonyms($settings['synonyms'] ?? []);
|
|
|
|
|
|
|
|
$instance->setRegion($submittedValues['region'] ?? '');
|
2022-06-28 11:38:55 +02:00
|
|
|
if (isset($submittedValues['regions']) && is_array($submittedValues['regions'])) {
|
|
|
|
$instance->setRegions($submittedValues['regions']);
|
|
|
|
}
|
2021-07-13 15:50:14 +02:00
|
|
|
|
|
|
|
if ($submittedValues['highlight'] ?? false) {
|
|
|
|
$instance->setHighlight($settings['highlight'] ?? false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($submittedValues['start']) && $submittedValues['start'] !== '') {
|
2021-09-07 09:52:14 +02:00
|
|
|
$instance->setStart(strtotime($submittedValues['start'] . ' 00:00') ?: null);
|
2021-07-13 15:50:14 +02:00
|
|
|
}
|
|
|
|
if (isset($submittedValues['end']) && $submittedValues['end'] !== '') {
|
2021-09-07 09:52:14 +02:00
|
|
|
$instance->setEnd(strtotime($submittedValues['end'] . ' 23:59') ?: null);
|
2021-07-13 15:50:14 +02:00
|
|
|
}
|
|
|
|
if (isset($submittedValues['considerDate']) && $submittedValues['considerDate'] !== '') {
|
2021-09-07 09:52:14 +02:00
|
|
|
$instance->setConsiderDate((bool)$submittedValues['considerDate']);
|
2021-07-13 15:50:14 +02:00
|
|
|
}
|
|
|
|
|
2022-06-28 11:38:55 +02:00
|
|
|
if (isset($submittedValues['userCategories']) && is_array($submittedValues['userCategories'])) {
|
|
|
|
$instance->setUserCategories($submittedValues['userCategories']);
|
2021-07-13 15:50:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$instance->setSortBy($settings['sortByDate'] ?? '');
|
|
|
|
$instance->setSortOrder($settings['sortOrder'] ?? '');
|
2021-12-07 15:26:25 +01:00
|
|
|
$instance->setQueryCallback($settings['queryCallback'] ?? '');
|
2021-07-13 15:50:14 +02:00
|
|
|
|
|
|
|
if (!empty($settings['limit'])) {
|
|
|
|
$instance->setLimit($settings['limit']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
2019-07-18 13:44:19 +02:00
|
|
|
public function getSortBy(): string
|
|
|
|
{
|
|
|
|
return $this->sortBy;
|
|
|
|
}
|
|
|
|
|
2021-09-07 09:52:14 +02:00
|
|
|
public function setSortBy(string $sortBy): void
|
2019-07-18 13:44:19 +02:00
|
|
|
{
|
|
|
|
$this->sortBy = $sortBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSortOrder(): string
|
|
|
|
{
|
|
|
|
return $this->sortOrder;
|
|
|
|
}
|
|
|
|
|
2021-09-07 09:52:14 +02:00
|
|
|
public function setSortOrder(string $sortOrder): void
|
2019-07-18 13:44:19 +02:00
|
|
|
{
|
|
|
|
$this->sortOrder = $sortOrder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCategories(): string
|
|
|
|
{
|
|
|
|
return $this->categories;
|
|
|
|
}
|
|
|
|
|
2022-06-28 11:38:55 +02:00
|
|
|
/**
|
|
|
|
* @param int[] $categories
|
|
|
|
*/
|
|
|
|
public function setUserCategories(array $categories): void
|
|
|
|
{
|
|
|
|
$this->userCategories = array_map('intval', $categories);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int[]
|
|
|
|
*/
|
2021-07-13 15:50:14 +02:00
|
|
|
public function getUserCategories(): array
|
|
|
|
{
|
|
|
|
return $this->userCategories;
|
|
|
|
}
|
|
|
|
|
2021-09-07 09:52:14 +02:00
|
|
|
public function setCategories(string $categories): void
|
2019-07-18 13:44:19 +02:00
|
|
|
{
|
|
|
|
$this->categories = $categories;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIncludeSubCategories(): bool
|
|
|
|
{
|
|
|
|
return $this->includeSubCategories;
|
|
|
|
}
|
|
|
|
|
2021-09-07 09:52:14 +02:00
|
|
|
public function setIncludeSubCategories(bool $includeSubCategories): void
|
2019-07-18 13:44:19 +02:00
|
|
|
{
|
|
|
|
$this->includeSubCategories = $includeSubCategories;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCategoryCombination(): string
|
|
|
|
{
|
|
|
|
return $this->categoryCombination;
|
|
|
|
}
|
|
|
|
|
2021-09-07 09:52:14 +02:00
|
|
|
public function setCategoryCombination(string $categoryCombination): void
|
2019-07-18 13:44:19 +02:00
|
|
|
{
|
|
|
|
$this->categoryCombination = $categoryCombination;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRegion(): string
|
|
|
|
{
|
|
|
|
return $this->region;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setRegion(string $region): void
|
|
|
|
{
|
|
|
|
$this->region = $region;
|
|
|
|
}
|
|
|
|
|
2022-06-28 11:38:55 +02:00
|
|
|
/**
|
|
|
|
* @return int[]
|
|
|
|
*/
|
|
|
|
public function getRegions(): array
|
|
|
|
{
|
|
|
|
return $this->regions;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setRegions(array $regions): void
|
|
|
|
{
|
|
|
|
$this->regions = array_map('intval', $regions);
|
|
|
|
}
|
|
|
|
|
2019-08-14 17:22:01 +02:00
|
|
|
public function getHighlight(): bool
|
2019-07-18 13:44:19 +02:00
|
|
|
{
|
|
|
|
return $this->highlight;
|
|
|
|
}
|
|
|
|
|
2021-07-13 15:50:14 +02:00
|
|
|
public function setHighlight(bool $highlight): void
|
2019-07-18 13:44:19 +02:00
|
|
|
{
|
|
|
|
$this->highlight = $highlight;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLimit(): string
|
|
|
|
{
|
|
|
|
return $this->limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setLimit(string $limit): void
|
|
|
|
{
|
|
|
|
$this->limit = $limit;
|
|
|
|
}
|
|
|
|
|
2019-08-14 17:22:01 +02:00
|
|
|
public function getSearchword(): string
|
|
|
|
{
|
|
|
|
return $this->searchword;
|
|
|
|
}
|
2019-07-18 13:44:19 +02:00
|
|
|
|
2019-08-14 17:22:01 +02:00
|
|
|
public function setSearchword(string $searchword): void
|
|
|
|
{
|
|
|
|
$this->searchword = $searchword;
|
|
|
|
}
|
|
|
|
|
2021-07-13 12:11:47 +02:00
|
|
|
/**
|
|
|
|
* @param array $synonyms
|
|
|
|
* [
|
|
|
|
* [
|
|
|
|
* 'word' => 'Word1',
|
|
|
|
* 'synonyms' => 'synonym1, synonym2',
|
|
|
|
* ],
|
|
|
|
* [
|
|
|
|
* 'word' => 'Word2',
|
|
|
|
* 'synonyms' => 'synonym3, synonym4',
|
|
|
|
* ],
|
|
|
|
* …
|
|
|
|
* ]
|
|
|
|
*/
|
|
|
|
public function setSynonyms(array $synonyms): void
|
|
|
|
{
|
|
|
|
$this->synonyms = [];
|
|
|
|
foreach ($synonyms as $config) {
|
|
|
|
$synonymsForWord = GeneralUtility::trimExplode(',', $config['synonyms'], true);
|
|
|
|
foreach ($synonymsForWord as $synonym) {
|
|
|
|
$synonym = mb_strtolower($synonym);
|
|
|
|
$this->synonyms[$synonym][] = $config['word'];
|
|
|
|
$this->synonyms[$synonym] = array_unique($this->synonyms[$synonym]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSynonymsForSearchword(): array
|
|
|
|
{
|
|
|
|
$searchWord = mb_strtolower($this->getSearchword());
|
|
|
|
return $this->synonyms[$searchWord] ?? [];
|
|
|
|
}
|
|
|
|
|
2021-09-07 09:52:14 +02:00
|
|
|
public function getStart(): ?int
|
2019-08-14 17:22:01 +02:00
|
|
|
{
|
|
|
|
return $this->start;
|
|
|
|
}
|
|
|
|
|
2021-09-07 09:52:14 +02:00
|
|
|
public function setStart(?int $start): void
|
2019-08-14 17:22:01 +02:00
|
|
|
{
|
|
|
|
$this->start = $start;
|
|
|
|
}
|
|
|
|
|
2021-09-07 09:52:14 +02:00
|
|
|
public function getEnd(): ?int
|
2019-08-14 17:22:01 +02:00
|
|
|
{
|
|
|
|
return $this->end;
|
|
|
|
}
|
|
|
|
|
2021-09-07 09:52:14 +02:00
|
|
|
public function setEnd(?int $end): void
|
2019-08-14 17:22:01 +02:00
|
|
|
{
|
|
|
|
$this->end = $end;
|
|
|
|
}
|
2019-07-18 13:44:19 +02:00
|
|
|
|
2022-05-16 13:24:39 +02:00
|
|
|
public function setUseMidnight(bool $useMidnight): void
|
|
|
|
{
|
|
|
|
$this->useMidnight = $useMidnight;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldShowFromNow(): bool
|
|
|
|
{
|
|
|
|
return $this->getStart() === null
|
|
|
|
&& $this->getEnd() === null
|
|
|
|
&& $this->useMidnight === false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldShowFromMidnight(): bool
|
|
|
|
{
|
|
|
|
return $this->getStart() === null
|
|
|
|
&& $this->getEnd() === null
|
|
|
|
&& $this->useMidnight === true;
|
|
|
|
}
|
|
|
|
|
2019-11-13 10:46:21 +01:00
|
|
|
public function getConsiderDate(): bool
|
|
|
|
{
|
|
|
|
return $this->considerDate;
|
|
|
|
}
|
|
|
|
|
2021-09-07 09:52:14 +02:00
|
|
|
public function setConsiderDate(bool $considerDate): void
|
2019-11-13 10:46:21 +01:00
|
|
|
{
|
|
|
|
$this->considerDate = $considerDate;
|
|
|
|
}
|
2021-12-07 15:26:25 +01:00
|
|
|
|
|
|
|
public function getQueryCalback(): string
|
|
|
|
{
|
|
|
|
return $this->queryCallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setQueryCallback(string $queryCallback): void
|
|
|
|
{
|
|
|
|
$this->queryCallback = $queryCallback;
|
|
|
|
}
|
2021-07-13 15:50:14 +02:00
|
|
|
}
|