Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Recommend
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setConfig
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
 getContext
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * Recommend ContentBlock.
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2024.
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  VuFind\ContentBlock
25 * @author   Demian Katz <demian.katz@villanova.edu>
26 * @license  https://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org/wiki/development Wiki
28 */
29
30namespace VuFind\ContentBlock;
31
32use Laminas\Stdlib\Parameters;
33use VuFind\Recommend\PluginManager as RecommendPluginManager;
34use VuFind\Recommend\RecommendInterface;
35use VuFind\Search\Params\PluginManager as ParamsPluginManager;
36
37/**
38 * Recommend ContentBlock.
39 *
40 * @category VuFind
41 * @package  VuFind\ContentBlock
42 * @author   Demian Katz <demian.katz@villanova.edu>
43 * @license  https://opensource.org/licenses/gpl-2.0.php GNU General Public License
44 * @link     https://vufind.org/wiki/development Wiki
45 */
46class Recommend implements ContentBlockInterface
47{
48    /**
49     * Recommendation module.
50     *
51     * @var RecommendInterface
52     */
53    protected $recommend;
54
55    /**
56     * Constructor.
57     *
58     * @param ParamsPluginManager    $paramsManager    Search params plugin manager
59     * @param RecommendPluginManager $recommendManager Recommendation plugin manager
60     * @param Parameters             $request          Query parameters from request
61     */
62    public function __construct(
63        protected ParamsPluginManager $paramsManager,
64        protected RecommendPluginManager $recommendManager,
65        protected Parameters $request
66    ) {
67    }
68
69    /**
70     * Store the configuration of the content block.
71     *
72     * @param string $settings Settings from searches.ini.
73     *
74     * @return void
75     */
76    public function setConfig($settings)
77    {
78        $parts = explode(':', $settings, 3);
79        $backend = array_shift($parts);
80        $module = array_shift($parts);
81        $this->recommend = $this->recommendManager->get($module);
82        $this->recommend->setConfig($parts[0] ?? '');
83        $params = $this->paramsManager->get($backend ?: DEFAULT_SEARCH_BACKEND);
84        $this->recommend->init($params, $this->request);
85    }
86
87    /**
88     * Return context variables used for rendering the block's template.
89     *
90     * @return array
91     */
92    public function getContext()
93    {
94        return ['recommend' => $this->recommend];
95    }
96}