Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
RecommendLinks | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setConfig | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
init | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
process | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getLinks | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * RecommendLinks Recommendations Module |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2019. |
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 Recommendations |
25 | * @author Vaclav Rosecky <xrosecky@gmail.com> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org/wiki/development:plugins:recommendation_modules Wiki |
28 | */ |
29 | |
30 | namespace VuFind\Recommend; |
31 | |
32 | /** |
33 | * RecommendLinks Recommendations Module |
34 | * |
35 | * This class recommends links to services, that user may try. |
36 | * |
37 | * @category VuFind |
38 | * @package Recommendations |
39 | * @author Vaclav Rosecky <xrosecky@gmail.com> |
40 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
41 | * @link https://vufind.org/wiki/development:plugins:recommendation_modules Wiki |
42 | */ |
43 | class RecommendLinks implements RecommendInterface |
44 | { |
45 | /** |
46 | * Links to show |
47 | * |
48 | * @var array |
49 | */ |
50 | protected $links = []; |
51 | |
52 | /** |
53 | * Configuration loader |
54 | * |
55 | * @var \VuFind\Config\PluginManager |
56 | */ |
57 | protected $configLoader; |
58 | |
59 | /** |
60 | * Constructor |
61 | * |
62 | * @param \VuFind\Config\PluginManager $configLoader Configuration loader |
63 | */ |
64 | public function __construct(\VuFind\Config\PluginManager $configLoader) |
65 | { |
66 | $this->configLoader = $configLoader; |
67 | } |
68 | |
69 | /** |
70 | * Store the configuration of the recommendation module. |
71 | * |
72 | * RecommendLinks:[ini section]:[ini name] |
73 | * Display a list of recommended links, taken from [ini section] in |
74 | * [ini name], where the section is a mapping of label => URL. [ini name] |
75 | * defaults to searches.ini, and [ini section] defaults to RecommendLinks. |
76 | * |
77 | * @param string $settings Settings from searches.ini. |
78 | * |
79 | * @return void |
80 | */ |
81 | public function setConfig($settings) |
82 | { |
83 | $settings = explode(':', $settings); |
84 | $mainSection = empty($settings[0]) ? 'RecommendLinks' : $settings[0]; |
85 | $iniName = $settings[1] ?? 'searches'; |
86 | $config = $this->configLoader->get($iniName); |
87 | $this->links = isset($config->$mainSection) |
88 | ? $config->$mainSection->toArray() : []; |
89 | } |
90 | |
91 | /** |
92 | * Called before the Search Results object performs its main search |
93 | * (specifically, in response to \VuFind\Search\SearchRunner::EVENT_CONFIGURED). |
94 | * This method is responsible for setting search parameters needed by the |
95 | * recommendation module and for reading any existing search parameters that may |
96 | * be needed. |
97 | * |
98 | * @param \VuFind\Search\Base\Params $params Search parameter object |
99 | * @param \Laminas\Stdlib\Parameters $request Parameter object representing user |
100 | * request. |
101 | * |
102 | * @return void |
103 | */ |
104 | public function init($params, $request) |
105 | { |
106 | // No action needed. |
107 | } |
108 | |
109 | /** |
110 | * Called after the Search Results object has performed its main search. This |
111 | * may be used to extract necessary information from the Search Results object |
112 | * or to perform completely unrelated processing. |
113 | * |
114 | * @param \VuFind\Search\Base\Results $results Search results object |
115 | * |
116 | * @return void |
117 | */ |
118 | public function process($results) |
119 | { |
120 | // No action needed. |
121 | } |
122 | |
123 | /** |
124 | * Get array of links with title as key and value as link |
125 | * |
126 | * @return \VuFind\Search\Base\Results |
127 | */ |
128 | public function getLinks() |
129 | { |
130 | return $this->links; |
131 | } |
132 | } |