Skip to content

Commit ebcd81c

Browse files
committed
Merge remote-tracking branch 'origin/release-9.0' into dev
2 parents ea553ae + e0e8eec commit ebcd81c

File tree

5 files changed

+76
-4
lines changed

5 files changed

+76
-4
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/**
4+
* OperatorToFieldPrefix view helper
5+
*
6+
* PHP version 8
7+
*
8+
* Copyright (C) Villanova University 2023.
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 View_Helpers
25+
* @author Demian Katz <[email protected]>
26+
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27+
* @link https://vufind.org/wiki/development Wiki
28+
*/
29+
30+
namespace VuFind\View\Helper\Root;
31+
32+
/**
33+
* OperatorToFieldPrefix view helper
34+
*
35+
* @category VuFind
36+
* @package View_Helpers
37+
* @author Demian Katz <[email protected]>
38+
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
39+
* @link https://vufind.org/wiki/development Wiki
40+
*/
41+
class OperatorToFieldPrefix extends \Laminas\View\Helper\AbstractHelper
42+
{
43+
/**
44+
* Given a Boolean operator from a filter, convert it into a VuFind URL field prefix.
45+
*
46+
* @param string $operator Boolean operator (AND/OR/NOT)
47+
*
48+
* @return string
49+
*/
50+
public function __invoke(string $operator): string
51+
{
52+
switch (strtoupper(trim($operator))) {
53+
case 'OR':
54+
return '~';
55+
case 'NOT':
56+
return '-';
57+
}
58+
// Default case -- no prefix:
59+
return '';
60+
}
61+
}

themes/bootstrap3/templates/search/advanced/layout.phtml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,17 @@
192192
<?php foreach ($searchFilters as $field => $data): ?>
193193
<div class="facet-group">
194194
<div class="title"><?=$this->transEsc($field)?></div>
195-
<?php foreach ($data as $value): ?>
196-
<label class="facet checkbox"><input class="checkbox-select-item" type="checkbox" checked="checked" name="filter[]" value='<?=$this->escapeHtmlAttr($value['field'])?>:"<?=$this->escapeHtmlAttr($value['value'])?>"'> <?=$this->escapeHtml($value['displayText'])?></label>
195+
<?php foreach ($data as $i => $value): ?>
196+
<?php $operator = $value['operator'] ?? 'AND'; ?>
197+
<label class="facet checkbox">
198+
<input class="checkbox-select-item" type="checkbox" checked="checked" name="filter[]" value="<?=$this->escapeHtmlAttr($this->operatorToFieldPrefix($operator) . $value['field'] . ':"' . $value['value'] . '"')?>">
199+
<?php if ($operator === 'NOT'): ?>
200+
<?=$this->transEsc('NOT')?>
201+
<?php elseif ($operator === 'OR' && $i > 0): ?>
202+
<?=$this->transEsc('OR')?>
203+
<?php endif; ?>
204+
<?=$this->escapeHtml($value['displayText'])?>
205+
</label>
197206
<?php endforeach; ?>
198207
</div>
199208
<?php endforeach; ?>

themes/bootstrap3/templates/search/advanced/solr.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<?php if (is_array($this->hierarchicalFacets) && in_array($field, $this->hierarchicalFacets)): ?>
1313
<?php foreach ($list['list'] as $value): ?>
1414
<?php $display = str_pad('', 4 * $value['level'] * 6, '&nbsp;', STR_PAD_LEFT) . $this->escapeHtml($value['displayText']); ?>
15-
<option value="<?=$this->escapeHtmlAttr(($value['operator'] == 'OR' ? '~' : '') . $field . ':"' . $value['value'] . '"')?>"<?=(isset($value['selected']) && $value['selected']) ? ' selected="selected"' : ''?>><?=$display?></option>
15+
<option value="<?=$this->escapeHtmlAttr($this->operatorToFieldPrefix($value['operator']) . $field . ':"' . $value['value'] . '"')?>"<?=(isset($value['selected']) && $value['selected']) ? ' selected="selected"' : ''?>><?=$display?></option>
1616
<?php endforeach; ?>
1717
<?php else: ?>
1818
<?php

themes/bootstrap3/templates/search/advanced/summon.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
?>
2121
<?php foreach ($sorted as $i => $display): ?>
2222
<?php $value = $list['list'][$i]; ?>
23-
<option value="<?=$this->escapeHtmlAttr(($value['operator'] == 'OR' ? '~' : '') . $field . ':"' . $value['value'] . '"')?>"<?=(isset($value['selected']) && $value['selected']) ? ' selected="selected"' : ''?>><?=$this->escapeHtml($display)?></option>
23+
<option value="<?=$this->escapeHtmlAttr($this->operatorToFieldPrefix($value['operator']) . $field . ':"' . $value['value'] . '"')?>"<?=(isset($value['selected']) && $value['selected']) ? ' selected="selected"' : ''?>><?=$this->escapeHtml($display)?></option>
2424
<?php endforeach; ?>
2525
</select>
2626
</div>

themes/root/theme.config.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
'VuFind\View\Helper\Root\Matomo' => 'VuFind\View\Helper\Root\MatomoFactory',
5151
'VuFind\View\Helper\Root\Metadata' => 'VuFind\View\Helper\Root\MetadataFactory',
5252
'VuFind\View\Helper\Root\OpenUrl' => 'VuFind\View\Helper\Root\OpenUrlFactory',
53+
'VuFind\View\Helper\Root\OperatorToFieldPrefix' => 'Laminas\ServiceManager\Factory\InvokableFactory',
5354
'VuFind\View\Helper\Root\Overdrive' => 'VuFind\View\Helper\Root\OverdriveFactory',
5455
'VuFind\View\Helper\Root\Permission' => 'VuFind\View\Helper\Root\PermissionFactory',
5556
'VuFind\View\Helper\Root\Piwik' => 'VuFind\View\Helper\Root\PiwikFactory',
@@ -137,6 +138,7 @@
137138
'matomo' => 'VuFind\View\Helper\Root\Matomo',
138139
'metadata' => 'VuFind\View\Helper\Root\Metadata',
139140
'openUrl' => 'VuFind\View\Helper\Root\OpenUrl',
141+
'operatorToFieldPrefix' => 'VuFind\View\Helper\Root\OperatorToFieldPrefix',
140142
'overdrive' => 'VuFind\View\Helper\Root\Overdrive',
141143
'permission' => 'VuFind\View\Helper\Root\Permission',
142144
'piwik' => 'VuFind\View\Helper\Root\Piwik',

0 commit comments

Comments
 (0)