Bugzilla – Attachment 194452 Details for
Bug 40481
The items table on koha/opac-MARCdetail.pl does not honor OPACHiddenItems
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40481: (follow-up) Simplify item loop in OPAC MARC detail
Bug-40481-follow-up-Simplify-item-loop-in-OPAC-MAR.patch (text/plain), 4.55 KB, created by
David Nind
on 2026-03-04 14:20:24 UTC
(
hide
)
Description:
Bug 40481: (follow-up) Simplify item loop in OPAC MARC detail
Filename:
MIME Type:
Creator:
David Nind
Created:
2026-03-04 14:20:24 UTC
Size:
4.55 KB
patch
obsolete
>From b203121d16ccd9acd8af8d5bf6851a09422b614f Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= <tomascohen@theke.io> >Date: Wed, 4 Mar 2026 10:16:43 -0300 >Subject: [PATCH] Bug 40481: (follow-up) Simplify item loop in OPAC MARC detail > >Now that the item loop only processes item fields from the filtered >$items resultset, several checks and patterns become unnecessary. > >Changes: >- Remove dead checks: tag < 10 and tab != 10 guards >- Resolve $tagslib->{$item_tag} once instead of per-subfield >- Destructure ($code, $value) instead of indexed $subf[$i][0/1] >- Replace per-subfield grep over date kohafields with a hash lookup >- Remove redundant second $tagslib lookup for $kohafield >- Collapse repeatable if/else into a ternary > >No functional changes. > >Test plan: >1. Apply patch >2. Run the same test plan as the previous patch >=> SUCCESS: Behavior is identical >3. Sign off :-D > >Signed-off-by: David Nind <david@davidnind.com> >--- > opac/opac-MARCdetail.pl | 53 ++++++++++++++++------------------------- > 1 file changed, 21 insertions(+), 32 deletions(-) > >diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl >index 01ba8ff886..616ee7a292 100755 >--- a/opac/opac-MARCdetail.pl >+++ b/opac/opac-MARCdetail.pl >@@ -271,54 +271,43 @@ for ( my $tabloop = 0 ; $tabloop <= 9 ; $tabloop++ ) { > $template->param( "tab" . $tabloop . "XX" => \@loop_data ); > } > >-# now, build item tab ! >-# the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values... >-# loop through each tag >-# warning : we may have different number of columns in each row. Thus, we first build a hash, complete it if necessary >-# then construct template. >-# $record has already had all the item fields filtered above. >+# Now, build item tab! >+# Data is in rows (one per item) not columns: build headers (%witness) and row data (@item_loop). > $items->reset(); >-my @fields = map { $_->as_marc_field } $items->as_list; >-my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code >+my @fields = map { $_->as_marc_field } $items->as_list; >+my $item_tag = $fields[0] ? $fields[0]->tag() : undef; >+my $item_tagslib = $item_tag ? $tagslib->{$item_tag} : {}; >+my %witness; > my @item_subfield_codes; > my @item_loop; >+ >+my %date_fields = map { $_ => 1 } >+ qw( items.dateaccessioned items.onloan items.datelastseen items.datelastborrowed items.replacementpricedate ); >+ > foreach my $field (@fields) { >- next if ( $field->tag() < 10 ); >- my @subf = $field->subfields; > my $item; > >- # loop through each subfield >- for my $i ( 0 .. $#subf ) { >- my $sf_def = $tagslib->{ $field->tag() }->{ $subf[$i][0] }; >- next if ( ( $sf_def->{tab} || 0 ) != 10 ); >+ for my $subf ( $field->subfields ) { >+ my ( $code, $value ) = @$subf; >+ my $sf_def = $item_tagslib->{$code}; > next if ( ( $sf_def->{hidden} || 0 ) > 0 ); > >- push @item_subfield_codes, $subf[$i][0]; >- $witness{ $subf[$i][0] } = $sf_def->{lib}; >+ push @item_subfield_codes, $code; >+ $witness{$code} = $sf_def->{lib}; > > # Allow repeatables (BZ 13574) >- if ( $item->{ $subf[$i][0] } ) { >- $item->{ $subf[$i][0] } .= ' | '; >- } else { >- $item->{ $subf[$i][0] } = q{}; >- } >+ $item->{$code} = ( $item->{$code} ) ? $item->{$code} . ' | ' : q{}; > > if ( $sf_def->{isurl} ) { >- $item->{ $subf[$i][0] } .= "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>"; >+ $item->{$code} .= "<a href=\"$value\">$value</a>"; > } elsif ( $sf_def->{kohafield} eq "biblioitems.isbn" ) { >- $item->{ $subf[$i][0] } .= $subf[$i][1]; >+ $item->{$code} .= $value; > } else { >- $item->{ $subf[$i][0] } .= GetAuthorisedValueDesc( >- $field->tag(), $subf[$i][0], >- $subf[$i][1], '', $tagslib, '', 'opac' >- ) // q{}; >+ $item->{$code} .= GetAuthorisedValueDesc( $item_tag, $code, $value, '', $tagslib, '', 'opac' ) // q{}; > } > >- my $kohafield = $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield}; >- $item->{ $subf[$i][0] } = output_pref( { str => $item->{ $subf[$i][0] }, dateonly => 1 } ) >- if grep { $kohafield eq $_ } >- qw( items.dateaccessioned items.onloan items.datelastseen items.datelastborrowed items.replacementpricedate ); >- >+ $item->{$code} = output_pref( { str => $item->{$code}, dateonly => 1 } ) >+ if $date_fields{ $sf_def->{kohafield} // q{} }; > } > push @item_loop, $item if $item; > } >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 40481
:
188582
|
188583
|
188584
|
188585
|
188586
|
194401
|
194446
|
194447
|
194451
| 194452