events/Classes/Domain/Model/Dto/DateDemand.php

382 lines
7.6 KiB
PHP
Raw Normal View History

<?php
namespace Wrm\Events\Domain\Model\Dto;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class DateDemand
{
/**
* @var string
*/
protected $sortBy = '';
/**
* @var string
*/
protected $sortOrder = '';
/**
* @var string
*/
protected $categories = '';
2021-07-13 15:50:14 +02:00
/**
* @var int[]
2021-07-13 15:50:14 +02:00
*/
protected $userCategories = [];
/**
* @var int[]
*/
protected $features = [];
/**
* @var bool
*/
protected $includeSubCategories = false;
/**
* @var string
*/
protected $categoryCombination = '';
/**
* @var int[]
*/
protected $regions = [];
2022-08-02 15:56:18 +02:00
/**
* @var int[]
*/
protected $locations = [];
/**
2019-08-14 17:22:01 +02:00
* @var bool
*/
protected $highlight = false;
/**
* @var string
*/
protected $limit = '';
2019-08-14 17:22:01 +02:00
/**
* @var null|\DateTimeImmutable
2019-08-14 17:22:01 +02:00
*/
protected $startObject = null;
2019-08-14 17:22:01 +02:00
/**
* @var null|\DateTimeImmutable
2019-08-14 17:22:01 +02:00
*/
protected $endObject = null;
2019-08-14 17:22:01 +02:00
/**
* @var bool
*/
protected $useMidnight = true;
2019-08-14 17:22:01 +02:00
/**
* @var string
*/
protected $searchword = '';
/**
* @var array
*
* Synonym1 => ['word1', 'word2', ],
* Synonym2 => ['word3', 'word4', ],
*
*/
protected $synonyms = [];
2019-11-13 10:46:21 +01:00
/**
* @var bool
*/
protected $considerDate = false;
2019-11-13 10:46:21 +01:00
/**
* @var string
*/
protected $queryCallback = '';
public function getSortBy(): string
{
return $this->sortBy;
}
public function setSortBy(string $sortBy): void
{
$this->sortBy = $sortBy;
}
public function getSortOrder(): string
{
return $this->sortOrder;
}
public function setSortOrder(string $sortOrder): void
{
$this->sortOrder = $sortOrder;
}
public function getCategories(): string
{
return $this->categories;
}
/**
* @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;
}
public function setCategories(string $categories): void
{
$this->categories = $categories;
}
/**
* @param int[] $categories
*/
public function setFeatures(array $categories): void
{
$this->features = array_map('intval', $categories);
}
/**
* @return int[]
*/
public function getFeatures(): array
{
return $this->features;
}
public function getIncludeSubCategories(): bool
{
return $this->includeSubCategories;
}
public function setIncludeSubCategories(bool $includeSubCategories): void
{
$this->includeSubCategories = $includeSubCategories;
}
public function getCategoryCombination(): string
{
return $this->categoryCombination;
}
public function setCategoryCombination(string $categoryCombination): void
{
$this->categoryCombination = $categoryCombination;
}
public function getRegion(): string
{
return implode(',', $this->regions);
}
/**
* @return int[]
*/
public function getRegions(): array
{
return $this->regions;
}
public function setRegions(array $regions): void
{
$this->regions = array_map('intval', $regions);
}
2022-08-02 15:56:18 +02:00
/**
* @return int[]
*/
public function getLocations(): array
{
return $this->locations;
}
public function setLocations(array $locations): void
{
$this->locations = array_map('intval', $locations);
}
2019-08-14 17:22:01 +02:00
public function getHighlight(): bool
{
return $this->highlight;
}
2021-07-13 15:50:14 +02:00
public function setHighlight(bool $highlight): void
{
$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-08-14 17:22:01 +02:00
public function setSearchword(string $searchword): void
{
$this->searchword = $searchword;
}
/**
* @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] ?? [];
}
public function getStartObject(): ?\DateTimeImmutable
{
return $this->startObject;
}
2022-11-22 12:58:36 +01:00
/**
* Returns necessary format for forms.
*
* @internal Only for Extbase/Fluid.
*/
public function getStart(): string
2019-08-14 17:22:01 +02:00
{
if ($this->getStartObject() === null) {
2022-11-22 12:58:36 +01:00
return '';
}
2022-11-22 12:58:36 +01:00
return $this->getStartObject()->format('Y-m-d');
2019-08-14 17:22:01 +02:00
}
public function setStart(?int $start): void
2019-08-14 17:22:01 +02:00
{
if ($start === null) {
return;
}
$this->startObject = new \DateTimeImmutable(date('Y-m-d H:i', $start));
}
public function getEndObject(): ?\DateTimeImmutable
{
return $this->endObject;
}
public function getEndsOnSameDay(): bool
{
if ($this->getStartObject() === null || $this->getEndObject() === null) {
return true;
}
return $this->getStartObject()->format('Y-m-d') === $this->getEndObject()->format('Y-m-d');
2019-08-14 17:22:01 +02:00
}
2022-11-22 12:58:36 +01:00
/**
* Returns necessary format for forms.
*
* @internal Only for Extbase/Fluid.
*/
public function getEnd(): string
2019-08-14 17:22:01 +02:00
{
if ($this->getEndObject() === null) {
2022-11-22 12:58:36 +01:00
return '';
}
2022-11-22 12:58:36 +01:00
return $this->getEndObject()->format('Y-m-d');
2019-08-14 17:22:01 +02:00
}
public function setEnd(?int $end): void
2019-08-14 17:22:01 +02:00
{
if ($end === null) {
return;
}
$this->endObject = new \DateTimeImmutable(date('Y-m-d H:i', $end));
2019-08-14 17:22:01 +02:00
}
public function setUseMidnight(bool $useMidnight): void
{
$this->useMidnight = $useMidnight;
}
public function shouldShowFromNow(): bool
{
2022-11-22 12:58:36 +01:00
return $this->getStartObject() === null
&& $this->getEndObject() === null
&& $this->useMidnight === false;
}
public function shouldShowFromMidnight(): bool
{
2022-11-22 12:58:36 +01:00
return $this->getStartObject() === null
&& $this->getEndObject() === null
&& $this->useMidnight === true;
}
2019-11-13 10:46:21 +01:00
public function getConsiderDate(): bool
{
return $this->considerDate;
}
public function setConsiderDate(bool $considerDate): void
2019-11-13 10:46:21 +01:00
{
$this->considerDate = $considerDate;
}
public function getQueryCalback(): string
{
return $this->queryCallback;
}
public function setQueryCallback(string $queryCallback): void
{
$this->queryCallback = $queryCallback;
}
2021-07-13 15:50:14 +02:00
}