Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
Params
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 7
110
0.00% covered (danger)
0.00%
0 / 1
 initSearch
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 setRecordIdsFromFilter
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 addHiddenFilter
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 deminify
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getDisplayQuery
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getHiddenFilters
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getRecordsToRequest
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * Mixed List aspect of the Search Multi-class (Params)
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  Search_MixedList
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 Main Site
28 */
29
30namespace VuFind\Search\MixedList;
31
32use function count;
33
34/**
35 * Search Mixed List Parameters
36 *
37 * @category VuFind
38 * @package  Search_MixedList
39 * @author   Demian Katz <demian.katz@villanova.edu>
40 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
41 * @link     https://vufind.org Main Site
42 */
43class Params extends \VuFind\Search\Base\Params
44{
45    /**
46     * Array of target record ids
47     *
48     * @var array
49     */
50    protected $recordsToRequest;
51
52    /**
53     * Initialize the object's search settings from a request object.
54     *
55     * @param \Laminas\Stdlib\Parameters $request Parameter object representing user
56     * request.
57     *
58     * @return void
59     */
60    protected function initSearch($request)
61    {
62        // Convert special 'id' parameter into a standard hidden filter:
63        $idParam = $request->get('id', []);
64        if (!empty($idParam)) {
65            $this->addHiddenFilter('ids:' . implode("\t", $idParam));
66        }
67    }
68
69    /**
70     * Parse record ids from a filter value and set as the ID list.
71     *
72     * @param string $filterValue Filter value
73     *
74     * @return void
75     */
76    protected function setRecordIdsFromFilter($filterValue)
77    {
78        $this->recordsToRequest = explode("\t", $filterValue);
79        $this->setLimit(count($this->recordsToRequest));
80    }
81
82    /**
83     * Take a filter string and add it into the protected hidden filters
84     *   array checking for duplicates.
85     *
86     * Special case for 'ids': populate the ID list and remove from hidden filters.
87     *
88     * @param string $newFilter A filter string from url : "field:value"
89     *
90     * @return void
91     */
92    public function addHiddenFilter($newFilter)
93    {
94        [$field, $value] = $this->parseFilter($newFilter);
95        if ($field == 'ids') {
96            $this->setRecordIdsFromFilter($value);
97        } else {
98            parent::addHiddenFilter($newFilter);
99        }
100    }
101
102    /**
103     * Restore settings from a minified object found in the database.
104     *
105     * @param \VuFind\Search\Minified $minified Minified Search Object
106     *
107     * @return void
108     */
109    public function deminify($minified)
110    {
111        parent::deminify($minified);
112        if (isset($this->hiddenFilters['ids'][0])) {
113            $this->setRecordIdsFromFilter($this->hiddenFilters['ids'][0]);
114            unset($this->hiddenFilters['ids']);
115        }
116    }
117
118    /**
119     * Build a string for onscreen display.
120     *
121     * @return string
122     */
123    public function getDisplayQuery()
124    {
125        return $this->translate(
126            'result_count',
127            ['%%count%%' => count($this->recordsToRequest)]
128        );
129    }
130
131    /**
132     * Return record ids as a hidden filter list so that it is properly stored when
133     * the search is represented as an URL or stored in the database.
134     *
135     * @return array
136     */
137    public function getHiddenFilters()
138    {
139        $filters = parent::getHiddenFilters();
140        $filters['ids'] = [implode("\t", $this->recordsToRequest)];
141        return $filters;
142    }
143
144    /**
145     * Get list of records to display.
146     *
147     * @return array
148     */
149    public function getRecordsToRequest()
150    {
151        return $this->recordsToRequest;
152    }
153}