Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
SimilarItemsCarousel | |
100.00% |
12 / 12 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getDescription | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getResults | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * Similar items carousel tab. |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2010, 2022. |
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 VuFindSearch\Command\SimilarCommand; |
33 | |
34 | /** |
35 | * Similar items carousel tab. |
36 | * |
37 | * @category VuFind |
38 | * @package RecordTabs |
39 | * @author Demian Katz <demian.katz@villanova.edu> |
40 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
41 | * @link https://vufind.org/wiki/development:plugins:record_tabs Wiki |
42 | */ |
43 | class SimilarItemsCarousel extends AbstractBase |
44 | { |
45 | /** |
46 | * Similar records |
47 | * |
48 | * @var array |
49 | */ |
50 | protected $results; |
51 | |
52 | /** |
53 | * Search service |
54 | * |
55 | * @var \VuFindSearch\Service |
56 | */ |
57 | protected $searchService; |
58 | |
59 | /** |
60 | * Configuration |
61 | * |
62 | * @var \Laminas\Config\Config |
63 | */ |
64 | protected $config; |
65 | |
66 | /** |
67 | * Constructor |
68 | * |
69 | * @param \VuFindSearch\Service $search Search service |
70 | * @param ?\Laminas\Config\Config $config Configuration |
71 | */ |
72 | public function __construct( |
73 | \VuFindSearch\Service $search, |
74 | ?\Laminas\Config\Config $config = null |
75 | ) { |
76 | $this->searchService = $search; |
77 | $this->config = $config; |
78 | } |
79 | |
80 | /** |
81 | * Get the on-screen description for this tab. |
82 | * |
83 | * @return string |
84 | */ |
85 | public function getDescription() |
86 | { |
87 | return 'Similar Items'; |
88 | } |
89 | |
90 | /** |
91 | * Get an array of Record Driver objects representing items similar to the one |
92 | * passed to the constructor. |
93 | * |
94 | * @return RecordCollectionInterface |
95 | */ |
96 | public function getResults() |
97 | { |
98 | $record = $this->getRecordDriver(); |
99 | $rows = $this->config->Record->similar_carousel_items ?? 40; |
100 | $params = new \VuFindSearch\ParamBag(['rows' => $rows]); |
101 | $command = new SimilarCommand( |
102 | $record->getSourceIdentifier(), |
103 | $record->getUniqueId(), |
104 | $params |
105 | ); |
106 | return $this->searchService->invoke($command)->getResult(); |
107 | } |
108 | } |