Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
SummonTopics
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 init
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getResults
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 configureSummonResults
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * SummonTopics Recommendations Module
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  Recommendations
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/wiki/development:plugins:recommendation_modules Wiki
28 */
29
30namespace VuFind\Recommend;
31
32/**
33 * SummonTopics Recommendations Module
34 *
35 * This class provides database recommendations by doing a search of Summon.
36 *
37 * @category VuFind
38 * @package  Recommendations
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/wiki/development:plugins:recommendation_modules Wiki
42 */
43class SummonTopics extends AbstractSummonRecommend
44{
45    /**
46     * Called before the Search Results object performs its main search
47     * (specifically, in response to \VuFind\Search\SearchRunner::EVENT_CONFIGURED).
48     * This method is responsible for setting search parameters needed by the
49     * recommendation module and for reading any existing search parameters that may
50     * be needed.
51     *
52     * @param \VuFind\Search\Base\Params $params  Search parameter object
53     * @param \Laminas\Stdlib\Parameters $request Parameter object representing user
54     * request.
55     *
56     * @return void
57     */
58    public function init($params, $request)
59    {
60        parent::init($params, $request);
61        if ($params->getSearchClassId() == 'Summon') {
62            $params->getOptions()->setMaxTopicRecommendations(1);
63        }
64    }
65
66    /**
67     * Get topic results.
68     *
69     * @return array
70     */
71    public function getResults()
72    {
73        return $this->results->getTopicRecommendations();
74    }
75
76    /**
77     * If we have to create a new Summon results object, this method is used to
78     * configure it with appropriate settings.
79     *
80     * @param \VuFind\Search\Summon\Results $results Search results object
81     *
82     * @return void
83     */
84    protected function configureSummonResults(\VuFind\Search\Summon\Results $results)
85    {
86        parent::configureSummonResults($results);
87        $results->getOptions()->setMaxTopicRecommendations(1);
88    }
89}