Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
75.00% |
6 / 8 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
ViewOptionsTrait | |
75.00% |
6 / 8 |
|
0.00% |
0 / 1 |
5.39 | |
0.00% |
0 / 1 |
initViewOptions | |
75.00% |
6 / 8 |
|
0.00% |
0 / 1 |
5.39 |
1 | <?php |
2 | |
3 | /** |
4 | * Trait for setting up view options. Designed to be included in a subclass of |
5 | * \VuFind\Search\Base\Options. |
6 | * |
7 | * PHP version 8 |
8 | * |
9 | * Copyright (C) Villanova University 2017. |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License version 2, |
13 | * as published by the Free Software Foundation. |
14 | * |
15 | * This program is distributed in the hope that it will be useful, |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | * GNU General Public License for more details. |
19 | * |
20 | * You should have received a copy of the GNU General Public License |
21 | * along with this program; if not, write to the Free Software |
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23 | * |
24 | * @category VuFind |
25 | * @package Search |
26 | * @author Demian Katz <demian.katz@villanova.edu> |
27 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
28 | * @link https://vufind.org Main Page |
29 | */ |
30 | |
31 | namespace VuFind\Search\Options; |
32 | |
33 | use Laminas\Config\Config; |
34 | |
35 | /** |
36 | * Trait for setting up view options. Designed to be included in a subclass of |
37 | * \VuFind\Search\Base\Options. |
38 | * |
39 | * @category VuFind |
40 | * @package Search |
41 | * @author Demian Katz <demian.katz@villanova.edu> |
42 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
43 | * @link https://vufind.org Main Page |
44 | */ |
45 | trait ViewOptionsTrait |
46 | { |
47 | /** |
48 | * Set up the view options. |
49 | * |
50 | * @param ?Config $searchSettings Search settings. |
51 | * |
52 | * @return void |
53 | */ |
54 | public function initViewOptions(?Config $searchSettings) |
55 | { |
56 | if (isset($searchSettings->General->default_view)) { |
57 | $this->defaultView = $searchSettings->General->default_view; |
58 | } |
59 | // Load view preferences (or defaults if none in .ini file): |
60 | if (isset($searchSettings->Views)) { |
61 | foreach ($searchSettings->Views as $key => $value) { |
62 | $this->viewOptions[$key] = $value; |
63 | } |
64 | } elseif (isset($searchSettings->General->default_view)) { |
65 | $this->viewOptions = [$this->defaultView => $this->defaultView]; |
66 | } else { |
67 | $this->viewOptions = ['list' => 'List']; |
68 | } |
69 | } |
70 | } |