Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
QRCodeController | |
0.00% |
0 / 18 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
showAction | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
unavailableAction | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
displayQRCode | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * QRCode Controller |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2011. |
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 | * @author Luke O'Sullivan <l.osullivan@swansea.ac.uk> |
27 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
28 | * @link https://vufind.org Main Page |
29 | */ |
30 | |
31 | namespace VuFind\Controller; |
32 | |
33 | use VuFind\QRCode\Loader; |
34 | use VuFind\Session\Settings as SessionSettings; |
35 | |
36 | /** |
37 | * Generates qrcodes |
38 | * |
39 | * @category VuFind |
40 | * @package Controller |
41 | * @author Demian Katz <demian.katz@villanova.edu> |
42 | * @author Luke O'Sullivan <l.osullivan@swansea.ac.uk> |
43 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
44 | * @link https://vufind.org Main Page |
45 | */ |
46 | class QRCodeController extends \Laminas\Mvc\Controller\AbstractActionController |
47 | { |
48 | /** |
49 | * QR Code loader |
50 | * |
51 | * @var Loader |
52 | */ |
53 | protected $loader = false; |
54 | |
55 | /** |
56 | * Session settings |
57 | * |
58 | * @var SessionSettings |
59 | */ |
60 | protected $sessionSettings = null; |
61 | |
62 | /** |
63 | * Constructor |
64 | * |
65 | * @param Loader $loader QR Code Loader |
66 | * @param SessionSettings $ss Session settings |
67 | */ |
68 | public function __construct(Loader $loader, SessionSettings $ss) |
69 | { |
70 | $this->loader = $loader; |
71 | $this->sessionSettings = $ss; |
72 | } |
73 | |
74 | /** |
75 | * Send QRCode data for display in the view |
76 | * |
77 | * @return \Laminas\Http\Response |
78 | */ |
79 | public function showAction() |
80 | { |
81 | $this->sessionSettings->disableWrite(); // avoid session write timing bug |
82 | |
83 | $params = []; |
84 | foreach ($this->loader->getDefaults() as $param => $default) { |
85 | $params[$param] = $this->params()->fromQuery($param, $default); |
86 | } |
87 | $this->loader->loadQRCode($this->params()->fromQuery('text'), $params); |
88 | return $this->displayQRCode(); |
89 | } |
90 | |
91 | /** |
92 | * Return the default 'qrcode not found' information |
93 | * |
94 | * @return \Laminas\Http\Response |
95 | */ |
96 | public function unavailableAction() |
97 | { |
98 | $this->sessionSettings->disableWrite(); // avoid session write timing bug |
99 | $this->loader->loadUnavailable(); |
100 | return $this->displayQRCode(); |
101 | } |
102 | |
103 | /** |
104 | * Support method -- update the view to display the qrcode currently found in the |
105 | * \VuFind\QRCode\Loader. |
106 | * |
107 | * @return \Laminas\Http\Response |
108 | */ |
109 | protected function displayQRCode() |
110 | { |
111 | $response = $this->getResponse(); |
112 | $response->getHeaders()->addHeaderLine( |
113 | 'Content-type', |
114 | $this->loader->getContentType() |
115 | ); |
116 | $response->setContent($this->loader->getImage()); |
117 | return $response; |
118 | } |
119 | } |