From 0beef88f62a0b42b24e76d7785b3d4bd7d89dea4 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Thu, 29 May 2014 18:31:03 -0400 Subject: [PATCH] Bug 12330: OpacHiddenItems not affecting Advanced Search This patch affects only the area displayed on Advanced Search by setting the AdvancedSearchTypes OPAC system preference accordingly. Prior to this patch, no filtering based on OpacHiddenItems was done. This patch determines if itemtypes, collections, or shelving locations are hidden and prevents them from being shown. TEST PLAN --------- 1) Back up your DB (always handy) 2) Set the OPAC system preference AdvancedSearchTypes to: 'itemtypes|ccode|loc' (without the single quotes). 3) Set the OPAC system preference OpacHiddenItems to include the lines: itype: [{list of itemtype codes separated by commas}] location: [{list of comma delimited shelving location codes}] ccode: [{list of comma delimited collection codes}] Make sure to exclude one value for each, so there will be at least one known thing on each tab. 4) Open the OPAC. 5) Click on 'Advanced Search' -- three tabs appear: Itemtypes, Collection, Shelving location -- Everything is visible 6) Set the OPAC system preference AdvancedSearchTypes to: 'itemtypes | ccode | loc' (without the single quotes). 7) Refresh the OPAC. -- There will be three tabs, but ugliness ensues. 8) Apply the patch 9) Refresh the OPAC. -- You will see: Itemtypes, Collection, Shelving location -- Only excluded values from OpacHiddenItems will be seen. 10) Run koha qa test tools --- opac/opac-search.pl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 990cbd0..9c13c0a 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -28,6 +28,7 @@ use Modern::Perl; # to perform, etc. ## load Koha modules use C4::Context; +use List::MoreUtils q/any/; my $searchengine = C4::Context->preference("SearchEngine"); for ( $searchengine ) { @@ -213,11 +214,27 @@ my $cnt; my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes") || "itemtypes"; my @advanced_search_types = split(/\|/, $advanced_search_types); +my $hidingrules = {}; +my $yaml = C4::Context->preference('OpacHiddenItems'); +if ( $yaml =~ /\S/ ) { + $yaml = "$yaml\n\n"; # YAML is anal on ending \n. Surplus does not hurt + eval { + $hidingrules = YAML::Load($yaml); + }; + if ($@) { + warn "Unable to parse OpacHiddenItems syspref : $@"; + } +} + foreach my $advanced_srch_type (@advanced_search_types) { + $advanced_srch_type =~ s/^\s*//; + $advanced_srch_type =~ s/\s*$//; if ($advanced_srch_type eq 'itemtypes') { # itemtype is a special case, since it's not defined in authorized values my @itypesloop; foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) { + next if $hidingrules->{itype} && any { $_ eq $thisitemtype } @{$hidingrules->{itype}}; + next if $hidingrules->{itemtype} && any { $_ eq $thisitemtype } @{$hidingrules->{itemtype}}; my %row =( number=>$cnt++, ccl => "$itype_or_itemtype,phr", code => $thisitemtype, @@ -234,6 +251,9 @@ foreach my $advanced_srch_type (@advanced_search_types) { my $advsearchtypes = GetAuthorisedValues($advanced_srch_type, '', 'opac'); my @authvalueloop; for my $thisitemtype (@$advsearchtypes) { + my $hiding_key = lc $thisitemtype->{category}; + $hiding_key = "location" if $hiding_key eq 'loc'; + next if $hidingrules->{$hiding_key} && any { $_ eq $thisitemtype->{authorised_value} } @{$hidingrules->{$hiding_key}}; my %row =( number=>$cnt++, ccl => $advanced_srch_type, -- 1.7.9.5