From c2c2269d5d762fdeb09ea78db35e8820511d0c01 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 10 May 2021 10:01:02 +0200 Subject: [PATCH] Bug 28299: Make buildKohaItemsNamespace accept Koha::Items --- C4/XSLT.pm | 25 ++++++++++++++++--------- opac/opac-shelves.pl | 15 +++++---------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/C4/XSLT.pm b/C4/XSLT.pm index d4cdb832cdc..5aa0f7ce147 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -297,14 +297,21 @@ Is only used in this module currently. sub buildKohaItemsNamespace { my ($biblionumber, $hidden_items) = @_; - $hidden_items ||= []; - my @items = Koha::Items->search( - { - 'me.biblionumber' => $biblionumber, - 'me.itemnumber' => { not_in => $hidden_items } - }, - { prefetch => [ 'branchtransfers', 'reserves' ] } - ); + if ( ref $hidden_items eq 'Koha::Items' ) { + $items = $items->search( + {}, + { prefetch => [ 'branchtransfers', 'reserves' ] } + ); + } else { + $hidden_items ||= []; + + $items = Koha::Items->search( + { + 'me.biblionumber' => $biblionumber, + 'me.itemnumber' => { not_in => $hidden_items } + { prefetch => [ 'branchtransfers', 'reserves' ] } + ); + } my $shelflocations = { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => "", kohafield => 'items.location' } ) }; @@ -318,7 +325,7 @@ sub buildKohaItemsNamespace { my %descs = map { $_->{authorised_value} => $_ } Koha::AuthorisedValues->get_descriptions_by_koha_field( { kohafield => 'items.notforloan' } ); my $ref_status = C4::Context->preference('Reference_NFL_Statuses') || '1|2'; - for my $item (@items) { + while ( my $item = $items->next ) { my $status; my $substatus = ''; diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index 2d9d5613d9a..d1783ca649c 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -346,23 +346,18 @@ if ( $op eq 'view' ) { }); } - my @items; - my $items = $biblio->items; + my $items = $biblio->items->filter_by_visible_in_opac({ patron => $patron }); my $allow_onshelf_holds; - my @hidden_items; while ( my $item = $items->next ) { - if ( $item->hidden_in_opac({rules => C4::Context->yaml_preference('OpacHiddenItems')} ) ) { - push @hidden_items, $item->itemnumber; - next; - } + # This method must take a Koha::Items rs $allow_onshelf_holds ||= Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => $patron } ); - push @items, $item; # This is for non-xslt only } + $this_item->{allow_onshelf_holds} = $allow_onshelf_holds; - $this_item->{'ITEM_RESULTS'} = \@items; + $this_item->{'ITEM_RESULTS'} = $items; if ($xslfile) { my $variables = { @@ -371,7 +366,7 @@ if ( $op eq 'view' ) { $this_item->{XSLTBloc} = XSLTParse4Display( $biblionumber, $record, "OPACXSLTListsDisplay", 1, - \@hidden_items, $sysxml, + $items, $sysxml, $xslfile, $lang, $variables ); -- 2.20.1