From 986cbaf830923ce75d396e1a2d87ae8f029f4be9 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 1 Oct 2015 15:13:20 +0200 Subject: [PATCH] Bug 11139: Add support for multiple values in AdvancedSearchTypes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit AdvancedSearchTypes syspref can be multivalued, opac-topissues.pl have to support that. AdvancedSearchTypes can have one or more of the following values: 'itemtypes', 'ccode', 'loc'. But this patch adds support only for itemtypes and ccode. AdvancedSearchTypes can still contain 'loc' but it will change nothing to the behaviour of opac-topissues.pl. This patch also removes duplicate code in template (the "Refine your search" form was written in two different places) This introduces a small behaviour change: when there is no results, instead of having the form in the center of the page, it remains in the left sidebar and we have a "No results" message in the main area. Depends on bug 14788 Tested on top of 14788. Works as expected. Signed-off-by: Marc Véron Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- Koha/Template/Plugin/ItemTypes.pm | 6 ++ .../bootstrap/en/includes/opac-topissues.inc | 49 +++++++---- .../bootstrap/en/modules/opac-topissues.tt | 81 ++----------------- opac/opac-topissues.pl | 61 ++++---------- 4 files changed, 65 insertions(+), 132 deletions(-) diff --git a/Koha/Template/Plugin/ItemTypes.pm b/Koha/Template/Plugin/ItemTypes.pm index 800e151be5..91e8c4e169 100644 --- a/Koha/Template/Plugin/ItemTypes.pm +++ b/Koha/Template/Plugin/ItemTypes.pm @@ -35,4 +35,10 @@ sub GetDescription { } +sub Get { + my @itemtypes = @{ GetItemTypes(style => 'array') }; + @itemtypes = sort { $a->{description} cmp $b->{description} } @itemtypes; + return \@itemtypes; +} + 1; diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-topissues.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-topissues.inc index 4d6ca89430..0a211d53fb 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-topissues.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-topissues.inc @@ -1,3 +1,5 @@ +[% USE Koha %] +

Refine your search

@@ -27,23 +29,42 @@ [% END %] -
  • - + + [% FOREACH itemtype IN ItemTypes.Get() %] + [% IF itemtype.itemtype == selected_itemtype %] + + + [% itemtype.description %] + + [% END %] + +
  • + [% END %] + + [% IF AdvancedSearchTypes.grep('^ccode$').size %] +
  • + +
  • + [% ccode.lib %] + + [% END %] + + + [% END %]
  • - [% IF ( limit == 10 ) %][% ELSE %][% END %] - [% IF ( limit == 15 ) %][% ELSE %][% END %] - [% IF ( limit == 20 ) %][% ELSE %][% END %] - [% IF ( limit == 30 ) %][% ELSE %][% END %] - [% IF ( limit == 40 ) %][% ELSE %][% END %] - [% IF ( limit == 50 ) %][% ELSE %][% END %] - [% IF ( limit == 100 ) %][% ELSE %][% END %] - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • - - - -
    - -
    -
    - [% END # / IF results %] + No results, try to change filters. + [% END # / IF results %]
    diff --git a/opac/opac-topissues.pl b/opac/opac-topissues.pl index 772ec0354c..8e4e6db51a 100755 --- a/opac/opac-topissues.pl +++ b/opac/opac-topissues.pl @@ -73,7 +73,7 @@ if (!$do_it && C4::Context->userenv && C4::Context->userenv->{'branch'} ) { my $itemtype = $input->param('itemtype') || ''; my $timeLimit = $input->param('timeLimit') || 3; my $advanced_search_types = C4::Context->preference('AdvancedSearchTypes'); - +my @advanced_search_types = split /\|/, $advanced_search_types; my $params = { count => $limit, @@ -81,53 +81,24 @@ my $params = { newness => $timeLimit < 999 ? $timeLimit * 30 : undef, }; -if($advanced_search_types eq 'ccode'){ - $params->{ccode} = $itemtype; - $template->param(ccodesearch => 1); -} else { - $params->{itemtype} = $itemtype; - $template->param(itemtypesearch => 1); +@advanced_search_types = grep /^(ccode|itemtypes)$/, @advanced_search_types; +foreach my $type (@advanced_search_types) { + if ($type eq 'itemtypes') { + $type = 'itemtype'; + } + $params->{$type} = $input->param($type); + $template->param('selected_' . $type => $input->param($type)); } my @results = GetTopIssues($params); -$template->param(do_it => 1, - limit => $limit, - branch => $branches->{$branch}->{branchname}, - itemtype => $itemtypes->{$itemtype}->{description}, - timeLimit => $timeLimit, - results => \@results, - ); - -$template->param( branchloop => GetBranchesLoop($branch)); - -# the index parameter is different for item-level itemtypes -my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype'; -$itemtypes = GetItemTypes; -my @itemtypesloop; -if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') { - foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) { - my %row =( value => $thisitemtype, - description => $itemtypes->{$thisitemtype}->{'description'}, - selected => $thisitemtype eq $itemtype, - ); - push @itemtypesloop, \%row; - } -} else { - my $advsearchtypes = GetAuthorisedValues($advanced_search_types, '', 'opac'); - for my $thisitemtype (@$advsearchtypes) { - my $selected; - $selected = 1 if $thisitemtype->{authorised_value} eq $itemtype; - my %row =( value => $thisitemtype->{authorised_value}, - selected => $thisitemtype eq $itemtype, - description => $thisitemtype->{'lib'}, - ); - push @itemtypesloop, \%row; - } -} - $template->param( - itemtypeloop =>\@itemtypesloop, - ); -output_html_with_http_headers $input, $cookie, $template->output; + limit => $limit, + branch => $branches->{$branch}->{branchname}, + timeLimit => $timeLimit, + results => \@results, +); +$template->param(branchloop => GetBranchesLoop($branch)); + +output_html_with_http_headers $input, $cookie, $template->output; -- 2.39.5