@@ -, +, @@ --------- 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. --- opac/opac-search.pl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) --- a/opac/opac-search.pl +++ a/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, --