1
|
|
|
<?php |
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RangeBased\DateRange; |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the TYPO3 CMS project. |
6
|
|
|
* |
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
9
|
|
|
* of the License, or any later version. |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please read the |
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
13
|
|
|
* |
14
|
|
|
* The TYPO3 project - inspiring people to share! |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RangeBased\AbstractRangeFacetParser; |
18
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet; |
19
|
|
|
use ApacheSolrForTypo3\Solr\System\Data\DateTime; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class DateRangeFacetParser |
23
|
|
|
* |
24
|
|
|
* @author Frans Saris <[email protected]> |
25
|
|
|
* @author Timo Hund <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class DateRangeFacetParser extends AbstractRangeFacetParser |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $facetClass = DateRangeFacet::class; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $facetItemClass = DateRange::class; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
protected $facetRangeCountClass = DateRangeCount::class; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param SearchResultSet $resultSet |
46
|
|
|
* @param string $facetName |
47
|
|
|
* @param array $facetConfiguration |
48
|
|
|
* @return DateRangeFacet|null |
49
|
|
|
*/ |
50
|
1 |
|
public function parse(SearchResultSet $resultSet, $facetName, array $facetConfiguration) |
51
|
|
|
{ |
52
|
1 |
|
return $this->getParsedFacet( |
53
|
1 |
|
$resultSet, |
54
|
1 |
|
$facetName, |
55
|
1 |
|
$facetConfiguration, |
56
|
1 |
|
$this->facetClass, |
57
|
1 |
|
$this->facetItemClass, |
58
|
1 |
|
$this->facetRangeCountClass |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string $rawDate |
64
|
|
|
* @return DateTime|null |
65
|
|
|
*/ |
66
|
1 |
|
protected function parseRequestValue($rawDate) |
67
|
|
|
{ |
68
|
1 |
|
$rawDate = \DateTime::createFromFormat('Ymd', substr($rawDate, 0, 8)); |
69
|
1 |
|
if ($rawDate === false) { |
70
|
1 |
|
return null; |
71
|
|
|
} |
72
|
|
|
$date = new DateTime($rawDate->format(DateTime::ISO8601)); |
73
|
|
|
return $date; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param string $isoDateString |
78
|
|
|
* @return DateTime |
79
|
|
|
*/ |
80
|
1 |
|
protected function parseResponseValue($isoDateString) |
81
|
|
|
{ |
82
|
1 |
|
$rawDate = \DateTime::createFromFormat(\DateTime::ISO8601, $isoDateString); |
83
|
1 |
|
return new DateTime($rawDate->format(DateTime::ISO8601)); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|