Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
ExternalSearch | |
100.00% |
9 / 9 |
|
100.00% |
5 / 5 |
6 | |
100.00% |
1 / 1 |
setConfig | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
init | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
process | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getLinkText | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getUrl | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * ExternalSearch Recommendation 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 Mark Triggs <vufind-tech@lists.sourceforge.net> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org Main Page |
28 | */ |
29 | |
30 | namespace VuFind\Recommend; |
31 | |
32 | /** |
33 | * ExternalSearch Recommendation Module |
34 | * |
35 | * @category VuFind |
36 | * @package Recommendations |
37 | * @author Chris Hallberg <challber@villanova.edu> |
38 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
39 | * @link https://vufind.org Main Page |
40 | */ |
41 | class ExternalSearch implements RecommendInterface |
42 | { |
43 | /** |
44 | * Link text |
45 | * |
46 | * @var string |
47 | */ |
48 | protected $linkText; |
49 | |
50 | /** |
51 | * URL template string |
52 | * |
53 | * @var string |
54 | */ |
55 | protected $template; |
56 | |
57 | /** |
58 | * Search query |
59 | * |
60 | * @var string |
61 | */ |
62 | protected $lookfor; |
63 | |
64 | /** |
65 | * Store the configuration of the recommendation module. |
66 | * |
67 | * @param string $settingsStr Settings from searches.ini. |
68 | * |
69 | * @return void |
70 | */ |
71 | public function setConfig($settingsStr) |
72 | { |
73 | // Parse the settings: |
74 | $settings = explode(':', $settingsStr, 2); |
75 | $this->linkText = $settings[0] ?? null; |
76 | $this->template = $settings[1] ?? null; |
77 | } |
78 | |
79 | /** |
80 | * Called before the Search Results object performs its main search |
81 | * (specifically, in response to \VuFind\Search\SearchRunner::EVENT_CONFIGURED). |
82 | * This method is responsible for setting search parameters needed by the |
83 | * recommendation module and for reading any existing search parameters that may |
84 | * be needed. |
85 | * |
86 | * @param \VuFind\Search\Base\Params $params Search parameter object |
87 | * @param \Laminas\Stdlib\Parameters $request Parameter object representing user |
88 | * request. |
89 | * |
90 | * @return void |
91 | */ |
92 | public function init($params, $request) |
93 | { |
94 | $this->lookfor = $request->get('lookfor'); |
95 | } |
96 | |
97 | /** |
98 | * Called after the Search Results object has performed its main search. This |
99 | * may be used to extract necessary information from the Search Results object |
100 | * or to perform completely unrelated processing. |
101 | * |
102 | * @param \VuFind\Search\Base\Results $results Search results object |
103 | * |
104 | * @return void |
105 | */ |
106 | public function process($results) |
107 | { |
108 | // no action needed |
109 | } |
110 | |
111 | /** |
112 | * Get the link text. |
113 | * |
114 | * @return string |
115 | */ |
116 | public function getLinkText() |
117 | { |
118 | return $this->linkText; |
119 | } |
120 | |
121 | /** |
122 | * Get the link URL. |
123 | * |
124 | * @return string |
125 | */ |
126 | public function getUrl() |
127 | { |
128 | return (!str_contains($this->template, '%%lookfor%%')) |
129 | ? $this->template . urlencode($this->lookfor) |
130 | : str_replace('%%lookfor%%', urlencode($this->lookfor), $this->template); |
131 | } |
132 | } |