Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
88.24% covered (warning)
88.24%
15 / 17
66.67% covered (warning)
66.67%
4 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
AbstractChannelProvider
88.24% covered (warning)
88.24%
15 / 17
66.67% covered (warning)
66.67%
4 / 6
9.13
0.00% covered (danger)
0.00%
0 / 1
 configureSearchParams
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setCoverRouter
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setRecordRouter
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setProviderId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setOptions
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 summarizeRecordDrivers
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3/**
4 * Abstract base class for channel providers.
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2016.
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  Channels
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 Wiki
28 */
29
30namespace VuFind\ChannelProvider;
31
32use VuFind\Cover\Router as CoverRouter;
33use VuFind\Record\Router as RecordRouter;
34use VuFind\Search\Base\Params;
35
36/**
37 * Abstract base class for channel providers.
38 *
39 * @category VuFind
40 * @package  Channels
41 * @author   Demian Katz <demian.katz@villanova.edu>
42 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
43 * @link     https://vufind.org/wiki/development Wiki
44 */
45abstract class AbstractChannelProvider implements ChannelProviderInterface
46{
47    /**
48     * Cover router
49     *
50     * @var CoverRouter
51     */
52    protected $coverRouter = null;
53
54    /**
55     * Provider ID
56     *
57     * @var string
58     */
59    protected $providerId = '';
60
61    /**
62     * Record router
63     *
64     * @var RecordRouter
65     */
66    protected $recordRouter = null;
67
68    /**
69     * Hook to configure search parameters before executing search.
70     *
71     * @param Params $params Search parameters to adjust
72     *
73     * @return void
74     *
75     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
76     */
77    public function configureSearchParams(Params $params)
78    {
79        // No action necessary by default.
80    }
81
82    /**
83     * Inject cover router
84     *
85     * @param CoverRouter $coverRouter Cover router.
86     *
87     * @return void
88     */
89    public function setCoverRouter(CoverRouter $coverRouter)
90    {
91        $this->coverRouter = $coverRouter;
92    }
93
94    /**
95     * Inject record router
96     *
97     * @param RecordRouter $recordRouter Record router.
98     *
99     * @return void
100     */
101    public function setRecordRouter(RecordRouter $recordRouter)
102    {
103        $this->recordRouter = $recordRouter;
104    }
105
106    /**
107     * Set an identifier that will be injected as the 'providerId' key of all
108     * channels created by this provider.
109     *
110     * @param string $id Provider ID
111     *
112     * @return void
113     */
114    public function setProviderId($id)
115    {
116        $this->providerId = $id;
117    }
118
119    /**
120     * Set the options for the provider.
121     *
122     * @param array $options Options
123     *
124     * @return void
125     *
126     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
127     */
128    public function setOptions(array $options)
129    {
130        // No options required by default
131    }
132
133    /**
134     * Convert a search results object into channel contents.
135     *
136     * @param array|\Traversable $drivers Record drivers to summarize.
137     *
138     * @return array
139     */
140    protected function summarizeRecordDrivers($drivers)
141    {
142        $summary = [];
143        foreach ($drivers as $current) {
144            $summary[] = [
145                'title' => $current->getTitle(),
146                'source' => $current->getSourceIdentifier(),
147                'thumbnail' => $this->coverRouter
148                    ? $this->coverRouter->getUrl($current, 'medium')
149                    : false,
150                'routeDetails' => $this->recordRouter
151                    ? $this->recordRouter->getTabRouteDetails($current)
152                    : false,
153                'id' => $current->getUniqueId(),
154            ];
155        }
156        return $summary;
157    }
158}