@@ -, +, @@ opac-MARCdetail.pl - Find a known record, go to the OPAC MARC page of it. - Play with several options in OpacHiddenItems, refreshing it - Play with OpacHiddenItemsExceptions as well - Apply this patch - Repeate the tests above - Sign off :-D --- opac/opac-MARCdetail.pl | 46 ++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 26 deletions(-) --- a/opac/opac-MARCdetail.pl +++ a/opac/opac-MARCdetail.pl @@ -59,7 +59,6 @@ use C4::Koha; use List::MoreUtils qw( any uniq ); use Koha::Biblios; use Koha::CirculationRules; -use Koha::Items; use Koha::ItemTypes; use Koha::Patrons; use Koha::RecordProcessor; @@ -85,39 +84,34 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -my $patron = Koha::Patrons->find( $loggedinuser ); -my $borcat = q{}; -if ( C4::Context->preference('OpacHiddenItemsExceptions') ) { - # we need to fetch the borrower info here, so we can pass the category - $borcat = $patron ? $patron->categorycode : $borcat; -} +my $biblio = Koha::Biblios->find( $biblionumber, { prefetch => [ 'metadata', 'items' ] } ); -my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1, - opac => 1, - borcat => $borcat }); -if ( ! $record ) { +unless ( $biblio ) { print $query->redirect("/cgi-bin/koha/errors/404.pl"); 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 (scalar @all_items >= 1 && scalar @nonhiddenitems == 0) { - print $query->redirect("/cgi-bin/koha/errors/404.pl"); - exit; +my $patron = Koha::Patrons->find( $loggedinuser ); + +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 ( $biblio->hidden_in_opac({ rules => $opachiddenitems_rules }) ) { + print $query->redirect('/cgi-bin/koha/errors/404.pl'); # escape early + exit; + } } +my $record = $biblio->metadata->record; +my $marcflavour = C4::Context->preference("marcflavour"); + my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy', options => { interface => 'opac', - frameworkcode => $framework + frameworkcode => $biblio->frameworkcode } }); $record_processor->process($record); @@ -130,6 +124,7 @@ if(my $cart_list = $query->cookie("bib_list")){ } } +my $tagslib = &GetMarcStructure( 0, $biblio->frameworkcode ); my ($bt_tag,$bt_subtag) = GetMarcFromKohaField( 'biblio.title' ); $template->param( bibliotitle => $biblio->title, @@ -137,8 +132,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; } @@ -341,7 +336,6 @@ if ( C4::Context->preference("OPACISBD") ) { } #Search for title in links -my $marcflavour = C4::Context->preference("marcflavour"); my $dat = TransformMarcToKoha( $record ); my $isbn = GetNormalizedISBN(undef,$record,$marcflavour); my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour); --