From fb811af0ed67a9991ef7276139ab5ab29c8e709d Mon Sep 17 00:00:00 2001 From: Baptiste Wojtkowski Date: Mon, 8 Dec 2025 15:32:35 +0000 Subject: [PATCH] Bug 41402: Do not hide all items if there is a pref OpacMaxItemsToDisplay Test plan: 1. Set OpacMaxItemsToDisplay to 3. 2. Add multiple items on a record. 3. Visit http://koha-ktd:8080/cgi-bin/koha/opac-detail.pl?biblionumber=YOUR_BIBLIONUMBER, notice every items are hidden. 4. Apply patch 5. Visit the same page, notice that the 3 first items are displayed Signed-off-by: David Nind --- .../bootstrap/en/modules/opac-detail.tt | 8 +- opac/opac-detail.pl | 172 +++++++++--------- 2 files changed, 93 insertions(+), 87 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt index 0c85fbb735..89d522e9ab 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -595,8 +595,12 @@ [% WRAPPER tab_panel tabname="holdings" %] [% IF too_many_items %] -

This record has many physical items ([% items_count | html %]). View all the physical items.

- [% ELSIF ( itemloop.size ) %] +

This record has many physical items ([% items_count | html %]), some of them are hidden. + View all the physical items.

+ [% END %] + [% IF ( itemloop.size ) %] [% INCLUDE items_table items=itemloop tab="holdings" table_id="holdingst" %] [% IF specific_item %]

Show all items

diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 211dac36ea..3875296dd6 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -698,103 +698,105 @@ my $can_holds_be_placed = $patron ? 0 : $holdable_items; my ( $itemloop_has_images, $otheritemloop_has_images ); my $item_level_holds; my $item_checkouts; -if ( not $viewallitems and $items->count > $max_items_to_display ) { - $template->param( - too_many_items => 1, - items_count => $items->count, - ); -} else { - my $library_info; - while ( my $item = $items->next ) { - my $item_info = $item->unblessed; - $item_info->{holds_count} = $item_reserves{ $item->itemnumber }; - if ( $item_info->{holds_count} && $item_info->{holds_count} > 0 ) { $item_level_holds = 1; } - $item_info->{priority} = $priority{ $item->itemnumber }; - - # Get opac_info from Additional contents for home and holding library - my ( $opac_info_home, $opac_info_holding ); - $opac_info_holding = $library_info->{ $item->holdingbranch } - // $item->holding_branch->opac_info( { lang => $lang } ); - $library_info->{ $item->holdingbranch } = $opac_info_holding; - $opac_info_home = $library_info->{ $item->homebranch } // $item->home_branch->opac_info( { lang => $lang } ); - $library_info->{ $item->homebranch } = $opac_info_home; - $item_info->{holding_library_info} = $opac_info_holding->content if $opac_info_holding; - $item_info->{home_library_info} = $opac_info_home->content if $opac_info_home; - - # We only need to check if we haven't determined holds can be placed - # and if we don't have patron, we have already decided - $can_holds_be_placed = - $can_holds_be_placed || $patron && IsAvailableForItemLevelRequest( $item, $patron, undef ); - - # get collection code description, too - my $ccode = $item->ccode; - $item_info->{'ccode'} = $collections->{$ccode} - if defined($ccode) - && $collections - && exists( $collections->{$ccode} ); - - my $copynumber = $item->copynumber; - $item_info->{copynumber} = $copynumbers->{$copynumber} - if ( defined($copynumbers) - && defined($copynumber) - && exists( $copynumbers->{$copynumber} ) ); - - if ( defined $item->location ) { - $item_info->{'location_description'} = $shelflocations->{ $item->location }; - } - - my $itemtype = $item->itemtype; - $item_info->{'imageurl'} = getitemtypeimagelocation( - 'opac', - $itemtypes->{ $itemtype->itemtype }->{'imageurl'} +my $library_info; +my $nb_items_processed = 0; +while ( my $item = $items->next ) { + if ( not $viewallitems and $nb_items_processed >= $max_items_to_display ) { + $template->param( + too_many_items => 1, + items_count => $items->count, ); - $item_info->{'description'} = - $itemtypes->{ $itemtype->itemtype }->{translated_description}; + last; + } + $nb_items_processed = $nb_items_processed + 1; + + my $item_info = $item->unblessed; + $item_info->{holds_count} = $item_reserves{ $item->itemnumber }; + if ( $item_info->{holds_count} && $item_info->{holds_count} > 0 ) { $item_level_holds = 1; } + $item_info->{priority} = $priority{ $item->itemnumber }; + + # Get opac_info from Additional contents for home and holding library + my ( $opac_info_home, $opac_info_holding ); + $opac_info_holding = $library_info->{ $item->holdingbranch } + // $item->holding_branch->opac_info( { lang => $lang } ); + $library_info->{ $item->holdingbranch } = $opac_info_holding; + $opac_info_home = $library_info->{ $item->homebranch } // $item->home_branch->opac_info( { lang => $lang } ); + $library_info->{ $item->homebranch } = $opac_info_home; + $item_info->{holding_library_info} = $opac_info_holding->content if $opac_info_holding; + $item_info->{home_library_info} = $opac_info_home->content if $opac_info_home; + + # We only need to check if we haven't determined holds can be placed + # and if we don't have patron, we have already decided + $can_holds_be_placed = $can_holds_be_placed || $patron && IsAvailableForItemLevelRequest( $item, $patron, undef ); + + # get collection code description, too + my $ccode = $item->ccode; + $item_info->{'ccode'} = $collections->{$ccode} + if defined($ccode) + && $collections + && exists( $collections->{$ccode} ); + + my $copynumber = $item->copynumber; + $item_info->{copynumber} = $copynumbers->{$copynumber} + if ( defined($copynumbers) + && defined($copynumber) + && exists( $copynumbers->{$copynumber} ) ); + + if ( defined $item->location ) { + $item_info->{'location_description'} = $shelflocations->{ $item->location }; + } - $item_info->{checkout} = $item->checkout; - if ( $item_info->{checkout} && $item_info->{checkout} > 0 ) { $item_checkouts = 1; } + my $itemtype = $item->itemtype; + $item_info->{'imageurl'} = getitemtypeimagelocation( + 'opac', + $itemtypes->{ $itemtype->itemtype }->{'imageurl'} + ); + $item_info->{'description'} = + $itemtypes->{ $itemtype->itemtype }->{translated_description}; - foreach my $field ( - qw(ccode materials enumchron copynumber itemnotes location_description uri barcode itemcallnumber)) - { - $itemfields{$field} = 1 if $item_info->{$field}; - } + $item_info->{checkout} = $item->checkout; + if ( $item_info->{checkout} && $item_info->{checkout} > 0 ) { $item_checkouts = 1; } - # FIXME The following must be Koha::Item->serial - my $serial_item = Koha::Serial::Items->find( $item->itemnumber ); - if ($serial_item) { - my $serial = Koha::Serials->find( $serial_item->serialid ); - $item_info->{serial} = $serial if $serial; - } + foreach + my $field (qw(ccode materials enumchron copynumber itemnotes location_description uri barcode itemcallnumber)) + { + $itemfields{$field} = 1 if $item_info->{$field}; + } - $item_info->{object} = $item; + # FIXME The following must be Koha::Item->serial + my $serial_item = Koha::Serial::Items->find( $item->itemnumber ); + if ($serial_item) { + my $serial = Koha::Serials->find( $serial_item->serialid ); + $item_info->{serial} = $serial if $serial; + } - if ( C4::Context->preference("OPACLocalCoverImages") == 1 ) { - $item_info->{cover_images} = $item->cover_images; - } + $item_info->{object} = $item; - if ( C4::Context->preference('UseCourseReserves') ) { - $item_info->{course_reserves} = GetItemCourseReservesInfo( itemnumber => $item->itemnumber ); - } + if ( C4::Context->preference("OPACLocalCoverImages") == 1 ) { + $item_info->{cover_images} = $item->cover_images; + } - $item_info->{holding_branch} = $item->holding_branch; - $item_info->{home_branch} = $item->home_branch; + if ( C4::Context->preference('UseCourseReserves') ) { + $item_info->{course_reserves} = GetItemCourseReservesInfo( itemnumber => $item->itemnumber ); + } - my $itembranch = $item->$separatebranch; - if ( $currentbranch - and C4::Context->preference('OpacSeparateHoldings') ) - { - if ( $itembranch and $itembranch eq $currentbranch ) { - push @itemloop, $item_info; - $itemloop_has_images++ if $item->cover_images->count; - } else { - push @otheritemloop, $item_info; - $otheritemloop_has_images++ if $item->cover_images->count; - } - } else { + $item_info->{holding_branch} = $item->holding_branch; + $item_info->{home_branch} = $item->home_branch; + + my $itembranch = $item->$separatebranch; + if ( $currentbranch + and C4::Context->preference('OpacSeparateHoldings') ) + { + if ( $itembranch and $itembranch eq $currentbranch ) { push @itemloop, $item_info; $itemloop_has_images++ if $item->cover_images->count; + } else { + push @otheritemloop, $item_info; + $otheritemloop_has_images++ if $item->cover_images->count; } + } else { + push @itemloop, $item_info; + $itemloop_has_images++ if $item->cover_images->count; } } -- 2.39.5