Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
60.00% |
6 / 10 |
|
40.00% |
2 / 5 |
CRAP | |
0.00% |
0 / 1 |
FacetRestrictionsTrait | |
60.00% |
6 / 10 |
|
40.00% |
2 / 5 |
10.14 | |
0.00% |
0 / 1 |
initFacetRestrictionsFromConfig | |
50.00% |
2 / 4 |
|
0.00% |
0 / 1 |
4.12 | |||
setFacetPrefixByField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setFacetMatchesByField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getFacetPrefixForField | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getFacetMatchesForField | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * Trait to add facet prefix and matches settings to a Params object. |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2018. |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package Search |
25 | * @author Demian Katz <demian.katz@villanova.edu> |
26 | * @author Hajo Seng <hajo.seng@sub.uni-hamburg.de> |
27 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
28 | * @link https://vufind.org/wiki/development:plugins:record_drivers Wiki |
29 | */ |
30 | |
31 | namespace VuFind\Search\Params; |
32 | |
33 | use Laminas\Config\Config; |
34 | |
35 | /** |
36 | * Trait to add facet limiting settings to a Params object. |
37 | * |
38 | * @category VuFind |
39 | * @package Search |
40 | * @author Demian Katz <demian.katz@villanova.edu> |
41 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
42 | * @link https://vufind.org/wiki/development:plugins:record_drivers Wiki |
43 | */ |
44 | trait FacetRestrictionsTrait |
45 | { |
46 | /** |
47 | * Per-field facet prefix |
48 | * |
49 | * @var array |
50 | */ |
51 | protected $facetPrefixByField = []; |
52 | |
53 | /** |
54 | * Per-field facet matches |
55 | * |
56 | * @var array |
57 | */ |
58 | protected $facetMatchesByField = []; |
59 | |
60 | /** |
61 | * Initialize facet prefix and matches from a Config object. |
62 | * |
63 | * @param Config $config Configuration |
64 | * |
65 | * @return void |
66 | */ |
67 | protected function initFacetRestrictionsFromConfig(Config $config = null) |
68 | { |
69 | foreach ($config->facet_prefix_by_field ?? [] as $k => $v) { |
70 | $this->facetPrefixByField[$k] = $v; |
71 | } |
72 | foreach ($config->facet_matches_by_field ?? [] as $k => $v) { |
73 | $this->facetMatchesByField[$k] = $v; |
74 | } |
75 | } |
76 | |
77 | /** |
78 | * Set Facet Prefix by Field |
79 | * |
80 | * @param array $new Associative array of $field name => $limit |
81 | * |
82 | * @return void |
83 | */ |
84 | public function setFacetPrefixByField(array $new) |
85 | { |
86 | $this->facetPrefixByField = $new; |
87 | } |
88 | |
89 | /** |
90 | * Set Facet Matches by Field |
91 | * |
92 | * @param array $new Associative array of $field name => $limit |
93 | * |
94 | * @return void |
95 | */ |
96 | public function setFacetMatchesByField(array $new) |
97 | { |
98 | $this->facetMatchesByField = $new; |
99 | } |
100 | |
101 | /** |
102 | * Get the facet prefix for the specified field. |
103 | * |
104 | * @param string $field Field to look up |
105 | * |
106 | * @return string |
107 | */ |
108 | protected function getFacetPrefixForField($field) |
109 | { |
110 | $prefix = $this->facetPrefixByField[$field] ?? ''; |
111 | return $prefix; |
112 | } |
113 | |
114 | /** |
115 | * Get the facet matches for the specified field. |
116 | * |
117 | * @param string $field Field to look up |
118 | * |
119 | * @return string |
120 | */ |
121 | protected function getFacetMatchesForField($field) |
122 | { |
123 | $matches = $this->facetMatchesByField[$field] ?? ''; |
124 | return $matches; |
125 | } |
126 | } |