Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Channels
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 3
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 setConfig
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 getContext
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * Channels content block.
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2018.
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  ContentBlock
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\ContentBlock;
31
32use Laminas\Http\PhpEnvironment\Request;
33use VuFind\ChannelProvider\ChannelLoader;
34
35/**
36 * Channels content block.
37 *
38 * @category VuFind
39 * @package  ContentBlock
40 * @author   Demian Katz <demian.katz@villanova.edu>
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 */
44class Channels implements ContentBlockInterface
45{
46    /**
47     * Request object
48     *
49     * @var Request
50     */
51    protected $request;
52
53    /**
54     * Channel loader
55     *
56     * @var ChannelLoader
57     */
58    protected $loader;
59
60    /**
61     * Data source (null to use default found in channels.ini)
62     *
63     * @var string
64     */
65    protected $source = null;
66
67    /**
68     * Constructor
69     *
70     * @param Request       $request Request object
71     * @param ChannelLoader $loader  Channel loader
72     */
73    public function __construct(Request $request, ChannelLoader $loader)
74    {
75        $this->request = $request;
76        $this->loader = $loader;
77    }
78
79    /**
80     * Store the configuration of the content block.
81     *
82     * @param string $settings Settings from searches.ini.
83     *
84     * @return void
85     */
86    public function setConfig($settings)
87    {
88        if (!empty($settings)) {
89            $this->source = $settings;
90        }
91    }
92
93    /**
94     * Return context variables used for rendering the block's template.
95     *
96     * @return array
97     */
98    public function getContext()
99    {
100        $activeChannel = $this->request->getQuery()->get('channelProvider');
101        $token = $this->request->getQuery()->get('channelToken');
102        return $this->loader->getHomeContext($token, $activeChannel, $this->source);
103    }
104}