1
|
|
|
<?php |
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RangeBased\DateRange; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2010-2011 Markus Goldbach <[email protected]> |
8
|
|
|
* (c) 2012-2015 Ingo Renner <[email protected]> |
9
|
|
|
* All rights reserved |
10
|
|
|
* |
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
12
|
|
|
* free software; you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU General Public License as published by |
14
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
15
|
|
|
* (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* The GNU General Public License can be found at |
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
19
|
|
|
* |
20
|
|
|
* This script is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
26
|
|
|
***************************************************************/ |
27
|
|
|
|
28
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\FacetUrlDecoderInterface; |
29
|
|
|
use ApacheSolrForTypo3\Solr\System\DateTime\FormatService; |
30
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Parser to build solr range queries from tx_solr[filter] |
34
|
|
|
* |
35
|
|
|
* @author Markus Goldbach <[email protected]> |
36
|
|
|
*/ |
37
|
|
|
class DateRangeUrlDecoder implements FacetUrlDecoderInterface |
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Delimiter for date parts in the URL. |
42
|
|
|
* |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
const DELIMITER = '-'; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Parses the given date range from a GET parameter and returns a Solr |
49
|
|
|
* date range filter. |
50
|
|
|
* |
51
|
|
|
* @param string $dateRange The range filter query string from the query URL |
52
|
|
|
* @param array $configuration Facet configuration |
53
|
|
|
* @return string Lucene query language filter to be used for querying Solr |
54
|
|
|
*/ |
55
|
1 |
|
public function decode($dateRange, array $configuration = []) |
56
|
|
|
{ |
57
|
1 |
|
list($dateRangeStart, $dateRangeEnd) = explode(self::DELIMITER, $dateRange); |
58
|
|
|
|
59
|
1 |
|
$dateRangeEnd .= '59'; // adding 59 seconds |
60
|
|
|
|
61
|
1 |
|
$formatService = GeneralUtility::makeInstance(FormatService::class); |
62
|
1 |
|
$dateRangeFilter = '[' . $formatService->timestampToIso(strtotime($dateRangeStart)); |
63
|
1 |
|
$dateRangeFilter .= ' TO '; |
64
|
1 |
|
$dateRangeFilter .= $formatService->timestampToIso(strtotime($dateRangeEnd)) . ']'; |
65
|
1 |
|
return $dateRangeFilter; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|