From 9f268cc276c849e56eae7b3110032615451191b7 Mon Sep 17 00:00:00 2001 From: Jake Deery Date: Mon, 1 Dec 2025 14:47:58 +0000 Subject: [PATCH] Bug 14962: On Display code for OPAC scripts & templates This patch makes the necessary changes to the OPAC to make sure effective locations, collection codes, and branches are correctly displayed. Please see the test files commit for instructions on how to test this bundle of patches. Sponsored-by: ByWater Solutions Signed-of-by: Martin Renvoize --- .../bootstrap/en/modules/opac-basket.tt | 8 +- .../bootstrap/en/modules/opac-detail.tt | 31 ++++++-- opac/opac-detail.pl | 78 ++++++++++++++++--- opac/opac-reserve.pl | 36 ++++++++- 4 files changed, 133 insertions(+), 20 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-basket.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-basket.tt index 382bf9727c3..01d4412f59c 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-basket.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-basket.tt @@ -319,7 +319,9 @@ [% FOREACH ITEM_RESULT IN BIBLIO_RESULT.ITEM_RESULTS %]
  • [% Branches.GetName(ITEM_RESULT.holdingbranch) | html %] - [% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => ITEM_RESULT.location, opac => 1 ) | html %] + [% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => ITEM_RESULT.effective_location, opac => 1 ) | html %] [% IF ( ITEM_RESULT.itemcallnumber ) %] ([% ITEM_RESULT.itemcallnumber | html %]) [% END %] @@ -401,7 +403,9 @@ >[% FOREACH ITEM_RESULT IN BIBLIO_RESULT.ITEM_RESULTS %]
  • [% Branches.GetName(ITEM_RESULT.holdingbranch) | html %] - [% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => ITEM_RESULT.location, opac => 1 ) | html %] + [% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => ITEM_RESULT.effective_location, opac => 1 ) | html %] [% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.ccode', authorised_value => ITEM_RESULT.ccode, opac => 1 ) | html %] [% IF ( ITEM_RESULT.itemcallnumber ) %] ([% ITEM_RESULT.itemcallnumber | html %]) 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 9d432eaa075..46c90cf937c 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -1309,6 +1309,7 @@ URL Copy number Status + Displays Notes Date due Barcode @@ -1355,8 +1356,8 @@ [% END %] [% IF ( OpacLocationBranchToDisplay == 'holding' || OpacLocationBranchToDisplay == 'both' ) %] [%# Show opac_info or branchurl from holding library %] - [% SET holding_library_name = Branches.GetName( ITEM_RESULT.holdingbranch ) %] - [% SET holding_library_url = Branches.GetURL( ITEM_RESULT.holdingbranch ) %] + [% SET holding_library_name = ITEM_RESULT.holding_branch.branchname %] + [% SET holding_library_url = Branches.GetURL( ITEM_RESULT.holding_branch.branchcode ) %] @@ -1381,8 +1382,8 @@ [% IF ( OpacLocationBranchToDisplay == 'home' || OpacLocationBranchToDisplay == 'both' ) %] [%# Show opac_info or branchurl from home library %] - [% SET home_library_name = Branches.GetName( ITEM_RESULT.homebranch ) %] - [% SET home_library_url = Branches.GetURL( ITEM_RESULT.homebranch ) %] + [% SET home_library_name = ITEM_RESULT.home_branch.branchname %] + [% SET home_library_url = Branches.GetURL( ITEM_RESULT.home_branch.branchcode ) %] @@ -1532,8 +1533,26 @@ [% INCLUDE 'item-status.inc' item = ITEM_RESULT.object include_schema_org = 1 %] - [% IF ( itemdata_itemnotes ) %] - [% ITEM_RESULT.itemnotes | $raw %] + [% IF ( itemdata_displays ) %] + +
      + [% FOREACH display IN ITEM_RESULT.displays %] +
    • [% display.display_name | html %]
    • + [% END %] +
    + + [% ELSE %] + [% hidden_columns_force.$table_id.push('item_displays') %] + + [% END %] + + [% IF ( itemdata_itemnotes || itemdata_displaynotes ) %] + + [% ITEM_RESULT.itemnotes | $raw %] + [% IF ( ITEM_RESULT.displaynotes ) %] +

    [% ITEM_RESULT.displaynotes | $raw %]

    + [% END %] + [% ELSE %] [% hidden_columns_force.$table_id.push('item_notes') %] diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index edf609cb021..c9aacc45c90 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -727,11 +727,13 @@ if ( not $viewallitems and $items->count > $max_items_to_display ) { $can_holds_be_placed || $patron && IsAvailableForItemLevelRequest( $item, $patron, undef ); # get collection code description, too - my $ccode = $item->ccode; + my $ccode = $item->effective_collection_code; $item_info->{'ccode'} = $collections->{$ccode} - if defined($ccode) - && $collections - && exists( $collections->{$ccode} ); + if defined($ccode) && $collections && exists( $collections->{$ccode} ); + + my $location = $item->effective_location; + $item_info->{'location_description'} = $shelflocations->{$location} + if defined($location) && $shelflocations && exists( $shelflocations->{$location} ); my $copynumber = $item->copynumber; $item_info->{copynumber} = $copynumbers->{$copynumber} @@ -739,11 +741,42 @@ if ( not $viewallitems and $items->count > $max_items_to_display ) { && defined($copynumber) && exists( $copynumbers->{$copynumber} ) ); - if ( defined $item->location ) { - $item_info->{'location_description'} = $shelflocations->{ $item->location }; + $item_info->{holding_branch} = $item->holding_branch; + $item_info->{home_branch} = $item->home_branch; + + if ( C4::Context->preference('UseDisplayModule') && $item->effective_homebranch ) { + my $effective_homebranch = $item->effective_homebranch; + my $effective_homebranch_id = $item->effective_homebranch->branchcode; + my $effective_homebranch_opac_info = $item->effective_homebranch->opac_info( { lang => $lang } ); + + $item_info->{home_library_info} = $effective_homebranch_opac_info + if ($effective_homebranch_opac_info); + + # If it starts with "DISPLAY:", use it as-is, otherwise look it up + if ( $effective_homebranch_id =~ /^DISPLAY:/ ) { + $item_info->{home_branch} = $effective_homebranch_id; + } else { + $item_info->{home_branch} = $effective_homebranch; + } + } + + if ( C4::Context->preference('UseDisplayModule') && $item->effective_holdingbranch ) { + my $effective_holdingbranch = $item->effective_holdingbranch; + my $effective_holdingbranch_id = $item->effective_holdingbranch->branchcode; + my $effective_holdingbranch_opac_info = $item->effective_homebranch->opac_info( { lang => $lang } ); + + $item_info->{holding_library_info} = $effective_holdingbranch_opac_info + if ($effective_holdingbranch_opac_info); + + # If it starts with "DISPLAY:", use it as-is, otherwise look it up + if ( $effective_holdingbranch_id =~ /^DISPLAY:/ ) { + $item_info->{holding_branch} = $effective_holdingbranch_id; + } else { + $item_info->{holding_branch} = $effective_holdingbranch; + } } - my $itemtype = $item->itemtype; + my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype ); $item_info->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itemtype->itemtype }->{'imageurl'} @@ -754,8 +787,31 @@ if ( not $viewallitems and $items->count > $max_items_to_display ) { $item_info->{checkout} = $item->checkout; if ( $item_info->{checkout} && $item_info->{checkout} > 0 ) { $item_checkouts = 1; } + if ( C4::Context->preference('UseDisplayModule') ) { + my @displays; + my @display_items = Koha::DisplayItems->search( + { itemnumber => $item->itemnumber }, + { + order_by => { '-desc' => 'date_added' }, + } + )->as_list; + + foreach my $display_item (@display_items) { + push @displays, $display_item->display; + } + + foreach my $display (@displays) { + $item_info->{displaynotes} .= $display->public_note + if ( $display->public_note ); + } + + $item_info->{display_items} = \@display_items if @display_items; + $item_info->{displays} = \@displays if @displays; + } + foreach my $field ( - qw(ccode materials enumchron copynumber itemnotes location_description uri barcode itemcallnumber)) + qw(ccode materials enumchron copynumber itemnotes location_description uri barcode itemcallnumber displaynotes displays display_items) + ) { $itemfields{$field} = 1 if $item_info->{$field}; } @@ -777,9 +833,6 @@ if ( not $viewallitems and $items->count > $max_items_to_display ) { $item_info->{course_reserves} = GetItemCourseReservesInfo( itemnumber => $item->itemnumber ); } - $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') ) @@ -837,6 +890,9 @@ $template->param( itemdata_location => $itemfields{location_description}, itemdata_barcode => $itemfields{barcode}, itemdata_itemcallnumber => $itemfields{itemcallnumber}, + itemdata_displaynotes => $itemfields{displaynotes}, + itemdata_displays => $itemfields{displays}, + itemdata_display_items => $itemfields{display_items}, OpacStarRatings => C4::Context->preference("OpacStarRatings"), ); diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index 892de210c2c..cea3f7bf81f 100755 --- a/opac/opac-reserve.pl +++ b/opac/opac-reserve.pl @@ -348,7 +348,13 @@ foreach my $biblioNumber (@biblionumbers) { { prefetch => [ 'issue', 'homebranch', 'holdingbranch' ] } )->filter_by_visible_in_opac( { patron => $patron } ); - $biblioData->{items} = [ $items->as_list ]; # FIXME Potentially a lot in memory here! + foreach my $item ( $items->as_list ) { + $item->{'ccode'} = $item->effective_collection_code; + $item->holdingbranch( $item->effective_holdingbranch->branchcode ); + $item->homebranch( $item->effective_homebranch->branchcode ); + + push @{ $biblioData->{items} }, $item; # FIXME Potentially a lot in memory here! + } # Compute the priority rank. $biblioData->{object} = $biblio; @@ -431,6 +437,34 @@ foreach my $biblioNum (@biblionumbers) { my $item_info = $item->unblessed; $item_info->{holding_branch} = $item->holding_branch; $item_info->{home_branch} = $item->home_branch; + + $item_info->{'ccode'} = $item->effective_collection_code + if ( C4::Context->preference('UseDisplayModule') && $item->effective_collection_code ); + + if ( C4::Context->preference('UseDisplayModule') && $item->effective_homebranch ) { + my $effective_homebranch = $item->effective_homebranch; + my $effective_homebranch_id = $item->effective_homebranch->branchcode; + + # If it starts with "DISPLAY:", use it as-is, otherwise look it up + if ( $effective_homebranch_id =~ /^DISPLAY:/ ) { + $item_info->{holding_branch} = $effective_homebranch_id; + } else { + $item_info->{holding_branch} = $effective_homebranch; + } + } + + if ( C4::Context->preference('UseDisplayModule') && $item->effective_holdingbranch ) { + my $effective_holdingbranch = $item->effective_holdingbranch; + my $effective_holdingbranch_id = $item->effective_holdingbranch->branchcode; + + # If it starts with "DISPLAY:", use it as-is, otherwise look it up + if ( $effective_holdingbranch_id =~ /^DISPLAY:/ ) { + $item_info->{home_branch} = $effective_holdingbranch_id; + } else { + $item_info->{home_branch} = $effective_holdingbranch; + } + } + if ($itemLevelTypes) { my $itemtype = $item->itemtype; $item_info->{'imageurl'} = getitemtypeimagelocation( -- 2.53.0