From 4d8ff723d53abe8c95e18d5034d4c727b0dbfb3e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 7 May 2021 11:16:17 +0200 Subject: [PATCH] Bug 28299: Take OpacHiddenItems into account on opac-shelves MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit hidden_items was not passed to XSLTParse4Display 2 things: * Should we hide the biblio record if OpacHiddenItemsHidesRecord is set? * allow_onshelf_holds is not working like in other scripts, what's the expected behaviour? If hidden should we completely ignore the item? Test plan: 1. Without the patch 2. fill OpacHiddenItems with «damaged: [1]» 3. find a record with several item 4. mark one of them as damaged 5. OPAC: go to the record, you shouldn't see the damaged item 6. add the record to a list 7. see the list 8. in Availability you see the damaged item mentioned, this is the issue 9. apply the patches and restart the services 10. the list should not mention the damaged item :D Signed-off-by: Victor Grousset/tuxayo Signed-off-by: David Nind Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- .../bootstrap/en/modules/opac-shelves.tt | 15 +++--- opac/opac-shelves.pl | 52 +++++++++++-------- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt index 9c1e19047d..9b08b0d208 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt @@ -524,14 +524,15 @@ Holdings: - [% IF ( itemsloo.ITEM_RESULTS ) %] - [% FOREACH ITEM_RESULT IN itemsloo.ITEM_RESULTS %] - [% ITEM_RESULT.homebranch | html %] - [% IF ( ITEM_RESULT.location_opac ) %] - [% ITEM_RESULT.location_opac | html %] + [% IF itemsloo.ITEM_RESULTS %] + [% FOREACH item IN itemsloo.ITEM_RESULTS %] + [% item.homebranch | html %] + [% SET location_opac = AuthorisedValues.GetByCode( 'LOC', item.location, 1 ) %] + [% IF location_opac %] + [% location_opac | html %] [% END %] - [% IF ( ITEM_RESULT.itemcallnumber ) %] - ([% ITEM_RESULT.itemcallnumber | html %]) + [% IF item.itemcallnumber %] + ([% item.itemcallnumber | html %]) [% IF ( loop.last ) %].[% ELSE %],[% END %] [% END %] [% END %] diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index 0ec193c9ec..8fe037bd31 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -306,7 +306,7 @@ if ( $op eq 'view' ) { $art_req_itypes = Koha::CirculationRules->guess_article_requestable_itemtypes({ $patron ? ( categorycode => $patron->categorycode ) : () }); } - my @items; + my @items_info; while ( my $content = $contents->next ) { my $biblionumber = $content->biblionumber; my $this_item = GetBiblioData($biblionumber); @@ -319,19 +319,6 @@ if ( $op eq 'view' ) { }); $record_processor->process($record); - if ($xslfile) { - my $variables = { - anonymous_session => ($loggedinuser) ? 0 : 1 - }; - $this_item->{XSLTBloc} = XSLTParse4Display( - $biblionumber, $record, - "OPACXSLTListsDisplay", 1, - undef, $sysxml, - $xslfile, $lang, - $variables - ); - } - my $marcflavour = C4::Context->preference("marcflavour"); my $itemtype = Koha::Biblioitems->search({ biblionumber => $content->biblionumber })->next->itemtype; $itemtype = Koha::ItemTypes->find( $itemtype ); @@ -354,10 +341,6 @@ if ( $op eq 'view' ) { $this_item->{size} = q||; } - # Getting items infos for location display - my @items_infos = &GetItemsLocationInfo( $biblionumber ); - $this_item->{'ITEM_RESULTS'} = \@items_infos; - if (C4::Context->preference('TagsEnabled') and C4::Context->preference('TagsShowOnList')) { $this_item->{TagLoop} = get_tags({ biblionumber => $biblionumber, approved=>1, 'sort'=>'-weight', @@ -365,10 +348,35 @@ if ( $op eq 'view' ) { }); } + my @items; my $items = $biblio->items; + my $allow_onshelf_holds; + my @hidden_items; while ( my $item = $items->next ) { - $this_item->{allow_onshelf_holds} = Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => $patron } ); - last if $this_item->{allow_onshelf_holds}; + if ( $item->hidden_in_opac({rules => C4::Context->yaml_preference('OpacHiddenItems')} ) ) { + push @hidden_items, $item->itemnumber; + next; + } + + $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; + + if ($xslfile) { + my $variables = { + anonymous_session => ($loggedinuser) ? 0 : 1 + }; + $this_item->{XSLTBloc} = XSLTParse4Display( + $biblionumber, $record, + "OPACXSLTListsDisplay", 1, + \@hidden_items, $sysxml, + $xslfile, $lang, + $variables + ); } if ( grep {$_ eq $biblionumber} @cart_list) { @@ -377,7 +385,7 @@ if ( $op eq 'view' ) { $this_item->{biblio_object} = $biblio; $this_item->{biblionumber} = $biblionumber; - push @items, $this_item; + push @items_info, $this_item; } $template->param( @@ -385,7 +393,7 @@ if ( $op eq 'view' ) { can_delete_shelf => $shelf->can_be_deleted($loggedinuser), can_remove_biblios => $shelf->can_biblios_be_removed($loggedinuser), can_add_biblios => $shelf->can_biblios_be_added($loggedinuser), - itemsloop => \@items, + itemsloop => \@items_info, sortfield => $sortfield, direction => $direction, csv_profiles => [ -- 2.39.5