Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
25.00% covered (danger)
25.00%
4 / 16
37.50% covered (danger)
37.50%
3 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
Config
25.00% covered (danger)
25.00%
4 / 16
37.50% covered (danger)
37.50%
3 / 8
72.75
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
 get
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 nonJavascriptSupportEnabled
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 ajaxCoversEnabled
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getHoldingsItemLimit
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 getRecordSubjectLimit
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 alwaysDisplayIndexRecordInStaffView
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 offcanvasSide
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3/**
4 * Config view helper
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2018.
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  View_Helpers
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 Wiki
28 */
29
30namespace VuFind\View\Helper\Root;
31
32use VuFind\Config\PluginManager;
33
34/**
35 * Config view helper
36 *
37 * @category VuFind
38 * @package  View_Helpers
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 Wiki
42 */
43class Config extends \Laminas\View\Helper\AbstractHelper
44{
45    /**
46     * Configuration plugin manager
47     *
48     * @var PluginManager
49     */
50    protected $configLoader;
51
52    /**
53     * Config constructor.
54     *
55     * @param PluginManager $configLoader Configuration loader
56     */
57    public function __construct(PluginManager $configLoader)
58    {
59        $this->configLoader = $configLoader;
60    }
61
62    /**
63     * Get the specified configuration.
64     *
65     * @param string $config Name of configuration
66     *
67     * @return \Laminas\Config\Config
68     */
69    public function get($config)
70    {
71        return $this->configLoader->get($config);
72    }
73
74    /**
75     * Is non-Javascript support enabled?
76     *
77     * @return bool
78     */
79    public function nonJavascriptSupportEnabled()
80    {
81        return $this->get('config')->Site->nonJavascriptSupportEnabled ?? false;
82    }
83
84    /**
85     * Should covers be loaded via AJAX?
86     *
87     * @return bool
88     */
89    public function ajaxCoversEnabled()
90    {
91        return $this->get('config')->Content->ajaxcovers ?? false;
92    }
93
94    /**
95     * Should we limit the number of items displayed on the full record?
96     *
97     * @return int
98     */
99    public function getHoldingsItemLimit()
100    {
101        $limit = $this->get('config')->Record->holdingsItemLimit;
102        return $limit ? (int)$limit : PHP_INT_MAX;
103    }
104
105    /**
106     * Should we limit the number of subjects displayed on the full record?
107     *
108     * @return int
109     */
110    public function getRecordSubjectLimit()
111    {
112        $limit = $this->get('config')->Record->subjectLimit;
113        return $limit ? (int)$limit : PHP_INT_MAX;
114    }
115
116    /**
117     * Check if index record should always be displayed (i.e. also when a
118     * format-specific template is available)
119     *
120     * @return bool
121     */
122    public function alwaysDisplayIndexRecordInStaffView(): bool
123    {
124        return (bool)($this->get('config')->Record
125            ->alwaysDisplayIndexRecordInStaffView ?? false);
126    }
127
128    /**
129     * Get offcanvas sidebar side
130     *
131     * @return ?string 'left', 'right' or null for no offcanvas
132     */
133    public function offcanvasSide(): ?string
134    {
135        $config = $this->get('config');
136        if (!($config->Site->offcanvas ?? false)) {
137            return null;
138        }
139        return ($config->Site->sidebarOnLeft ?? false)
140            ? 'left'
141            : 'right';
142    }
143}