Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
21.62% covered (danger)
21.62%
8 / 37
20.00% covered (danger)
20.00%
1 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
DevtoolsController
21.62% covered (danger)
21.62%
8 / 37
20.00% covered (danger)
20.00%
1 / 5
94.37
0.00% covered (danger)
0.00%
0 / 1
 getQueryBuilder
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
 deminifyAction
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
72
 homeAction
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 iconAction
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 languageAction
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * Development Tools 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   Mark Triggs <vufind-tech@lists.sourceforge.net>
26 * @author   Chris Hallberg <challber@villanova.edu>
27 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
28 * @link     https://vufind.org/wiki/indexing:alphabetical_heading_browse Wiki
29 */
30
31namespace VuFindDevTools\Controller;
32
33use VuFind\I18n\Locale\LocaleSettings;
34use VuFind\I18n\Translator\Loader\ExtendedIni;
35use VuFind\Search\Results\PluginManager as ResultsManager;
36use VuFindDevTools\LanguageHelper;
37
38use function is_callable;
39
40/**
41 * Development Tools Controller
42 *
43 * @category VuFind
44 * @package  Controller
45 * @author   Mark Triggs <vufind-tech@lists.sourceforge.net>
46 * @author   Chris Hallberg <challber@villanova.edu>
47 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
48 * @link     https://vufind.org/wiki/indexing:alphabetical_heading_browse Wiki
49 */
50class DevtoolsController extends \VuFind\Controller\AbstractBase
51{
52    /**
53     * Fetch the query builder for the specified search backend. Return null if
54     * unavailable.
55     *
56     * @param string $id Backend ID
57     *
58     * @return object
59     */
60    protected function getQueryBuilder($id)
61    {
62        $command = new \VuFindSearch\Command\GetQueryBuilderCommand($id);
63        try {
64            $this->serviceLocator->get(\VuFindSearch\Service::class)
65                ->invoke($command);
66        } catch (\Exception $e) {
67            return null;
68        }
69        return $command->getResult();
70    }
71
72    /**
73     * Deminify action
74     *
75     * @return \Laminas\View\Model\ViewModel
76     */
77    public function deminifyAction()
78    {
79        $min = trim($this->params()->fromPost('min'));
80        $view = $this->createViewModel();
81        if (!empty($min)) {
82            $view->min = unserialize($min);
83        }
84        if (isset($view->min) && $view->min) {
85            $view->results = $view->min->deminify(
86                $this->serviceLocator->get(ResultsManager::class)
87            );
88        }
89        if (isset($view->results) && $view->results) {
90            $params = $view->results->getParams();
91            $view->query = $params->getQuery();
92            if (is_callable([$params, 'getBackendParameters'])) {
93                $view->backendParams = $params->getBackendParameters()
94                    ->getArrayCopy();
95            }
96            if ($builder = $this->getQueryBuilder($params->getSearchClassId())) {
97                $view->queryParams = $builder->build($view->query)->getArrayCopy();
98            }
99        }
100        return $view;
101    }
102
103    /**
104     * Home action
105     *
106     * @return \Laminas\View\Model\ViewModel
107     */
108    public function homeAction()
109    {
110        return $this->createViewModel();
111    }
112
113    /**
114     * Icon action
115     *
116     * @return array
117     */
118    public function iconAction()
119    {
120        $config = $this->serviceLocator->get(\VuFindTheme\ThemeInfo::class)
121            ->getMergedConfig('icons');
122        $aliases = array_keys($config['aliases'] ?? []);
123        sort($aliases);
124        return compact('aliases');
125    }
126
127    /**
128     * Language action
129     *
130     * @return array
131     */
132    public function languageAction()
133    {
134        // Test languages with no local overrides and no fallback:
135        $loader = new ExtendedIni([APPLICATION_PATH . '/languages']);
136        $langs = $this->serviceLocator->get(LocaleSettings::class)
137            ->getEnabledLocales();
138        $helper = new LanguageHelper($loader, $langs);
139        return $helper->getAllDetails(
140            $this->params()->fromQuery('main', 'en'),
141            (bool)$this->params()->fromQuery('includeOptional', 1)
142        );
143    }
144}