Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
TopFacets
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 4
56
0.00% covered (danger)
0.00%
0 / 1
 setConfig
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
12
 init
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 getTopFacetSet
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTopFacetSettings
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * SideFacets 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 * @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/development:plugins:recommendation_modules Wiki
29 */
30
31namespace VuFind\Recommend;
32
33use function in_array;
34
35/**
36 * SideFacets Recommendations Module
37 *
38 * This class provides recommendations displaying facets beside search results
39 *
40 * @category VuFind
41 * @package  Recommendations
42 * @author   Demian Katz <demian.katz@villanova.edu>
43 * @author   Chris Hallberg <challber@villanova.edu>
44 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
45 * @link     https://vufind.org/wiki/development:plugins:recommendation_modules Wiki
46 */
47class TopFacets extends AbstractFacets
48{
49    /**
50     * Facet configuration
51     *
52     * @var array
53     */
54    protected $facets;
55
56    /**
57     * Basic configurations
58     *
59     * @var array
60     */
61    protected $baseSettings;
62
63    /**
64     * Store the configuration of the recommendation module.
65     *
66     * TopFacets:[ini section]:[ini name]
67     *      Display facets listed in the specified section of the specified ini file;
68     *      if [ini name] is left out, it defaults to "facets."
69     *
70     * @param string $settings Settings from searches.ini.
71     *
72     * @return void
73     */
74    public function setConfig($settings)
75    {
76        $settings = explode(':', $settings);
77        $mainSection = empty($settings[0]) ? 'ResultsTop' : $settings[0];
78        $iniName = $settings[1] ?? 'facets';
79
80        // Load the desired facet information:
81        $config = $this->configLoader->get($iniName);
82        $this->facets = isset($config->$mainSection)
83            ? $config->$mainSection->toArray() : [];
84
85        // Load other relevant settings:
86        $this->baseSettings = [
87            'rows' => $config->Results_Settings->top_rows,
88        ];
89
90        // Load boolean configurations:
91        $this->loadBooleanConfigs($config, array_keys($this->facets));
92    }
93
94    /**
95     * Called before the Search Results object performs its main search
96     * (specifically, in response to \VuFind\Search\SearchRunner::EVENT_CONFIGURED).
97     * This method is responsible for setting search parameters needed by the
98     * recommendation module and for reading any existing search parameters that may
99     * be needed.
100     *
101     * @param \VuFind\Search\Base\Params $params  Search parameter object
102     * @param \Laminas\Stdlib\Parameters $request Parameter object representing user
103     * request.
104     *
105     * @return void
106     */
107    public function init($params, $request)
108    {
109        // Turn on top facets in the search results:
110        foreach ($this->facets as $name => $desc) {
111            $params->addFacet($name, $desc, in_array($name, $this->orFacets));
112        }
113    }
114
115    /**
116     * Get facet information taken from the search.
117     *
118     * @return array
119     */
120    public function getTopFacetSet()
121    {
122        return $this->results->getFacetList($this->facets);
123    }
124
125    /**
126     * Get configuration settings related to top facets.
127     *
128     * @return array
129     */
130    public function getTopFacetSettings()
131    {
132        return $this->baseSettings;
133    }
134}