Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
55.56% |
5 / 9 |
|
60.00% |
3 / 5 |
CRAP | |
0.00% |
0 / 1 |
AbstractSummonRecommend | |
55.56% |
5 / 9 |
|
60.00% |
3 / 5 |
11.30 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setConfig | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
init | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
process | |
40.00% |
2 / 5 |
|
0.00% |
0 / 1 |
2.86 | |||
configureSummonResults | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getResults | n/a |
0 / 0 |
n/a |
0 / 0 |
0 |
1 | <?php |
2 | |
3 | /** |
4 | * Abstract base class for pulling Summon-specific recommendations. |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2010. |
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 Demian Katz <demian.katz@villanova.edu> |
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 | * Abstract base class for pulling Summon-specific recommendations. |
34 | * |
35 | * @category VuFind |
36 | * @package Recommendations |
37 | * @author Demian Katz <demian.katz@villanova.edu> |
38 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
39 | * @link https://vufind.org/wiki/development:plugins:recommendation_modules Wiki |
40 | */ |
41 | abstract class AbstractSummonRecommend implements RecommendInterface |
42 | { |
43 | /** |
44 | * Database details |
45 | * |
46 | * @var \VuFind\Search\Summon\Results |
47 | */ |
48 | protected $results; |
49 | |
50 | /** |
51 | * Request parameter to pull query from |
52 | * |
53 | * @var string |
54 | */ |
55 | protected $requestParam = 'lookfor'; |
56 | |
57 | /** |
58 | * User query |
59 | * |
60 | * @var string |
61 | */ |
62 | protected $lookfor; |
63 | |
64 | /** |
65 | * Results plugin manager |
66 | * |
67 | * @var \VuFind\Search\Results\PluginManager |
68 | */ |
69 | protected $resultsManager; |
70 | |
71 | /** |
72 | * Constructor |
73 | * |
74 | * @param \VuFind\Search\Results\PluginManager $results Results plugin manager |
75 | */ |
76 | public function __construct(\VuFind\Search\Results\PluginManager $results) |
77 | { |
78 | $this->resultsManager = $results; |
79 | } |
80 | |
81 | /** |
82 | * Store the configuration of the recommendation module. |
83 | * |
84 | * @param string $settings Settings from searches.ini. |
85 | * |
86 | * @return void |
87 | */ |
88 | public function setConfig($settings) |
89 | { |
90 | // Only one setting -- HTTP request field containing search terms (ignored |
91 | // if $searchObject is Summon type). |
92 | $this->requestParam = empty($settings) ? $this->requestParam : $settings; |
93 | } |
94 | |
95 | /** |
96 | * Called before the Search Results object performs its main search |
97 | * (specifically, in response to \VuFind\Search\SearchRunner::EVENT_CONFIGURED). |
98 | * This method is responsible for setting search parameters needed by the |
99 | * recommendation module and for reading any existing search parameters that may |
100 | * be needed. |
101 | * |
102 | * @param \VuFind\Search\Base\Params $params Search parameter object |
103 | * @param \Laminas\Stdlib\Parameters $request Parameter object representing user |
104 | * request. |
105 | * |
106 | * @return void |
107 | */ |
108 | public function init($params, $request) |
109 | { |
110 | // Save search query in case we need it later: |
111 | $this->lookfor = $request->get($this->requestParam); |
112 | } |
113 | |
114 | /** |
115 | * Called after the Search Results object has performed its main search. This |
116 | * may be used to extract necessary information from the Search Results object |
117 | * or to perform completely unrelated processing. |
118 | * |
119 | * @param \VuFind\Search\Base\Results $results Search results object |
120 | * |
121 | * @return void |
122 | */ |
123 | public function process($results) |
124 | { |
125 | // If we received a Summon search object, we'll use that. If not, we need |
126 | // to create a new Summon search object using the specified request |
127 | // parameter for search terms. |
128 | if ($results->getParams()->getSearchClassId() != 'Summon') { |
129 | $results = $this->resultsManager->get('Summon'); |
130 | $this->configureSummonResults($results); |
131 | $results->performAndProcessSearch(); |
132 | } |
133 | $this->results = $results; |
134 | } |
135 | |
136 | /** |
137 | * If we have to create a new Summon results object, this method is used to |
138 | * configure it with appropriate settings. |
139 | * |
140 | * @param \VuFind\Search\Summon\Results $results Search results object |
141 | * |
142 | * @return void |
143 | */ |
144 | protected function configureSummonResults(\VuFind\Search\Summon\Results $results) |
145 | { |
146 | $results->getParams()->setBasicSearch($this->lookfor, 'AllFields'); |
147 | } |
148 | |
149 | /** |
150 | * Get specific results needed by template. |
151 | * |
152 | * @return array |
153 | */ |
154 | abstract public function getResults(); |
155 | } |