|
1
|
|
|
<?php |
|
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\Hierarchy; |
|
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 options 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 HierarchyFacet extends AbstractFacet |
|
29
|
|
|
{ |
|
30
|
|
|
const TYPE_HIERARCHY = 'hierarchy'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* String |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
protected static $type = self::TYPE_HIERARCHY; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var NodeCollection |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $childNodes; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var NodeCollection |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $allNodes; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var array |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $nodesByKey = []; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* OptionsFacet constructor |
|
55
|
|
|
* |
|
56
|
|
|
* @param SearchResultSet $resultSet |
|
57
|
|
|
* @param string $name |
|
58
|
|
|
* @param string $field |
|
59
|
|
|
* @param string $label |
|
60
|
|
|
* @param array $configuration Facet configuration passed from typoscript |
|
61
|
|
|
*/ |
|
62
|
22 |
|
public function __construct(SearchResultSet $resultSet, $name, $field, $label = '', array $configuration = []) |
|
63
|
|
|
{ |
|
64
|
22 |
|
parent::__construct($resultSet, $name, $field, $label, $configuration); |
|
65
|
22 |
|
$this->childNodes = new NodeCollection(); |
|
66
|
22 |
|
$this->allNodes = new NodeCollection(); |
|
67
|
22 |
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param Node $node |
|
71
|
|
|
*/ |
|
72
|
22 |
|
public function addChildNode(Node $node) |
|
73
|
|
|
{ |
|
74
|
22 |
|
$this->childNodes->add($node); |
|
75
|
22 |
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @return NodeCollection |
|
79
|
|
|
*/ |
|
80
|
20 |
|
public function getChildNodes() |
|
81
|
|
|
{ |
|
82
|
20 |
|
return $this->childNodes; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Creates a new node on the right position with the right parent node. |
|
87
|
|
|
* |
|
88
|
|
|
* @param string $parentKey |
|
89
|
|
|
* @param string $key |
|
90
|
|
|
* @param string $label |
|
91
|
|
|
* @param string $value |
|
92
|
|
|
* @param integer $count |
|
93
|
|
|
* @param boolean $selected |
|
94
|
|
|
*/ |
|
95
|
22 |
|
public function createNode($parentKey, $key, $label, $value, $count, $selected) |
|
96
|
|
|
{ |
|
97
|
|
|
/** @var $parentNode Node|null */ |
|
98
|
22 |
|
$parentNode = isset($this->nodesByKey[$parentKey]) ? $this->nodesByKey[$parentKey] : null; |
|
99
|
22 |
|
$node = new Node($this, $parentNode, $key, $label, $value, $count, $selected); |
|
100
|
22 |
|
$this->nodesByKey[$key] = $node; |
|
101
|
|
|
|
|
102
|
22 |
|
if ($parentNode === null) { |
|
103
|
22 |
|
$this->addChildNode($node); |
|
104
|
|
|
} else { |
|
105
|
22 |
|
$parentNode->addChildNode($node); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
22 |
|
$this->allNodes->add($node); |
|
109
|
22 |
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Get facet partial name used for rendering the facet |
|
113
|
|
|
* |
|
114
|
|
|
* @return string |
|
115
|
|
|
*/ |
|
116
|
18 |
|
public function getPartialName() |
|
117
|
|
|
{ |
|
118
|
18 |
|
return !empty($this->configuration['partialName']) ? $this->configuration['partialName'] : 'Hierarchy'; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* The implementation of this method should return a "flatten" collection of all items. |
|
123
|
|
|
* |
|
124
|
|
|
* @return AbstractFacetItemCollection |
|
125
|
|
|
*/ |
|
126
|
|
|
public function getAllFacetItems() |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->allNodes; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|