Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
RelaisController
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 3
56
0.00% covered (danger)
0.00%
0 / 1
 loginAction
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
20
 getRelaisUserIdentifier
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 requestAction
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3/**
4 * Relais Controller
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  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 function is_array;
33
34/**
35 * Relais Controller
36 *
37 * @category VuFind
38 * @package  Controller
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 Main Site
42 */
43class RelaisController extends AbstractBase
44{
45    /**
46     * Relais login action
47     *
48     * @return mixed
49     */
50    public function loginAction()
51    {
52        // Fatal error if not configured correctly:
53        $config = $this->getConfig();
54        $baseUrl = $config->Relais->loginUrl ?? null;
55        if (empty($baseUrl)) {
56            throw new \Exception('Relais login URL not set.');
57        }
58
59        // Stop now if the user does not have valid catalog credentials available:
60        if (!is_array($patron = $this->catalogLogin())) {
61            return $patron;
62        }
63
64        // Send user credentials through to Relais:
65        $symbol = $config->Relais->symbol ?? '';
66        $q = $this->params()->fromQuery('query');
67        $url = $baseUrl . '?LS=' . urlencode($symbol)
68            . '&dest=discovery&group=patron&PI='
69            . urlencode($this->getRelaisUserIdentifier($patron));
70        if (!empty($q)) {
71            $url .= '&query=' . rawurlencode($q);
72        }
73        return $this->redirect()->toUrl($url);
74    }
75
76    /**
77     * Given patron data from the catalogLogin() method, return the appropriate
78     * identifier for use with Relais.
79     *
80     * @param array $patron Patron details
81     *
82     * @return string
83     */
84    protected function getRelaisUserIdentifier($patron)
85    {
86        // By default we assume the cat_username field provides the appropriate
87        // username... but if you have a more complex situation at your local
88        // institution, you can extend the controller and override this method.
89        return $patron['cat_username'];
90    }
91
92    /**
93     * Relais request action.
94     *
95     * @return mixed
96     */
97    public function requestAction()
98    {
99        // Stop now if the user does not have valid catalog credentials available:
100        if (!is_array($patron = $this->catalogLogin())) {
101            return $patron;
102        }
103        return $this->createViewModel(
104            [
105                'oclc' => $this->params()->fromQuery('oclc'),
106                'failLink' => $this->params()->fromQuery('failLink'),
107            ]
108        );
109    }
110}