Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
43.75% covered (danger)
43.75%
7 / 16
42.86% covered (danger)
42.86%
3 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
AbstractBase
43.75% covered (danger)
43.75%
7 / 16
42.86% covered (danger)
42.86%
3 / 7
27.80
0.00% covered (danger)
0.00%
0 / 1
 isActive
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 isVisible
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 supportsAjax
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setRecordDriver
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getRecordDriver
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 setRequest
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getRequest
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * Record tab abstract base class
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 LmcRbacMvc\Service\AuthorizationServiceAwareInterface;
33use LmcRbacMvc\Service\AuthorizationServiceAwareTrait;
34
35/**
36 * Record tab abstract base class
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 */
44abstract class AbstractBase implements
45    TabInterface,
46    AuthorizationServiceAwareInterface
47{
48    use AuthorizationServiceAwareTrait;
49
50    /**
51     * Permission that must be granted to access this module (null for no
52     * restriction)
53     *
54     * @var string
55     */
56    protected $accessPermission = null;
57
58    /**
59     * Record driver associated with the tab
60     *
61     * @var ?\VuFind\RecordDriver\AbstractBase
62     */
63    protected $driver = null;
64
65    /**
66     * User request associated with the tab (false for none)
67     *
68     * @var \Laminas\Http\Request|bool
69     */
70    protected $request = false;
71
72    /**
73     * Is this tab active?
74     *
75     * @return bool
76     */
77    public function isActive()
78    {
79        // If accessPermission is set, check for authorization to enable tab
80        if (!empty($this->accessPermission)) {
81            $auth = $this->getAuthorizationService();
82            if (!$auth) {
83                throw new \Exception('Authorization service missing');
84            }
85            return $auth->isGranted($this->accessPermission);
86        }
87
88        return true;
89    }
90
91    /**
92     * Is this tab initially visible?
93     *
94     * @return bool
95     */
96    public function isVisible()
97    {
98        // Assume visible by default; subclasses may add rules.
99        return true;
100    }
101
102    /**
103     * Can this tab be loaded via AJAX?
104     *
105     * @return bool
106     */
107    public function supportsAjax()
108    {
109        // Assume we can load by AJAX; subclasses may add rules.
110        return true;
111    }
112
113    /**
114     * Set the record driver
115     *
116     * @param \VuFind\RecordDriver\AbstractBase $driver Record driver
117     *
118     * @return AbstractBase
119     */
120    public function setRecordDriver(\VuFind\RecordDriver\AbstractBase $driver)
121    {
122        $this->driver = $driver;
123        return $this;
124    }
125
126    /**
127     * Get the record driver
128     *
129     * @return \VuFind\RecordDriver\AbstractBase
130     * @throws \Exception
131     */
132    protected function getRecordDriver()
133    {
134        if (null === $this->driver) {
135            throw new \Exception('Record driver not set.');
136        }
137        return $this->driver;
138    }
139
140    /**
141     * Set the user request
142     *
143     * @param \Laminas\Http\Request $request Request
144     *
145     * @return AbstractBase
146     */
147    public function setRequest(\Laminas\Http\Request $request)
148    {
149        $this->request = $request;
150        return $this;
151    }
152
153    /**
154     * Get the user request (or false if unavailable)
155     *
156     * @return \Laminas\Http\Request|bool
157     */
158    protected function getRequest()
159    {
160        return $this->request;
161    }
162}