Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
PrimoController
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 6
72
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
 resultScrollerActive
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 citedByAction
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 citesAction
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 performCitationSearch
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
12
 searchAction
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * Primo Central Controller
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2010.
9 * Copyright (C) The National Library of Finland 2023.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2,
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 *
24 * @category VuFind
25 * @package  Controller
26 * @author   Demian Katz <demian.katz@villanova.edu>
27 * @author   Ere Maijala <ere.maijala@helsinki.fi>
28 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
29 * @link     https://vufind.org Main Site
30 */
31
32namespace VuFind\Controller;
33
34use Laminas\ServiceManager\ServiceLocatorInterface;
35
36/**
37 * Primo Central Controller
38 *
39 * @category VuFind
40 * @package  Controller
41 * @author   Demian Katz <demian.katz@villanova.edu>
42 * @author   Ere Maijala <ere.maijala@helsinki.fi>
43 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
44 * @link     https://vufind.org Main Site
45 */
46class PrimoController extends AbstractSearch
47{
48    /**
49     * Constructor
50     *
51     * @param ServiceLocatorInterface $sm Service locator
52     */
53    public function __construct(ServiceLocatorInterface $sm)
54    {
55        $this->accessPermission = 'access.PrimoModule';
56        $this->searchClassId = 'Primo';
57        parent::__construct($sm);
58    }
59
60    /**
61     * Is the result scroller active?
62     *
63     * @return bool
64     */
65    protected function resultScrollerActive()
66    {
67        $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class)
68            ->get('Primo');
69        return $config->Record->next_prev_navigation ?? false;
70    }
71
72    /**
73     * Show results of "cited by" search.
74     *
75     * @return mixed
76     */
77    public function citedByAction()
78    {
79        $this->flashMessenger()->addInfoMessage('results_citing_title_note');
80        return $this->performCitationSearch();
81    }
82
83    /**
84     * Show results of "cites" search.
85     *
86     * @return mixed
87     */
88    public function citesAction()
89    {
90        $this->flashMessenger()->addInfoMessage('results_cited_by_title_note');
91        return $this->performCitationSearch();
92    }
93
94    /**
95     * Perform a "cited" or "cited by" search
96     *
97     * @return mixed
98     */
99    protected function performCitationSearch()
100    {
101        if (!($id = trim($this->params()->fromQuery('lookfor', ''), '"'))) {
102            return $this->forwardTo('Primo', 'Home');
103        }
104        $driver = $this->getRecordLoader()->load($id, $this->searchClassId);
105
106        // Don't save to history -- history page doesn't handle correctly:
107        $this->saveToHistory = false;
108
109        $callback = function ($runner, $params, $searchId) {
110            $options = $params->getOptions();
111            $options->disableHighlighting();
112            $options->spellcheckEnabled(false);
113            if ($lastLimit = $this->getSearchMemory()->retrieveLastSetting($this->searchClassId, 'limit')) {
114                $params->setLimit($lastLimit);
115            }
116        };
117
118        $view = $this->getSearchResultsView($callback);
119        $view->driver = $driver;
120        return $view;
121    }
122
123    /**
124     * Search action -- call standard results action
125     *
126     * @return mixed
127     */
128    public function searchAction()
129    {
130        return $this->resultsAction();
131    }
132}