From 5a9e4c765dbc9b0b48a77edf917683af67e5cdd2 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 11 Dec 2025 21:27:27 +0000 Subject: [PATCH] Bug 41435: Use AuthorisedValues.GetDescriptionByKohaField for search results To test: 1 - Do some search on the interface 2 - Check the results 3 - Apply patch 4 - Restart all 5 - Confirm notforloan, collectioncode, and shelving locations are still correctly described --- C4/Search.pm | 50 +++---------------- .../prog/en/modules/catalogue/results.tt | 6 +-- 2 files changed, 11 insertions(+), 45 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 5d6f3c6e33d..23dd75db4ff 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -541,20 +541,14 @@ sub getRecords { # also, if it's a location code, use the name instead of the code if ( $link_value =~ /location/ ) { - - # TODO Retrieve all authorised values at once, instead of 1 query per entry - my $av = - Koha::AuthorisedValues->search( { category => 'LOC', authorised_value => $one_facet } ); - $facet_label_value = $av->count ? $av->next->opac_description : ''; + $facet_label_value = Koha::AuthorisedValues->search( + { kohafield => 'items.location', authorised_value => $one_facet } ); } # also, if it's a collection code, use the name instead of the code if ( $link_value =~ /ccode/ ) { - - # TODO Retrieve all authorised values at once, instead of 1 query per entry - my $av = Koha::AuthorisedValues->search( - { category => 'CCODE', authorised_value => $one_facet } ); - $facet_label_value = $av->count ? $av->next->opac_description : ''; + $facet_label_value = Koha::AuthorisedValues->search( + { kohafield => 'items.ccode', authorised_value => $one_facet } ); } # but we're down with the whole label being in the link's title. @@ -1678,24 +1672,6 @@ sub searchResults { my %branches = map { $_->branchcode => $_->branchname } Koha::Libraries->search( {}, { order_by => 'branchname' } )->as_list; - # FIXME - We build an authorised values hash here, using the default framework - # though it is possible to have different authvals for different fws. - - my $shelflocations = { - map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( - { frameworkcode => '', kohafield => 'items.location' } - ) - }; - - # get notforloan authorised value list (see $shelflocations FIXME) - my $av = Koha::MarcSubfieldStructures->search( - { - frameworkcode => '', kohafield => 'items.notforloan', - authorised_value => [ -and => { '!=' => undef }, { '!=' => '' } ] - } - ); - my $notforloan_authorised_value = $av->count ? $av->next->authorised_value : undef; - #Get itemtype hash my $itemtypes = Koha::ItemTypes->search_with_localization; my %itemtypes = map { $_->{itemtype} => $_ } @{ $itemtypes->unblessed }; @@ -1912,15 +1888,13 @@ sub searchResults { $onloan_items->{$key}->{count}++ if $item->{$hbranch}; $onloan_items->{$key}->{branchname} = $item->{branchname}; $onloan_items->{$key}->{branchcode} = $item->{branchcode}; - $onloan_items->{$key}->{location} = $shelflocations->{ $item->{location} } if $item->{location}; $onloan_items->{$key}->{itemcallnumber} = $item->{itemcallnumber}; $onloan_items->{$key}->{description} = $item->{description}; $onloan_items->{$key}->{imageurl} = getitemtypeimagelocation( $search_context->{'interface'}, $itemtypes{ $item->{itype} }->{imageurl} ); - $onloan_items->{$key}->{collectioncode} = - GetAuthorisedValueDesc( '', '', $item->{ccode}, '', '', 'CCODE' ); + $onloan_items->{$key}->{collectioncode} = $item->{ccode}; # if something's checked out and lost, mark it as 'long overdue' if ( $item->{itemlost} ) { @@ -2026,18 +2000,13 @@ sub searchResults { $other_items->{$key}->{intransit} = ( $transfertwhen ne '' ) ? 1 : 0; $other_items->{$key}->{recalled} = ($recallstatus) ? 1 : 0; $other_items->{$key}->{onhold} = ($reservestatus) ? 1 : 0; - $other_items->{$key}->{notforloan} = - GetAuthorisedValueDesc( '', '', $item->{notforloan}, '', '', $notforloan_authorised_value ) - if $notforloan_authorised_value and $item->{notforloan}; $other_items->{$key}->{count}++ if $item->{$hbranch}; - $other_items->{$key}->{location} = $shelflocations->{ $item->{location} } if $item->{location}; $other_items->{$key}->{description} = $item->{description}; $other_items->{$key}->{imageurl} = getitemtypeimagelocation( $search_context->{'interface'}, $itemtypes{ $item->{itype} // q{} }->{imageurl} ); - $other_items->{$key}->{collectioncode} = - GetAuthorisedValueDesc( '', '', $item->{ccode}, '', '', 'CCODE' ); + $other_items->{$key}->{collectioncode} = $item->{ccode}; } # item is available @@ -2051,14 +2020,11 @@ sub searchResults { } $available_items->{$prefix}->{branchavailablecount} = $branch_available_count; $available_items->{$prefix}->{branchcode} = $item->{branchcode}; - $available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} } - if $item->{location}; - $available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( + $available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context->{'interface'}, $itemtypes{ $item->{itype} // q{} }->{imageurl} ); - $available_items->{$prefix}->{collectioncode} = - GetAuthorisedValueDesc( '', '', $item->{ccode}, '', '', 'CCODE' ); + $available_items->{$prefix}->{collectioncode} = $item->{ccode}; } } } # notforloan, item level and biblioitem level diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt index c04479af867..e3fbca39623 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -827,10 +827,10 @@ [% items_loo.branchname | html %] [% END %] [% IF ( items_loo.location ) %] - [% items_loo.location | html %] + AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => items_loo.location ) | html %] [% END %] [% IF ( items_loo.collectioncode ) %] - [% items_loo.collectioncode | html %] + AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.ccode', authorised_value => items_loo.collectioncode ) | html %] [% END %] [% IF ( items_loo.itemcallnumber ) %] @@ -853,7 +853,7 @@ (On hold) [% END %] [% IF ( items_loo.notforloan ) %] - [% items_loo.notforloan | html %] + [% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.notforloan', authorised_value => items_loo.notforloan ) | html %] [% END %] [% items_loo.count | html %] -- 2.39.5