From 9dcf2e1bb89fa7aaaa4b369d582dd6124bc1ba54 Mon Sep 17 00:00:00 2001 From: Thibaud Guillot Date: Mon, 12 Sep 2022 11:04:07 +0200 Subject: [PATCH] Bug 31550: Add fields to get opac description on ILSDI web service Test plan 1) Active your ILS-DI syspref 2) Have some authorised values linked to one or more concern fields 3) Choose an item and go to 'cgi-bin/koha/opac/ilsdi.pl?service=GetRecords&id=' 4) The XML file contains item fields with some of them the code associated to the authorized values. 5) Apply this patch 6) Repeat step 3 and see the new fields with specific "_description" suffix added and contains opac description from authorized values Sponsored-by: BibLibre Signed-off-by: David Nind --- C4/ILSDI/Services.pm | 20 +++++++++++++++----- t/db_dependent/AuthorisedValues.t | 12 ++++++++++-- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm index 597a9ddd1d..0269bc111b 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -262,11 +262,21 @@ sub GetRecords { $item{'homebranchname'} = $home_library ? $home_library->branchname : ''; $item{'holdingbranchname'} = $holding_library ? $holding_library->branchname : ''; - if ( $item->location ) { - my $authorised_value = Koha::AuthorisedValues->get_description_by_koha_field( - { frameworkcode => '', kohafield => 'items.location', authorised_value => $item->location } ); - if ($authorised_value) { - $item{location_description} = $authorised_value->{opac_description}; + my $item_strings = $item->strings_map; + foreach my $field ( keys %{$item_strings} ) { + if ( $item->$field ) { + my $authorised_value = + Koha::AuthorisedValues->get_description_by_koha_field( + { + frameworkcode => '', + kohafield => 'items.' . $field, + authorised_value => $item->$field + } + ); + if ($authorised_value) { + $item{ $field . '_description' } = + $authorised_value->{opac_description}; + } } } diff --git a/t/db_dependent/AuthorisedValues.t b/t/db_dependent/AuthorisedValues.t index 069614504a..08f09efca4 100755 --- a/t/db_dependent/AuthorisedValues.t +++ b/t/db_dependent/AuthorisedValues.t @@ -228,8 +228,7 @@ subtest 'search_by_*_field + find_by_koha_field + get_description + authorised_v }; subtest 'find_by_koha_field' => sub { - plan tests => 3; - + plan tests => 4; # Test authorised_value = 0 my $av; $av = Koha::AuthorisedValues->find_by_koha_field( { kohafield => 'items.restricted', authorised_value => 0 } ); @@ -243,6 +242,15 @@ subtest 'search_by_*_field + find_by_koha_field + get_description + authorised_v $av = Koha::AuthorisedValues->find_by_koha_field( { kohafield => 'items.restricted', authorised_value => undef } ); is( $av, undef, ); + # Test get authorised_value->opac_description if kohafield is in array + my @authorised_kohafields = ( 'location', 'ccode', 'permanent_location', 'notforloan', 'itemlost', 'withdrawn', 'damaged', 'restricted' ); + foreach my $kohafield (@authorised_kohafields) { + $av = Koha::AuthorisedValues->find_by_koha_field( { kohafield => 'items.' . $kohafield, authorised_value => 'location_1' } ); + if ($av) { + is( + $av->opac_description, 'location_1', "items.$kohafield description added correctly" ); + } + } }; subtest 'get_description_by_koha_field' => sub { plan tests => 4; -- 2.39.5