From ebeeffe6c8bf812a5118896fec25a3d025f6f36b Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 14 Jan 2022 14:08:51 +0000 Subject: [PATCH] Bug 17170: Add search filters to staff and opac interfaces This patch displays the filters on the results pages with the facets --- Koha/SearchFilter.pm | 2 +- catalogue/search.pl | 24 ++++ .../intranet-tmpl/prog/en/includes/facets.inc | 18 +++ .../prog/en/modules/catalogue/results.tt | 120 ++++++++++++++++++ .../bootstrap/en/includes/opac-facets.inc | 17 +++ opac/opac-search.pl | 10 ++ 6 files changed, 190 insertions(+), 1 deletion(-) diff --git a/Koha/SearchFilter.pm b/Koha/SearchFilter.pm index f400a8f703..493e1fc1ee 100644 --- a/Koha/SearchFilter.pm +++ b/Koha/SearchFilter.pm @@ -15,7 +15,7 @@ package Koha::SearchFilter; # along with Koha; if not, see . use Modern::Perl; - +use JSON qw( encode_json decode_json ); use Koha::Database; diff --git a/catalogue/search.pl b/catalogue/search.pl index 24e8692d27..c1996f9499 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -156,8 +156,10 @@ use Koha::SearchEngine::Search; use Koha::SearchEngine::QueryBuilder; use Koha::Virtualshelves; use Koha::SearchFields; +use Koha::SearchFilters; use URI::Escape; +use JSON qw( decode_json encode_json ); my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold"); # create a new CGI object @@ -477,6 +479,7 @@ $template->param ( QUERY_INPUTS => \@query_inputs, ## parse the limit_cgi string and put it into a form suitable for s my @limit_inputs; +my %active_filters; if ($limit_cgi) { for my $this_cgi ( split('&', $limit_cgi) ) { next unless $this_cgi; @@ -490,6 +493,11 @@ if ($limit_cgi) { my $input_value = $2; $input_name =~ s/=$//; push @limit_inputs, { input_name => $input_name, input_value => Encode::decode_utf8( uri_unescape($input_value) ) }; + if( $input_value =~ /search_filter/ ){ + my ($filter_id) = ( uri_unescape($input_value) =~ /^search_filter:(.*)$/ ); + $active_filters{$filter_id} = 1; + } + } } $template->param ( LIMIT_INPUTS => \@limit_inputs ); @@ -574,9 +582,19 @@ for (my $i=0;$i<@servers;$i++) { $template->param (z3950_search_params => C4::Search::z3950_search_args($z3950par || $query_desc)); $template->param(limit_cgi => $limit_cgi); $template->param(query_cgi => $query_cgi); + $template->param(query_json => encode_json({ + operators => \@operators, + operands => \@operands, + indexes => \@indexes + })); + $template->param(limit_json => encode_json({ + limits => \@limits + })); $template->param(query_desc => $query_desc); $template->param(limit_desc => $limit_desc); $template->param(offset => $offset); + $template->param(offset => $offset); + if ($hits) { $template->param(total => $hits); @@ -665,6 +683,12 @@ for my $facet ( @$facets ) { } } + +$template->param( + search_filters => Koha::SearchFilters->search({ staff_client => 1 }, { order_by => "name" }), + active_filters => \%active_filters, +) if C4::Context->preference('SavedSearchFilters'); + $template->param( #classlist => $classlist, total => $total, diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc index d31ade3d23..c4c854cadb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc @@ -1,11 +1,29 @@ [% USE raw %] [% USE AuthorisedValues %] [% USE Languages %] + [% IF ( opacfacets ) %] [% IF ( facets_loop ) %]

Refine your search

    +[% IF Koha.Preference("SavedSearchFilters") && search_filters.count > 0 %] +
  • +Custom search filters +
      + [% SET base_url = "/cgi-bin/koha/catalogue/search.pl?" _ query_cgi _ limit_cgi %] + [% FOREACH search_filter IN search_filters %] +
    • + [% IF active_filters.${search_filter.id} %] + [% search_filter.name | html %][X] + [% ELSE %] + [% search_filter.name | html %] + [% END %] +
    • + [% END %] +
    +
  • +[% END %]
  • Availability [% IF ( related ) %]
  • (related searches: [% FOREACH relate IN related %][% relate.related_search | html %][% END %])
  • [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt index f9b80cffe6..8e05f71e4c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -69,6 +69,9 @@ [% total | html %] result(s) found [% IF ( query_desc ) %]for '[% query_desc | html %]'[% END %][% IF limit_desc %] with limit(s): '[% limit_desc | html %]'[% END %][% IF ( LibraryName ) %] in [% LibraryName | html %] Catalog[% END %]. Edit this search + [% IF ( Koha.Preference('SavedSearchFilters') && CAN_user_parameters_manage_search_filters ) %] + | Save search as filter + [% END %]
    @@ -331,6 +334,9 @@

    View basket

    [% END %] Edit this search + [% IF ( Koha.Preference('SavedSearchFilters') &&CAN_user_parameters_manage_search_filters ) %] + | Save search as filter + [% END %] [% ELSE %]

    You did not specify any search criteria.

    [% END %] @@ -687,6 +693,39 @@
    [% END #/IF outer_sup_results_loop %] + [% IF ( Koha.Preference('SavedSearchFilters') && CAN_user_parameters_manage_search_filters ) %] + + [% END %] +
    @@ -712,6 +751,9 @@ [% Asset.js("js/browser.js") | $raw %] [% Asset.js("lib/hc-sticky.js") | $raw %] [% Asset.js("js/coce.js") | $raw %] + [% Asset.css("css/humanmsg.css") | $raw %] + [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %] + [% INCLUDE 'select2.inc' %] [% Asset.js("js/pages/results.js") | $raw %] [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-facets.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-facets.inc index 5e6e638c0b..af51f0b605 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-facets.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-facets.inc @@ -5,6 +5,23 @@

    Refine your search