Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Params
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 3
110
0.00% covered (danger)
0.00%
0 / 1
 initFromRecordDriver
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
72
 getCollectionField
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getCollectionId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * Solr Collection 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_SolrAuthor
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\SolrCollection;
31
32/**
33 * Solr Collection Search Options
34 *
35 * @category VuFind
36 * @package  Search_SolrAuthor
37 * @author   Demian Katz <demian.katz@villanova.edu>
38 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
39 * @link     https://vufind.org Main Site
40 */
41class Params extends \VuFind\Search\Solr\Params
42{
43    /**
44     * The field which defines something as being a collection
45     * this is usually either hierarchy_parent_id or
46     * hierarchy_top_id
47     *
48     * @var string
49     */
50    protected $collectionField = null;
51
52    /**
53     * The ID of the collection being searched
54     *
55     * @var string
56     */
57    protected $collectionID = null;
58
59    /**
60     * Pull the search parameters from the query and set up additional options using
61     * a record driver representing a collection.
62     *
63     * @param \VuFind\RecordDriver\AbstractBase $driver    Record driver
64     * @param bool                              $hasSearch Is the user performing a search?
65     *
66     * @return void
67     */
68    public function initFromRecordDriver($driver, bool $hasSearch = false)
69    {
70        $this->collectionID = $driver->tryMethod('getCollectionSearchId') ?? $driver->getUniqueID();
71        if ($hierarchyDriver = $driver->getHierarchyDriver()) {
72            $this->collectionField = $hierarchyDriver->getCollectionField($hasSearch);
73        }
74
75        if (null === $this->collectionID) {
76            throw new \Exception('Collection ID missing');
77        }
78        if (null === $this->collectionField) {
79            throw new \Exception('Collection field missing');
80        }
81
82        // We don't spellcheck this screen; it's not for free user input anyway
83        $this->getOptions()->spellcheckEnabled(false);
84
85        // Prepare the search
86        $safeId = addcslashes($this->collectionID, '"');
87        $this->addHiddenFilter($this->collectionField . ':"' . $safeId . '"');
88        $this->addHiddenFilter('!id:"' . $safeId . '"');
89
90        // Because the [HiddenFilters] and [RawHiddenFilters] settings for the
91        // Solr search backend come from searches.ini and are set up in the
92        // AbstractSolrBackendFactory, we need to account for additional ones
93        // from Collection.ini here.
94        $collectionConfig = $this->configLoader->get('Collection');
95        if (isset($collectionConfig->HiddenFilters)) {
96            foreach ($collectionConfig->HiddenFilters as $field => $value) {
97                $this->addHiddenFilter(sprintf('%s:"%s"', $field, $value));
98            }
99        }
100        if (isset($collectionConfig->RawHiddenFilters)) {
101            foreach ($collectionConfig->RawHiddenFilters as $current) {
102                $this->addHiddenFilter($current);
103            }
104        }
105    }
106
107    /**
108     * Get collection field
109     *
110     * @return string
111     */
112    public function getCollectionField()
113    {
114        return $this->collectionField;
115    }
116
117    /**
118     * Get collection id
119     *
120     * @return string
121     */
122    public function getCollectionId()
123    {
124        return $this->collectionID;
125    }
126}