|
1
|
|
|
<?php |
|
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets; |
|
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
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\AbstractFacetItem; |
|
17
|
|
|
use ApacheSolrForTypo3\Solr\System\Data\AbstractCollection; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Collection for facet options. |
|
21
|
|
|
* |
|
22
|
|
|
* @author Frans Saris <[email protected]> |
|
23
|
|
|
* @author Timo Hund <[email protected]> |
|
24
|
|
|
* @package ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionsFacet |
|
25
|
|
|
*/ |
|
26
|
|
|
abstract class AbstractFacetItemCollection extends AbstractCollection |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @param AbstractFacetItem $item |
|
30
|
|
|
* @return AbstractFacetItemCollection |
|
31
|
|
|
*/ |
|
32
|
55 |
|
public function add($item) |
|
33
|
|
|
{ |
|
34
|
55 |
|
if ($item === null) { |
|
35
|
|
|
return $this; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
55 |
|
$this->data[$item->getCollectionKey()] = $item; |
|
39
|
55 |
|
return $this; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param string $value |
|
44
|
|
|
* @return AbstractFacetItem |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getByValue($value) |
|
47
|
|
|
{ |
|
48
|
|
|
return isset($this->data[$value]) ? $this->data[$value] : null; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Retrieves the count (with get prefixed to be usable in fluid). |
|
53
|
|
|
* |
|
54
|
|
|
* @return int |
|
55
|
|
|
*/ |
|
56
|
3 |
|
public function getCount() |
|
57
|
|
|
{ |
|
58
|
3 |
|
return $this->count(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return AbstractFacetItemCollection |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getSelected() |
|
65
|
|
|
{ |
|
66
|
2 |
|
return $this->getFilteredCopy(function(AbstractFacetItem $item) { |
|
67
|
2 |
|
return $item->getSelected(); |
|
68
|
2 |
|
}); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param array $manualSorting |
|
73
|
|
|
* @return AbstractFacetItemCollection |
|
74
|
|
|
*/ |
|
75
|
5 |
|
public function getManualSortedCopy(array $manualSorting) |
|
76
|
|
|
{ |
|
77
|
5 |
|
$result = clone $this; |
|
78
|
5 |
|
$copiedItems = $result->data; |
|
79
|
5 |
|
$sortedOptions = []; |
|
80
|
5 |
|
foreach ($manualSorting as $item) { |
|
81
|
5 |
|
if (isset($copiedItems[$item])) { |
|
82
|
5 |
|
$sortedOptions[] = $copiedItems[$item]; |
|
83
|
5 |
|
unset($copiedItems[$item]); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
// in the end all items get appended that are not configured in the manual sort order |
|
87
|
5 |
|
$sortedOptions = $sortedOptions + $copiedItems; |
|
88
|
5 |
|
$result->data = $sortedOptions; |
|
89
|
|
|
|
|
90
|
5 |
|
return $result; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return AbstractFacetItemCollection |
|
95
|
|
|
*/ |
|
96
|
2 |
|
public function getReversedOrderCopy() |
|
97
|
|
|
{ |
|
98
|
2 |
|
$result = clone $this; |
|
99
|
2 |
|
$result->data = array_reverse($result->data, true); |
|
100
|
|
|
|
|
101
|
2 |
|
return $result; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|