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\AbstractFacet; |
18
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\AbstractFacetItemCollection; |
19
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Value object that represent a date range facet. |
23
|
|
|
* |
24
|
|
|
* @author Frans Saris <[email protected]> |
25
|
|
|
* @author Timo Hund <[email protected]> |
26
|
|
|
* @package ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionsFacet |
27
|
|
|
*/ |
28
|
|
|
class DateRangeFacet extends AbstractFacet |
29
|
|
|
{ |
30
|
|
|
const TYPE_DATE_RANGE = 'dateRange'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* String |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected static $type = self::TYPE_DATE_RANGE; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var DateRange |
40
|
|
|
*/ |
41
|
|
|
protected $range; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* OptionsFacet constructor |
45
|
|
|
* |
46
|
|
|
* @param SearchResultSet $resultSet |
47
|
|
|
* @param string $name |
48
|
|
|
* @param string $field |
49
|
|
|
* @param string $label |
50
|
|
|
* @param array $configuration Facet configuration passed from typoscript |
51
|
|
|
*/ |
52
|
2 |
|
public function __construct(SearchResultSet $resultSet, $name, $field, $label = '', array $configuration = []) |
53
|
|
|
{ |
54
|
2 |
|
parent::__construct($resultSet, $name, $field, $label, $configuration); |
55
|
2 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param DateRange $range |
59
|
|
|
*/ |
60
|
2 |
|
public function setRange(DateRange $range) |
61
|
|
|
{ |
62
|
2 |
|
$this->range = $range; |
63
|
2 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return DateRange |
67
|
|
|
*/ |
68
|
2 |
|
public function getRange() |
69
|
|
|
{ |
70
|
2 |
|
return $this->range; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get facet partial name used for rendering the facet |
76
|
|
|
* |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
1 |
|
public function getPartialName() |
80
|
|
|
{ |
81
|
1 |
|
return !empty($this->configuration['partialName']) ? $this->configuration['partialName'] : 'RangeDate.html'; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Since the DateRange contains only one or two items when return a collection with the range only to |
86
|
|
|
* allow to render the date range as other facet items. |
87
|
|
|
* |
88
|
|
|
* @return AbstractFacetItemCollection |
89
|
|
|
*/ |
90
|
|
|
public function getAllFacetItems() |
91
|
|
|
{ |
92
|
|
|
return new DateRangeCollection([$this->range]); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|