Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
66.67% covered (warning)
66.67%
6 / 9
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
CollectionHierarchyTree
66.67% covered (warning)
66.67%
6 / 9
33.33% covered (danger)
33.33%
1 / 3
5.93
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 renderTree
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getActiveRecord
66.67% covered (warning)
66.67%
4 / 6
0.00% covered (danger)
0.00%
0 / 1
3.33
1<?php
2
3/**
4 * HierarchyTree 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
32/**
33 * HierarchyTree tab
34 *
35 * @category VuFind
36 * @package  RecordTabs
37 * @author   Demian Katz <demian.katz@villanova.edu>
38 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
39 * @link     https://vufind.org/wiki/development:plugins:record_tabs Wiki
40 */
41class CollectionHierarchyTree extends HierarchyTree
42{
43    /**
44     * Record loader
45     *
46     * @var \VuFind\Record\Loader
47     */
48    protected $loader;
49
50    /**
51     * Constructor
52     *
53     * @param \Laminas\Config\Config $config Configuration
54     * @param \VuFind\Record\Loader  $loader Record loader
55     */
56    public function __construct(
57        \Laminas\Config\Config $config,
58        \VuFind\Record\Loader $loader
59    ) {
60        parent::__construct($config);
61        $this->loader = $loader;
62    }
63
64    /**
65     * Render a hierarchy tree
66     *
67     * @param string  $id      Hierarchy ID (omit to use active tree)
68     * @param ?string $context Context for use by renderer or null for default
69     * @param array   $options Additional options (like previewElement)
70     *
71     * @return string
72     */
73    public function renderTree(string $id = null, ?string $context = null, array $options = [])
74    {
75        // Same as parent -- we just have a different default context:
76        return parent::renderTree($id, $context ?? 'Collection', $options);
77    }
78
79    /**
80     * Get the current active record. Returns record driver if there is an active
81     * record or null otherwise.
82     *
83     * @return ?\VuFind\RecordDriver\AbstractBase
84     */
85    public function getActiveRecord(): ?\VuFind\RecordDriver\AbstractBase
86    {
87        $id = $this->getRequest()->getQuery('recordID');
88        if (null === $id) {
89            return $this->driver;
90        }
91        try {
92            return $this->loader->load($id);
93        } catch (\VuFind\Exception\RecordMissing $e) {
94            return null;
95        }
96    }
97}