From 8de3d9a95f2f3a01b5ed309805d81c698ac8e550 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 23 Apr 2021 16:55:35 -0300 Subject: [PATCH] Bug 18989: (QA follow-up) Make controllers use Koha::Biblio->hidden_in_opac Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- opac/opac-ISBDdetail.pl | 2 +- opac/opac-MARCdetail.pl | 22 ++++++++++++---------- opac/opac-basket.pl | 5 ++++- opac/opac-detail.pl | 19 +++++++------------ opac/opac-tags.pl | 13 ++++++++++--- 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index e4b54f068d..d1076e76ef 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -84,7 +84,7 @@ my $opachiddenitems_rules = C4::Context->yaml_preference('OpacHiddenItems'); 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 ( C4::Context->preference('OpacHiddenItemsHidesRecord') && $biblio->hidden_in_opac({ rules => $opachiddenitems_rules }) ) { + if ( $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 3211f61df3..4362270959 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -102,17 +102,19 @@ if ( ! $record ) { exit; } -my @all_items = GetItemsInfo($biblionumber); my $biblio = Koha::Biblios->find( $biblionumber ); -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 ( C4::Context->preference('OpacHiddenItemsHidesRecord') && scalar @all_items >= 1 && scalar @nonhiddenitems == 0 ) { - print $query->redirect("/cgi-bin/koha/errors/404.pl"); - exit; +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 => C4::Context->yaml_preference('OpacHiddenItems') }) ) { + print $query->redirect('/cgi-bin/koha/errors/404.pl'); # escape early + exit; + } } +my $framework = $biblio ? $biblio->frameworkcode : q{}; +my $tagslib = &GetMarcStructure( 0, $framework ); + my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy', options => { @@ -137,8 +139,8 @@ $template->param( $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} > -8; # except -8; my $allow_onshelf_holds; -for my $itm (@all_items) { - my $item = Koha::Items->find( $itm->{itemnumber} ); +my $items = $biblio->items; +while ( my $item = $items->next ) { $allow_onshelf_holds = Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => $patron } ); last if $allow_onshelf_holds; } diff --git a/opac/opac-basket.pl b/opac/opac-basket.pl index cc3d975355..2de55f4be6 100755 --- a/opac/opac-basket.pl +++ b/opac/opac-basket.pl @@ -66,6 +66,8 @@ if ( C4::Context->preference('OpacHiddenItemsExceptions') ) { } my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' }); +my $rules = C4::Context->yaml_preference('OpacHiddenItems'); + foreach my $biblionumber ( @bibs ) { $template->param( biblionumber => $biblionumber ); @@ -96,7 +98,8 @@ 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 ( C4::Context->preference('OpacHiddenItemsHidesRecord') && scalar @all_items >= 1 && scalar @hidden_items == scalar @all_items); + next + if $biblio->hidden_in_opac({ rules => $rules }); # copy the visible ones into the items array. my @items; diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 26d3ef0151..e2ea7e709e 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -89,10 +89,6 @@ if( $specific_item ) { } my @hiddenitems; my $patron = Koha::Patrons->find( $borrowernumber ); -our $borcat= q{}; -if ( C4::Context->preference('OpacHiddenItemsExceptions') ) { - $borcat = $patron ? $patron->categorycode : q{}; -} my $record = GetMarcBiblio({ biblionumber => $biblionumber, @@ -102,17 +98,16 @@ if ( ! $record ) { exit; } -if ( scalar @all_items >= 1 ) { - push @hiddenitems, - GetHiddenItemnumbers( { items => \@all_items, borcat => $borcat } ); - - if ( C4::Context->preference('OpacHiddenItemsHidesRecord') && scalar @hiddenitems == scalar @all_items ) { - print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early +my $biblio = Koha::Biblios->find( $biblionumber ); +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 => C4::Context->yaml_preference('OpacHiddenItems') }) ) { + print $query->redirect('/cgi-bin/koha/errors/404.pl'); # escape early exit; } } -my $biblio = Koha::Biblios->find( $biblionumber ); my $framework = $biblio ? $biblio->frameworkcode : q{}; my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy', @@ -280,7 +275,7 @@ if ($session->param('busc')) { my @newresults; my $search_context = { 'interface' => 'opac', - 'category' => $borcat + 'category' => ($patron) ? $patron->categorycode : q{} }; for (my $i=0;$i<@servers;$i++) { my $server = $servers[$i]; diff --git a/opac/opac-tags.pl b/opac/opac-tags.pl index 1f15149cb2..05a4c1a74a 100755 --- a/opac/opac-tags.pl +++ b/opac/opac-tags.pl @@ -233,8 +233,8 @@ my $borcat = q{}; if ($loggedinuser) { my $patron = Koha::Patrons->find( { borrowernumber => $loggedinuser } ); $borcat = $patron ? $patron->categorycode : $borcat; - my $should_hide = C4::Context->preference('OpacHiddenItems') // q{}; - $should_hide = ( $should_hide =~ /\S/ ) ? 1 : 0; + my $rules = C4::Context->yaml_preference('OpacHiddenItems'); + my $should_hide = ( $rules ) ? 1 : 0; $my_tags = get_tag_rows({borrowernumber=>$loggedinuser}); my $my_approved_tags = get_approval_rows({ approved => 1 }); @@ -270,7 +270,14 @@ if ($loggedinuser) { borcat => $borcat }); $hidden_items = \@hidden_itemnumbers; } - next if ( C4::Context->preference('OpacHiddenItemsHidesRecord') && $should_hide && scalar @all_items == scalar @hidden_itemnumbers ); + next + if ( + ( + !$patron + or ( $patron and !$patron->category->override_hidden_items ) + ) + and $biblio->hidden_in_opac( { rules => $rules } ) + ); $tag->{title} = $biblio->title; $tag->{subtitle} = $biblio->subtitle; $tag->{medium} = $biblio->medium; -- 2.39.5