Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
CollectionList | |
0.00% |
0 / 27 |
|
0.00% |
0 / 5 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getParams | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getResults | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
6 | |||
supportsAjax | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Collection list tab |
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 RecordTabs |
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:record_tabs Wiki |
28 | */ |
29 | |
30 | namespace VuFind\RecordTab; |
31 | |
32 | use VuFind\Recommend\PluginManager as RecommendManager; |
33 | use VuFind\Search\Memory as SearchMemory; |
34 | use VuFind\Search\RecommendListener; |
35 | use VuFind\Search\SearchRunner; |
36 | |
37 | /** |
38 | * Collection list tab |
39 | * |
40 | * @category VuFind |
41 | * @package RecordTabs |
42 | * @author Demian Katz <demian.katz@villanova.edu> |
43 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
44 | * @link https://vufind.org/wiki/development:plugins:record_tabs Wiki |
45 | */ |
46 | class CollectionList extends AbstractBase |
47 | { |
48 | /** |
49 | * Search results object (null prior to processing) |
50 | * |
51 | * @var \VuFind\Search\SolrCollection\Results |
52 | */ |
53 | protected $results = null; |
54 | |
55 | /** |
56 | * Search runner |
57 | * |
58 | * @var SearchRunner |
59 | */ |
60 | protected $runner; |
61 | |
62 | /** |
63 | * Recommendation manager |
64 | * |
65 | * @var RecommendManager |
66 | */ |
67 | protected $recommendManager; |
68 | |
69 | /** |
70 | * Search memory |
71 | * |
72 | * @var SearchMemory |
73 | */ |
74 | protected $searchMemory; |
75 | |
76 | /** |
77 | * Search class id |
78 | * |
79 | * @var string |
80 | */ |
81 | protected $searchClassId = 'SolrCollection'; |
82 | |
83 | /** |
84 | * Constructor |
85 | * |
86 | * @param SearchRunner $runner Search runner |
87 | * @param RecommendManager $recMan Recommendation manager |
88 | * @param SearchMemory $sm Search memory |
89 | */ |
90 | public function __construct( |
91 | SearchRunner $runner, |
92 | RecommendManager $recMan, |
93 | SearchMemory $sm |
94 | ) { |
95 | $this->runner = $runner; |
96 | $this->recommendManager = $recMan; |
97 | $this->searchMemory = $sm; |
98 | } |
99 | |
100 | /** |
101 | * Get the on-screen description for this tab. |
102 | * |
103 | * @return string |
104 | */ |
105 | public function getDescription() |
106 | { |
107 | return 'Collection Items'; |
108 | } |
109 | |
110 | /** |
111 | * Get the current search parameters. |
112 | * |
113 | * @return \VuFind\Search\SolrCollection\Params |
114 | */ |
115 | public function getParams() |
116 | { |
117 | return $this->getResults()->getParams(); |
118 | } |
119 | |
120 | /** |
121 | * Get the processed search results. |
122 | * |
123 | * @return \VuFind\Search\SolrCollection\Results |
124 | */ |
125 | public function getResults() |
126 | { |
127 | if (null === $this->results) { |
128 | $driver = $this->getRecordDriver(); |
129 | $request = $this->getRequest()->getQuery()->toArray() |
130 | + $this->getRequest()->getPost()->toArray(); |
131 | $rManager = $this->recommendManager; |
132 | $cb = function ($runner, $params, $searchId) use ($driver, $rManager, $request) { |
133 | $params->initFromRecordDriver($driver, '' !== ($request['lookfor'] ?? '')); |
134 | $listener = new RecommendListener($rManager, $searchId); |
135 | $listener->setConfig( |
136 | $params->getOptions()->getRecommendationSettings() |
137 | ); |
138 | $listener->attach($runner->getEventManager()->getSharedManager()); |
139 | }; |
140 | $this->results |
141 | = $this->runner->run($request, $this->searchClassId, $cb); |
142 | // Add search id from the originating search for paginator: |
143 | $this->results->getUrlQuery()->setDefaultParameter( |
144 | 'sid', |
145 | $this->searchMemory->getCurrentSearchId(), |
146 | true |
147 | ); |
148 | } |
149 | return $this->results; |
150 | } |
151 | |
152 | /** |
153 | * Can this tab be loaded via AJAX? |
154 | * |
155 | * @return bool |
156 | */ |
157 | public function supportsAjax() |
158 | { |
159 | // No, search parameters from the URL are needed. |
160 | return false; |
161 | } |
162 | } |