From 3b81402f2c0524eef428c9ce0be70d0cb6a2279e Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Fri, 4 Sep 2020 14:33:12 +0200 Subject: [PATCH] Bug 18989: Allow displaying biblios with all items hidden by OpacHiddenItems Bug 10584 made Koha hide biblios for which all items match some criteria (in OpacHiddenItems) so they are hidden. Add syspref OpacHiddenItemsHidesRecord controlling this behaviour. Test plan : 1) 1.1) Create some biblio records with one item having damaged=1 1.2) Define system preference OpacHiddenItems = damaged: 1 2) 2.1) Set system preference OpacHiddenItemsHidesRecord to 'don't hide' 2.2) At OPAC : perform a search showing those records and some more 2.3) Check you see the all the records 2.4) For a record with hidden item check you don't get HTTP 404 for : normal view, ISBD view, MARC view 2.5) Check you can had tags on this record 2.6) Add record to basket, check you see it in basket 3) 3.1) Set system preference OpacHiddenItemsHidesRecord to 'hide' 3.2) At OPAC : perform a search showing those records and some more 3.3) Check you don't see the records with hidden item 3.4) For a record with hidden item check you get HTTP 404 for : normal view, ISBD view, MARC view 3.5) Show basket, check you see the records with hidden item --- C4/Search.pm | 2 +- installer/data/mysql/sysprefs.sql | 1 + .../prog/en/modules/admin/preferences/opac.pref | 7 +++++++ opac/opac-ISBDdetail.pl | 2 +- opac/opac-MARCdetail.pl | 2 +- opac/opac-basket.pl | 2 +- opac/opac-detail.pl | 2 +- opac/opac-tags.pl | 2 +- 8 files changed, 14 insertions(+), 6 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 5509a5b4cb..278b8ab93d 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -2065,7 +2065,7 @@ sub searchResults { } # notforloan, item level and biblioitem level # if all items are hidden, do not show the record - if ($items_count > 0 && $hideatopac_count == $items_count) { + if ( C4::Context->preference('OpacHiddenItemsHidesRecord') && $items_count > 0 && $hideatopac_count == $items_count) { next; } diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 91f17b5a95..16df2851d3 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -395,6 +395,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('OPACFRBRizeEditions','0','','If ON, the OPAC will query one or more ISBN web services for associated ISBNs and display an Editions tab on the details pages','YesNo'), ('OpacHiddenItems','','','This syspref allows to define custom rules for hiding specific items at the OPAC. See http://wiki.koha-community.org/wiki/OpacHiddenItems for more information.','Textarea'), ('OpacHiddenItemsExceptions','',NULL,'List of borrower categories, separated by |, that can see items otherwise hidden by OpacHiddenItems','Textarea'), +('OpacHiddenItemsHidesRecord','1','','Hide biblio record when all its items are hidden because of OpacHiddenItems','YesNo'), ('OpacHighlightedWords','1','','If Set, then queried words are higlighted in OPAC','YesNo'), ('OPACHoldingsDefaultSortField','first_column','first_column|homebranch|holdingbranch','Default sort field for the holdings table at the OPAC','choice'), ('OPACHoldsIfAvailableAtPickup','1','','Allow to pickup up holds at libraries where the item is available','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index e078692ff6..bbb0b3e2f6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -638,6 +638,13 @@ OPAC: - - "List of patron categories, separated by |, that can see items otherwise hidden by OpacHiddenItems:" - pref: OpacHiddenItemsExceptions + - + - pref: OpacHiddenItemsHidesRecord + default: 1 + choices: + no: "Don't hide" + yes: Hide + - "biblio record when all its items are hidden by OpacHiddenItems." - - pref: OpacAllowPublicListCreation default: 1 diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index cc4b5b8d1a..8b744ce017 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -88,7 +88,7 @@ eval { unless ( $patron and $patron->category->override_hidden_items ) { # only skip this check if there's a logged in user # and its category overrides OpacHiddenItems - if ( $biblio->hidden_in_opac({ rules => $opachiddenitems_rules }) ) { + if ( C4::Context->preference('OpacHiddenItemsHidesRecord') && $biblio->hidden_in_opac({ rules => $opachiddenitems_rules }) ) { print $query->redirect('/cgi-bin/koha/errors/404.pl'); # escape early exit; } diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index 39cb10eecf..3211f61df3 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -108,7 +108,7 @@ my $framework = $biblio ? $biblio->frameworkcode : q{}; my $tagslib = &GetMarcStructure( 0, $framework ); my ($tag_itemnumber,$subtag_itemnumber) = &GetMarcFromKohaField( 'items.itemnumber' ); my @nonhiddenitems = $record->field($tag_itemnumber); -if (scalar @all_items >= 1 && scalar @nonhiddenitems == 0) { +if ( C4::Context->preference('OpacHiddenItemsHidesRecord') && scalar @all_items >= 1 && scalar @nonhiddenitems == 0 ) { print $query->redirect("/cgi-bin/koha/errors/404.pl"); exit; } diff --git a/opac/opac-basket.pl b/opac/opac-basket.pl index 1713de4993..81705c5fbb 100755 --- a/opac/opac-basket.pl +++ b/opac/opac-basket.pl @@ -94,7 +94,7 @@ foreach my $biblionumber ( @bibs ) { my @hidden_items = GetHiddenItemnumbers({ items => \@all_items, borcat => $borcat }); # If every item is hidden, then the biblio should be hidden too. - next if (scalar @all_items >= 1 && scalar @hidden_items == scalar @all_items); + next if ( C4::Context->preference('OpacHiddenItemsHidesRecord') && scalar @all_items >= 1 && scalar @hidden_items == scalar @all_items); # copy the visible ones into the items array. my @items; diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 8d4723e338..cbc9dc2b7c 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -107,7 +107,7 @@ if ( scalar @all_items >= 1 ) { push @hiddenitems, GetHiddenItemnumbers( { items => \@all_items, borcat => $borcat } ); - if (scalar @hiddenitems == scalar @all_items ) { + if ( C4::Context->preference('OpacHiddenItemsHidesRecord') && scalar @hiddenitems == scalar @all_items ) { print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early exit; } diff --git a/opac/opac-tags.pl b/opac/opac-tags.pl index be3c3d5886..1f15149cb2 100755 --- a/opac/opac-tags.pl +++ b/opac/opac-tags.pl @@ -270,7 +270,7 @@ if ($loggedinuser) { borcat => $borcat }); $hidden_items = \@hidden_itemnumbers; } - next if ( $should_hide && scalar @all_items == scalar @hidden_itemnumbers ); + next if ( C4::Context->preference('OpacHiddenItemsHidesRecord') && $should_hide && scalar @all_items == scalar @hidden_itemnumbers ); $tag->{title} = $biblio->title; $tag->{subtitle} = $biblio->subtitle; $tag->{medium} = $biblio->medium; -- 2.27.0