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