Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
ComponentParts
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
5 / 5
6
100.00% covered (success)
100.00%
1 / 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
 isActive
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 getMaxResults
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getResults
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * Component parts display tab
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2019, 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
30namespace VuFind\RecordTab;
31
32use VuFindSearch\Command\SearchCommand;
33
34/**
35 * Component parts display 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 */
43class ComponentParts extends AbstractBase
44{
45    /**
46     * Similar records
47     *
48     * @var array
49     */
50    protected $results;
51
52    /**
53     * Maximum results to display
54     *
55     * @var int
56     */
57    protected $maxResults = 100;
58
59    /**
60     * Search service
61     *
62     * @var \VuFindSearch\Service
63     */
64    protected $searchService;
65
66    /**
67     * Constructor
68     *
69     * @param \VuFindSearch\Service $search Search service
70     */
71    public function __construct(\VuFindSearch\Service $search)
72    {
73        $this->searchService = $search;
74    }
75
76    /**
77     * Get the on-screen description for this tab.
78     *
79     * @return string
80     */
81    public function getDescription()
82    {
83        return 'child_records';
84    }
85
86    /**
87     * Is this tab active?
88     *
89     * @return bool
90     */
91    public function isActive()
92    {
93        $children = $this->getRecordDriver()->tryMethod('getChildRecordCount');
94        return $children !== null && $children > 0;
95    }
96
97    /**
98     * Get the maximum result count.
99     *
100     * @return int
101     */
102    public function getMaxResults()
103    {
104        return $this->maxResults;
105    }
106
107    /**
108     * Get the contents for display.
109     *
110     * @return RecordCollectionInterface
111     */
112    public function getResults()
113    {
114        $record = $this->getRecordDriver();
115        $safeId = addcslashes($record->getUniqueId(), '"');
116        $query = new \VuFindSearch\Query\Query(
117            'hierarchy_parent_id:"' . $safeId . '"'
118        );
119        $params = new \VuFindSearch\ParamBag(
120            [
121                // Disable highlighting for efficiency; not needed here:
122                'hl' => ['false'],
123                // Sort appropriately:
124                'sort' => 'hierarchy_sequence ASC,title ASC',
125            ]
126        );
127        $command = new SearchCommand(
128            $record->getSourceIdentifier(),
129            $query,
130            0,
131            // retrieve 1 more than max results, so we know when to
132            // display a "more" link:
133            $this->maxResults + 1,
134            $params
135        );
136        return $this->searchService->invoke($command)->getResult();
137    }
138}