From 7559cc56042c43f4a8dd66adf693f6ebec42ac58 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 Content-Type: text/plain; charset=utf-8 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 Searching 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 Searching 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 Signed-off-by: Nicole C. Engard All tests pass Signed-off-by: Marcel de Rooy Small rewording in comment only. --- opac/opac-search.pl | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-) diff --git a/opac/opac-search.pl b/opac/opac-search.pl index cc6beb7..2360b88 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"); if ( $searchengine =~ /^Solr$/ ) { @@ -210,11 +211,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 expects trailing newline. 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, @@ -231,6 +248,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.7.6