Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.86% covered (success)
92.86%
13 / 14
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Summon
92.86% covered (success)
92.86%
13 / 14
0.00% covered (danger)
0.00%
0 / 1
4.01
0.00% covered (danger)
0.00%
0 / 1
 fetchSingleRecord
92.86% covered (success)
92.86%
13 / 14
0.00% covered (danger)
0.00%
0 / 1
4.01
1<?php
2
3/**
4 * Summon record fallback loader
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2018, 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  Record
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 Site
28 */
29
30namespace VuFind\Record\FallbackLoader;
31
32use SerialsSolutions\Summon\Laminas as Connector;
33use VuFindSearch\Command\RetrieveCommand;
34use VuFindSearch\ParamBag;
35
36use function strlen;
37
38/**
39 * Summon record fallback loader
40 *
41 * @category VuFind
42 * @package  Record
43 * @author   Demian Katz <demian.katz@villanova.edu>
44 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
45 * @link     https://vufind.org Main Site
46 */
47class Summon extends AbstractFallbackLoader
48{
49    /**
50     * Record source
51     *
52     * @var string
53     */
54    protected $source = 'Summon';
55
56    /**
57     * Fetch a single record (null if not found).
58     *
59     * @param string $id ID to load
60     *
61     * @return \VuFindSearch\Response\RecordCollectionInterface
62     */
63    protected function fetchSingleRecord($id)
64    {
65        $resource = $this->resourceService->getResourceByRecordId($id, 'Summon');
66        if ($resource && ($extra = json_decode($resource->getExtraMetadata(), true))) {
67            $bookmark = $extra['bookmark'] ?? '';
68            if (strlen($bookmark) > 0) {
69                $params = new ParamBag(
70                    ['summonIdType' => Connector::IDENTIFIER_BOOKMARK]
71                );
72                $command = new RetrieveCommand(
73                    'Summon',
74                    $bookmark,
75                    $params
76                );
77                return $this->searchService->invoke($command)->getResult();
78            }
79        }
80        return new \VuFindSearch\Backend\Summon\Response\RecordCollection([]);
81    }
82}