Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.00% covered (success)
90.00%
9 / 10
80.00% covered (warning)
80.00%
4 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
HoldingsWorldCat
90.00% covered (success)
90.00%
9 / 10
80.00% covered (warning)
80.00%
4 / 5
6.04
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDescription
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getHoldings
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
2.03
 isActive
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getOCLCNum
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * Holdings (WorldCat) 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
30namespace VuFind\RecordTab;
31
32use VuFindSearch\Backend\WorldCat\Command\GetHoldingsCommand;
33use VuFindSearch\Service;
34
35/**
36 * Holdings (WorldCat) tab
37 *
38 * @category VuFind
39 * @package  RecordTabs
40 * @author   Demian Katz <demian.katz@villanova.edu>
41 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
42 * @link     https://vufind.org/wiki/development:plugins:record_tabs Wiki
43 */
44class HoldingsWorldCat extends AbstractBase
45{
46    /**
47     * Search service
48     *
49     * @var Service
50     */
51    protected $searchService;
52
53    /**
54     * Constructor
55     *
56     * @param Service $searchService Search service
57     */
58    public function __construct(Service $searchService)
59    {
60        $this->searchService = $searchService;
61    }
62
63    /**
64     * Get the on-screen description for this tab.
65     *
66     * @return string
67     */
68    public function getDescription()
69    {
70        return 'Holdings';
71    }
72
73    /**
74     * Get holdings information from WorldCat (false if none available).
75     *
76     * @return \SimpleXMLElement|bool
77     */
78    public function getHoldings()
79    {
80        $id = $this->getOCLCNum();
81        if (empty($id)) {
82            return false;
83        }
84        $command = new GetHoldingsCommand('WorldCat', $id);
85        return $this->searchService->invoke($command)->getResult();
86    }
87
88    /**
89     * Is this tab active?
90     *
91     * @return bool
92     */
93    public function isActive()
94    {
95        $id = $this->getOCLCNum();
96        return !empty($id);
97    }
98
99    /**
100     * Get the OCLC number from the active record driver.
101     *
102     * @return string
103     */
104    protected function getOCLCNum()
105    {
106        return $this->getRecordDriver()->tryMethod('getCleanOCLCNum');
107    }
108}