Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
SearchSettings | |
0.00% |
0 / 15 |
|
0.00% |
0 / 6 |
156 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
__invoke | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
bulkOptionsEnabled | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
cartControlsEnabled | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
20 | |||
checkboxesEnabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
getOptions | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | /** |
4 | * Search settings view helper |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) The National Library of Finland 2023. |
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 View_Helpers |
25 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org/wiki/development Wiki |
28 | */ |
29 | |
30 | namespace VuFind\View\Helper\Root; |
31 | |
32 | use VuFind\Search\Base\Options; |
33 | use VuFind\Search\Base\Params; |
34 | |
35 | /** |
36 | * Search settings view helper |
37 | * |
38 | * @category VuFind |
39 | * @package View_Helpers |
40 | * @author Ere Maijala <ere.maijala@helsinki.fi> |
41 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
42 | * @link https://vufind.org/wiki/development Wiki |
43 | */ |
44 | class SearchSettings extends \Laminas\View\Helper\AbstractHelper |
45 | { |
46 | /** |
47 | * VuFind configuration |
48 | * |
49 | * @var array |
50 | */ |
51 | protected $config; |
52 | |
53 | /** |
54 | * Search params |
55 | * |
56 | * @var Params |
57 | */ |
58 | protected $params = null; |
59 | |
60 | /** |
61 | * Constructor |
62 | * |
63 | * @param array $config VuFind configuration |
64 | */ |
65 | public function __construct(array $config) |
66 | { |
67 | $this->config = $config; |
68 | } |
69 | |
70 | /** |
71 | * Store params and return this object |
72 | * |
73 | * @param Params $params Search params |
74 | * |
75 | * @return SearchResults |
76 | */ |
77 | public function __invoke(Params $params) |
78 | { |
79 | $this->params = $params; |
80 | return $this; |
81 | } |
82 | |
83 | /** |
84 | * Check if bulk options are enabled |
85 | * |
86 | * @return bool |
87 | */ |
88 | public function bulkOptionsEnabled() |
89 | { |
90 | if (!($this->config['Site']['showBulkOptions'] ?? false)) { |
91 | return false; |
92 | } |
93 | return $this->getOptions()->supportsCart(); |
94 | } |
95 | |
96 | /** |
97 | * Check if cart controls are enabled |
98 | * |
99 | * @return bool |
100 | */ |
101 | public function cartControlsEnabled() |
102 | { |
103 | $cart = $this->view->plugin('cart'); |
104 | return |
105 | $this->getOptions()->supportsCart() |
106 | && $cart()->isActive() |
107 | && ($this->bulkOptionsEnabled() || !$cart()->isActiveInSearch()); |
108 | } |
109 | |
110 | /** |
111 | * Check if result selection checkboxes are enabled |
112 | * |
113 | * @return bool |
114 | */ |
115 | public function checkboxesEnabled() |
116 | { |
117 | return $this->bulkOptionsEnabled() || $this->cartControlsEnabled(); |
118 | } |
119 | |
120 | /** |
121 | * Get search options from params |
122 | * |
123 | * @return Options |
124 | */ |
125 | protected function getOptions(): Options |
126 | { |
127 | if (null === $this->params) { |
128 | throw new \Exception('Params not provided for SearchSettings helper'); |
129 | } |
130 | return $this->params->getOptions(); |
131 | } |
132 | } |