Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractSummonRecommendDeferred
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 initLookFor
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3/**
4 * Abstract base for deferred-load Summon recommendations modules
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2014.
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   Lutz Biedinger <lutz.biedinger@gmail.com>
26 * @author   Demian Katz <demian.katz@villanova.edu>
27 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
28 * @link     https://vufind.org/wiki/development:plugins:recommendation_modules Wiki
29 */
30
31namespace VuFind\Recommend;
32
33use function is_object;
34
35/**
36 * Abstract base for deferred-load Summon recommendations modules
37 *
38 * @category VuFind
39 * @package  Recommendations
40 * @author   Lutz Biedinger <lutz.biedigner@gmail.com>
41 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
42 * @link     https://vufind.org/wiki/development:plugins:recommendation_modules Wiki
43 */
44abstract class AbstractSummonRecommendDeferred extends AbstractSearchObjectDeferred
45{
46    /**
47     * Number of expected module parameters (from .ini config)
48     *
49     * @var int
50     */
51    protected $paramCount = 1;
52
53    /**
54     * Initialize the lookFor query parameter. Called from init().
55     *
56     * @param \VuFind\Search\Base\Params $params   Search parameter object
57     * @param \Laminas\Stdlib\Parameters $request  Parameter object representing user
58     * request.
59     * @param array                      $settings Parameter array (passed by reference)
60     *
61     * @return void
62     */
63    protected function initLookFor($params, $request, &$settings)
64    {
65        // Collect the best possible search term(s):
66        $lookforParam = empty($settings[0]) ? 'lookfor' : $settings[0];
67        $this->lookfor = $request->get($lookforParam, '');
68        if (empty($this->lookfor) && is_object($params)) {
69            $this->lookfor = $params->getQuery()->getAllTerms();
70        }
71        $this->lookfor = trim($this->lookfor);
72
73        // In AJAX mode, the query will always be found in the 'lookfor' parameter,
74        // so override the setting:
75        $settings[0] = 'lookfor';
76    }
77}