Passed
Push — master ( 03080d...b269f8 )
by Timo
05:08
created

AbstractFacet::injectObjectManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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\SearchResultSet;
17
18
/**
19
 * Value object that represent a options facet.
20
 *
21
 * @author Frans Saris <[email protected]>
22
 * @author Timo Hund <[email protected]>
23
 * @package ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionsFacet
24
 */
25
abstract class AbstractFacet
26
{
27
    const TYPE_ABSTRACT = 'abstract';
28
29
    /**
30
     * String
31
     * @var string
32
     */
33
    protected static $type = self::TYPE_ABSTRACT;
34
35
    /**
36
     * The resultSet where this facet belongs to.
37
     *
38
     * @var SearchResultSet
39
     */
40
    protected $resultSet = null;
41
42
    /**
43
     * @var string
44
     */
45
    protected $name;
46
47
    /**
48
     * @var string
49
     */
50
    protected $field;
51
52
    /**
53
     * @var string
54
     */
55
    protected $label;
56
57
    /**
58
     * @var array
59
     */
60
    protected $configuration;
61
62
    /**
63
     * @var boolean
64
     */
65
    protected $isAvailable = false;
66
67
    /**
68
     * @var bool
69
     */
70
    protected $isUsed = false;
71
72
    /**
73
     * @var bool
74
     */
75
    protected $allRequirementsMet = true;
76
77
    /**
78
     * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
79
     */
80
    protected $objectManager;
81
82
    /**
83
     * AbstractFacet constructor.
84
     *
85
     * @param SearchResultSet $resultSet
86 111
     * @param string $name
87
     * @param string $field
88 111
     * @param string $label
89 111
     * @param array $configuration Facet configuration passed from typoscript
90 111
     */
91 111
    public function __construct(SearchResultSet $resultSet, $name, $field, $label = '', array $configuration = [])
92 111
    {
93 111
        $this->resultSet = $resultSet;
94
        $this->name = $name;
95
        $this->field = $field;
96
        $this->label = $label;
97
        $this->configuration = $configuration;
98
    }
99
100 76
    /**
101
     * Injects the object manager
102 76
     *
103
     * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
104
     */
105
    public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
106
    {
107
        $this->objectManager = $objectManager;
108
    }
109
110
    /**
111
     * Get name
112
     *
113
     * @return string
114
     */
115
    public function getName()
116
    {
117
        return $this->name;
118
    }
119
120
    /**
121
     * Get solr field name
122
     *
123
     * @return string
124
     */
125
    public function getField()
126 35
    {
127
        return $this->field;
128 35
    }
129
130
    /**
131
     * @param string $label
132
     */
133
    public function setLabel($label)
134 73
    {
135
        $this->label = $label;
136 73
    }
137 73
138
    /**
139
     * @return string
140
     */
141
    public function getLabel()
142 34
    {
143
        return $this->label;
144 34
    }
145
146
    /**
147
     * @param boolean $isAvailable
148
     */
149
    public function setIsAvailable($isAvailable)
150 79
    {
151
        $this->isAvailable = $isAvailable;
152 79
    }
153 79
154
    /**
155
     * @return boolean
156
     */
157
    public function getIsAvailable()
158 46
    {
159
        return $this->isAvailable;
160 46
    }
161
162
    /**
163
     * @param boolean $isUsed
164
     */
165
    public function setIsUsed($isUsed)
166 31
    {
167
        $this->isUsed = $isUsed;
168 31
    }
169
170
    /**
171
     * @return boolean
172
     */
173
    public function getIsUsed()
174 34
    {
175
        return $this->isUsed;
176 34
    }
177
178
    /**
179
     * @return string
180
     */
181
    public function getType()
182 58
    {
183
        return static::$type;
184 58
    }
185 58
186
    /**
187
     * @return boolean
188
     */
189
    public function getAllRequirementsMet()
190 44
    {
191
        return $this->allRequirementsMet;
192 44
    }
193
194
    /**
195
     * @param boolean $allRequirementsMet
196
     */
197
    public function setAllRequirementsMet($allRequirementsMet)
198
    {
199
        $this->allRequirementsMet = $allRequirementsMet;
200 2
    }
201
202 2
    /**
203
     * @return SearchResultSet
204
     */
205
    public function getResultSet()
206
    {
207
        return $this->resultSet;
208
    }
209
210
    /**
211
     * Get configuration
212
     *
213
     * @return mixed
214
     */
215
    public function getConfiguration()
216
    {
217
        return $this->configuration;
218 34
    }
219
220 34
    /**
221
     * Get facet partial name used for rendering the facet
222
     *
223
     * @return string
224
     */
225
    public function getPartialName()
226
    {
227
        return 'Default';
228
    }
229 38
230
    /**
231 38
     * @return string
232
     */
233
    public function getGroupName()
234
    {
235
        return isset($this->configuration['groupName']) ? $this->configuration['groupName'] : 'main';
236
    }
237
238
    /**
239
     * Indicates if this facet should ne included in the available facets. When nothing is configured,
240 6
     * the method return TRUE.
241
     *
242
     * @return boolean
243 6
     */
244
    public function getIncludeInAvailableFacets()
245
    {
246
        return ((int)$this->getFacetSettingOrDefaultValue('includeInAvailableFacets', 1)) === 1;
247
    }
248
249
    /**
250
     * Indicates if this facets should be included in the used facets. When nothing is configured,
251 66
     * the methods returns true.
252
     *
253 66
     * @return boolean
254
     */
255
    public function getIncludeInUsedFacets()
256
    {
257
258
        return ((int)$this->getFacetSettingOrDefaultValue('includeInUsedFacets', 1)) === 1;
259
    }
260
261
    /**
262
     * Returns the configured requirements
263
     *
264
     * @return array
265
     */
266
    public function getRequirements()
267
    {
268 71
        return $this->getFacetSettingOrDefaultValue('requirements.', []);
269
    }
270 71
271 59
    /**
272
     * The implementation of this method should return a "flatten" collection of all items.
273
     *
274 17
     * @return AbstractFacetItemCollection
275
     */
276
    abstract public function getAllFacetItems();
277
278
    /**
279
     * @param string $key
280
     * @param mixed $defaultValue
281
     * @return mixed
282
     */
283
    protected function getFacetSettingOrDefaultValue($key, $defaultValue)
284
    {
285
        if (!isset($this->configuration[$key])) {
286
            return $defaultValue;
287
        }
288
289
        return ($this->configuration[$key]);
290
    }
291
}
292