Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
QueryAdapter
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
56
0.00% covered (danger)
0.00%
0 / 1
 displayAdvanced
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
56
1<?php
2
3/**
4 * EDS API Query Adapter: search query parameters to AbstractQuery object
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2011.
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  EBSCO
25 * @author   Michelle Milton <mmilton@epnet.com>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org Main Page
28 */
29
30namespace VuFind\Search\EDS;
31
32use VuFindSearch\Query\AbstractQuery;
33use VuFindSearch\Query\Query;
34use VuFindSearch\Query\QueryGroup;
35
36use function call_user_func;
37use function count;
38
39/**
40 * EDS API Query Adapter: search query parameters to AbstractQuery object
41 *
42 * @category VuFind
43 * @package  EBSCO
44 * @author   Michelle Milton <mmilton@epnet.com>
45 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
46 * @link     https://vufind.org Main Page
47 */
48class QueryAdapter extends \VuFind\Search\QueryAdapter
49{
50    /**
51     * Support method for display() -- process advanced queries.
52     *
53     * @param QueryGroup $query     Query to convert
54     * @param callable   $translate Callback to translate strings
55     * @param callable   $showName  Callback to translate field names
56     *
57     * @return string
58     */
59    protected function displayAdvanced(
60        QueryGroup $query,
61        callable $translate,
62        callable $showName
63    ) {
64        // There should only ever be 1 group with EDS queries.
65        $all = [];
66        foreach ($query->getQueries() as $search) {
67            if ($search instanceof QueryGroup) {
68                // Process each search group. There should only be 1 with EDS queries
69                $groupQueries = $search->getQueries();
70                for ($i = 0; $i < count($groupQueries); $i++) {
71                    $group = $groupQueries[$i];
72                    if ($group instanceof Query) {
73                        // Build this group individually as a basic search
74                        $queryOperator = $group->getOperator();
75                        $op = (null != $queryOperator && 0 != $i) ?
76                            call_user_func($translate, $queryOperator) . ' ' : '';
77                        $all[] = $op
78                            . call_user_func($showName, $group->getHandler()) . ':'
79                            . $group->getString();
80                    } else {
81                        throw new \Exception('Unexpected ' . $group::class);
82                    }
83                }
84            } else {
85                throw new \Exception('Unexpected ' . $search::class);
86            }
87        }
88        return '(' . implode(' ', $all) . ')';
89    }
90}