1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the TYPO3 CMS project. |
7
|
|
|
* |
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
10
|
|
|
* of the License, or any later version. |
11
|
|
|
* |
12
|
|
|
* For the full copyright and license information, please read the |
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
14
|
|
|
* |
15
|
|
|
* The TYPO3 project - inspiring people to share! |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RangeBased\DateRange; |
19
|
|
|
|
20
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\FacetUrlDecoderInterface; |
21
|
|
|
use ApacheSolrForTypo3\Solr\System\DateTime\FormatService; |
22
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Parser to build solr range queries from tx_solr[filter] |
26
|
|
|
* |
27
|
|
|
* @author Markus Goldbach <[email protected]> |
28
|
|
|
* @copyright (c) 2010-2011 Markus Goldbach <[email protected]> |
29
|
|
|
* @copyright (c) 2012-2015 Ingo Renner <[email protected]> |
30
|
|
|
*/ |
31
|
|
|
class DateRangeUrlDecoder implements FacetUrlDecoderInterface |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Delimiter for date parts in the URL. |
35
|
|
|
* |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
const DELIMITER = '-'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Parses the given date range from a GET parameter and returns a Solr |
42
|
|
|
* date range filter. |
43
|
|
|
* |
44
|
|
|
* @param string $value The range filter query string from the query URL |
45
|
|
|
* @param array $configuration Facet configuration |
46
|
|
|
* @return string Lucene query language filter to be used for querying Solr |
47
|
|
|
*/ |
48
|
|
|
public function decode(string $value, array $configuration = []): string |
49
|
|
|
{ |
50
|
|
|
list($dateRangeStart, $dateRangeEnd) = explode(self::DELIMITER, $value); |
51
|
|
|
|
52
|
|
|
/* @var FormatService $formatService */ |
53
|
|
|
$formatService = GeneralUtility::makeInstance(FormatService::class); |
54
|
|
|
$fromPart = '*'; |
55
|
|
|
if ($dateRangeStart !== '') { |
56
|
|
|
$fromPart = $formatService->timestampToIso(strtotime($dateRangeStart)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$toPart = '*'; |
60
|
|
|
if ($dateRangeEnd !== '') { |
61
|
|
|
$dateRangeEnd .= '59'; // adding 59 seconds |
62
|
|
|
$toPart = $formatService->timestampToIso(strtotime($dateRangeEnd)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return '[' . $fromPart . ' TO ' . $toPart . ']'; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|