Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
Reserves | |
0.00% |
0 / 28 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
useIndex | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
findReserves | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | /** |
4 | * VuFind Action Helper - Reserves Support Methods |
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 Controller_Plugins |
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 Main Page |
28 | */ |
29 | |
30 | namespace VuFind\Controller\Plugin; |
31 | |
32 | use Laminas\Mvc\Controller\Plugin\AbstractPlugin; |
33 | use VuFindSearch\Command\RetrieveCommand; |
34 | use VuFindSearch\Service; |
35 | |
36 | /** |
37 | * Action helper to perform reserves-related actions |
38 | * |
39 | * @category VuFind |
40 | * @package Controller_Plugins |
41 | * @author Demian Katz <demian.katz@villanova.edu> |
42 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
43 | * @link https://vufind.org Main Page |
44 | */ |
45 | class Reserves extends AbstractPlugin |
46 | { |
47 | /** |
48 | * Do we need to use the Solr index for reserves (true) or the ILS driver |
49 | * (false)? |
50 | * |
51 | * @var bool |
52 | */ |
53 | protected $useIndex; |
54 | |
55 | /** |
56 | * Search service |
57 | * |
58 | * @var Service |
59 | */ |
60 | protected $searchService; |
61 | |
62 | /** |
63 | * Constructor |
64 | * |
65 | * @param bool $useIndex Do we need to use the Solr index for reserves |
66 | * (true) or the ILS driver (false)? |
67 | * @param Service $searchService Search service (only required when $useIndex |
68 | * is true). |
69 | */ |
70 | public function __construct($useIndex = false, Service $searchService = null) |
71 | { |
72 | $this->useIndex = $useIndex; |
73 | if ($useIndex && null === $searchService) { |
74 | throw new \Exception('Missing required search service'); |
75 | } |
76 | $this->searchService = $searchService; |
77 | } |
78 | |
79 | /** |
80 | * Do we need to use the Solr index for reserves (true) or the ILS driver |
81 | * (false)? |
82 | * |
83 | * @return bool |
84 | */ |
85 | public function useIndex() |
86 | { |
87 | return $this->useIndex; |
88 | } |
89 | |
90 | /** |
91 | * Get reserve info from the catalog or Solr reserves index. |
92 | * |
93 | * @param string $course Course ID to use as limit (optional) |
94 | * @param string $inst Instructor ID to use as limit (optional) |
95 | * @param string $dept Department ID to use as limit (optional) |
96 | * |
97 | * @return array |
98 | */ |
99 | public function findReserves($course = null, $inst = null, $dept = null) |
100 | { |
101 | // Special case -- process reserves info using index |
102 | if ($this->useIndex()) { |
103 | // get the selected reserve record from reserves index |
104 | // and extract the bib IDs from it |
105 | $command = new RetrieveCommand( |
106 | 'SolrReserves', |
107 | $course . '|' . $inst . '|' . $dept |
108 | ); |
109 | $result = $this->searchService |
110 | ->invoke($command)->getResult(); |
111 | $bibs = []; |
112 | if ($result->getTotal() < 1) { |
113 | return $bibs; |
114 | } |
115 | $record = current($result->getRecords()); |
116 | $instructor = $record->getInstructor(); |
117 | $course = $record->getCourse(); |
118 | foreach ($record->getItemIds() as $bib_id) { |
119 | $bibs[] = [ |
120 | 'BIB_ID' => $bib_id, |
121 | 'bib_id' => $bib_id, |
122 | 'course' => $course, |
123 | 'instructor' => $instructor, |
124 | ]; |
125 | } |
126 | return $bibs; |
127 | } |
128 | |
129 | // Default case -- find reserves info from the catalog |
130 | $catalog = $this->getController()->getILS(); |
131 | return $catalog->findReserves($course, $inst, $dept); |
132 | } |
133 | } |