Passed
Push — master ( 5adbd6...5901ba )
by Timo
20:55
created

AbstractFacet::setLabel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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 []
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
     * AbstractFacet constructor.
79
     *
80
     * @param SearchResultSet $resultSet
81
     * @param string $name
82
     * @param string $field
83
     * @param string $label
84
     * @param array $configuration Facet configuration passed from typoscript
85
     */
86 92
    public function __construct(SearchResultSet $resultSet, $name, $field, $label = '', array $configuration = [])
87
    {
88 92
        $this->resultSet = $resultSet;
89 92
        $this->name = $name;
90 92
        $this->field = $field;
91 92
        $this->label = $label;
92 92
        $this->configuration = $configuration;
93 92
    }
94
95
    /**
96
     * Get name
97
     *
98
     * @return string
99
     */
100 64
    public function getName()
101
    {
102 64
        return $this->name;
103
    }
104
105
    /**
106
     * Get solr field name
107
     *
108
     * @return string
109
     */
110
    public function getField()
111
    {
112
        return $this->field;
113
    }
114
115
    /**
116
     * @param string $label
117
     */
118
    public function setLabel($label)
119
    {
120
        $this->label = $label;
121
    }
122
123
    /**
124
     * @return string
125
     */
126 28
    public function getLabel()
127
    {
128 28
        return $this->label;
129
    }
130
131
    /**
132
     * @param boolean $isAvailable
133
     */
134 61
    public function setIsAvailable($isAvailable)
135
    {
136 61
        $this->isAvailable = $isAvailable;
137 61
    }
138
139
    /**
140
     * @return boolean
141
     */
142 27
    public function getIsAvailable()
143
    {
144 27
        return $this->isAvailable;
145
    }
146
147
    /**
148
     * @param boolean $isUsed
149
     */
150 64
    public function setIsUsed($isUsed)
151
    {
152 64
        $this->isUsed = $isUsed;
153 64
    }
154
155
    /**
156
     * @return boolean
157
     */
158 39
    public function getIsUsed()
159
    {
160 39
        return $this->isUsed;
161
    }
162
163
    /**
164
     * @return string
165
     */
166 24
    public function getType()
167
    {
168 24
        return static::$type;
169
    }
170
171
    /**
172
     * @return boolean
173
     */
174 27
    public function getAllRequirementsMet()
175
    {
176 27
        return $this->allRequirementsMet;
177
    }
178
179
    /**
180
     * @param boolean $allRequirementsMet
181
     */
182 49
    public function setAllRequirementsMet($allRequirementsMet)
183
    {
184 49
        $this->allRequirementsMet = $allRequirementsMet;
185 49
    }
186
187
    /**
188
     * @return SearchResultSet
189
     */
190 34
    public function getResultSet()
191
    {
192 34
        return $this->resultSet;
193
    }
194
195
    /**
196
     * Get configuration
197
     *
198
     * @return mixed
199
     */
200 2
    public function getConfiguration()
201
    {
202 2
        return $this->configuration;
203
    }
204
205
    /**
206
     * Get facet partial name used for rendering the facet
207
     *
208
     * @return string
209
     */
210
    public function getPartialName()
211
    {
212
        return 'Default';
213
    }
214
215
    /**
216
     * @return string
217
     */
218 27
    public function getGroupName()
219
    {
220 27
        return isset($this->configuration['groupName']) ? $this->configuration['groupName'] : 'main';
221
    }
222
223
    /**
224
     * Indicates if this facet should ne included in the available facets. When nothing is configured,
225
     * the method return TRUE.
226
     *
227
     * @return boolean
228
     */
229 31
    public function getIncludeInAvailableFacets()
230
    {
231 31
        return ((int)$this->getFacetSettingOrDefaultValue('includeInAvailableFacets', 1)) === 1;
232
    }
233
234
    /**
235
     * Indicates if this facets should be included in the used facets. When nothing is configured,
236
     * the methods returns true.
237
     *
238
     * @return boolean
239
     */
240 4
    public function getIncludeInUsedFacets()
241
    {
242
243 4
        return ((int) $this->getFacetSettingOrDefaultValue('includeInUsedFacets', 1)) === 1;
244
    }
245
246
    /**
247
     * Returns the configured requirements
248
     *
249
     * @return array
250
     */
251 54
    public function getRequirements()
252
    {
253 54
        return $this->getFacetSettingOrDefaultValue('requirements.', []);
254
    }
255
256
    /**
257
     * The implementation of this method should return a "flatten" collection of all items.
258
     *
259
     * @return AbstractFacetItemCollection
260
     */
261
    abstract public function getAllFacetItems();
262
263
    /**
264
     * @param string $key
265
     * @param mixed $defaultValue
266
     * @return mixed
267
     */
268 59
    protected function getFacetSettingOrDefaultValue($key, $defaultValue)
269
    {
270 59
        if (!isset($this->configuration[$key])) {
271 50
            return $defaultValue;
272
        }
273
274 14
        return ($this->configuration[$key]);
275
    }
276
}
277