Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
EdsrecordController
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 6
110
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 redirectToEbook
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
30
 epubAction
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 linkedtextAction
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 pdfAction
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 resultScrollerActive
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * EDS Record Controller
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  Controller
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 Main Site
28 */
29
30namespace VuFind\Controller;
31
32use Laminas\ServiceManager\ServiceLocatorInterface;
33use VuFind\Exception\Forbidden as ForbiddenException;
34use VuFindSearch\ParamBag;
35
36/**
37 * EDS Record Controller
38 *
39 * @category VuFind
40 * @package  Controller
41 * @author   Demian Katz <demian.katz@villanova.edu>
42 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
43 * @link     https://vufind.org Main Site
44 */
45class EdsrecordController extends AbstractRecord
46{
47    /**
48     * Constructor
49     *
50     * @param ServiceLocatorInterface $sm Service locator
51     */
52    public function __construct(ServiceLocatorInterface $sm)
53    {
54        // Override some defaults:
55        $this->sourceId = 'EDS';
56        $this->fallbackDefaultTab = 'Description';
57
58        // Call standard record controller initialization:
59        parent::__construct($sm);
60    }
61
62    /**
63     * Redirect to an eBook.
64     *
65     * @param string $format Format of eBook to request from API.
66     * @param string $method Record driver method to use to obtain target URL.
67     *
68     * @return mixed
69     */
70    protected function redirectToEbook($format, $method)
71    {
72        $paramArray = $format === null ? [] : ['ebookpreferredformat' => $format];
73        $params = new ParamBag($paramArray);
74        $driver = $this->loadRecord($params, true);
75        // If the user is a guest, redirect them to the login screen.
76        $auth = $this->getAuthorizationService();
77        if (!$auth->isGranted('access.EDSExtendedResults')) {
78            if (!$this->getUser()) {
79                return $this->forceLogin();
80            }
81            throw new ForbiddenException('Access denied.');
82        }
83        $url = $driver->tryMethod($method);
84        if (!$url) {
85            $this->flashMessenger()->addErrorMessage($this->translate('error_accessing_full_text'));
86            return $this->redirect()->toRoute('edsrecord', ['id' => $this->params()->fromRoute('id')]);
87        }
88        return $this->redirect()->toUrl($url);
89    }
90
91    /**
92     * Action to display ePub.
93     *
94     * @return mixed
95     */
96    public function epubAction()
97    {
98        return $this->redirectToEbook('ebook-epub', 'getEpubLink');
99    }
100
101    /**
102     * Linked text display action.
103     *
104     * @return mixed
105     */
106    public function linkedtextAction()
107    {
108        return $this->redirectToEbook(null, 'getLinkedFullTextLink');
109    }
110
111    /**
112     * PDF display action.
113     *
114     * @return mixed
115     */
116    public function pdfAction()
117    {
118        return $this->redirectToEbook('ebook-pdf', 'getPdfLink');
119    }
120
121    /**
122     * Is the result scroller active?
123     *
124     * @return bool
125     */
126    protected function resultScrollerActive()
127    {
128        $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class)
129            ->get('EDS');
130        return $config->Record->next_prev_navigation ?? false;
131    }
132}