Bug 18316: (follow-up) Koha::SearchField::search_marc_maps return a result set -...
[koha.git] / catalogue / getitem-ajax.pl
index f79e4ad..10df69e 100755 (executable)
@@ -29,6 +29,7 @@ use C4::Output;
 use Koha::Libraries;
 
 use Koha::AuthorisedValues;
+use Koha::ItemTypes;
 
 my $cgi = new CGI;
 
@@ -55,33 +56,24 @@ if($itemnumber) {
         $item->{holdingbranchname} = Koha::Libraries->find($item->{holdingbranch})->branchname;
     }
 
-    if(my $code = GetAuthValCode("items.notforloan", $fw)) {
-        my $av = Koha::AuthorisedValues->search({ category => $code, authorised_values => $item->{notforloan} });
-        $item->{notforloan} = $av->count ? $av->next->lib : '';
-    }
+    my $descriptions;
+    $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->{notforloan} });
+    $item->{notforloan} = $descriptions->{lib} // '';
 
-    if(my $code = GetAuthValCode("items.restricted", $fw)) {
-        my $av = Koha::AuthorisedValues->search({ category => $code, authorised_values => $item->{restricted} });
-        $item->{restricted} = $av->count ? $av->next->lib : '';
-    }
+    $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.restricted', authorised_value => $item->{restricted} });
+    $item->{restricted} = $descriptions->{lib} // '';
 
-    if(my $code = GetAuthValCode("items.location", $fw)) {
-        my $av = Koha::AuthorisedValues->search({ category => $code, authorised_values => $item->{location} });
-        $item->{location} = $av->count ? $av->next->lib : '';
-    }
+    $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.location', authorised_value => $item->{location} });
+    $item->{location} = $descriptions->{lib} // '';
 
-    if(my $code = GetAuthValCode("items.ccode", $fw)) {
-        my $av = Koha::AuthorisedValues->search({ category => $code, authorised_values => $item->{collection} });
-        $item->{collection} = $av->count ? $av->next->lib : '';
-    }
+    $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.collection', authorised_value => $item->{collection} });
+    $item->{collection} = $descriptions->{lib} // '';
 
-    if(my $code = GetAuthValCode("items.materials", $fw)) {
-        my $av = Koha::AuthorisedValues->search({ category => $code, authorised_values => $item->{materials} });
-        $item->{materials} = $av->count ? $av->next->lib : '';
-    }
+    $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->{materials} });
+    $item->{materials} = $descriptions->{lib} // '';
 
-    my $itemtype = getitemtypeinfo($item->{itype});
-    $item->{itemtype} = $itemtype->{description};
+    my $itemtype = Koha::ItemTypes->find( $item->{itype} );
+    $item->{itemtype} = $itemtype->description; # FIXME Should not it be translated_description?
 }
 
 my $json_text = to_json( $item, { utf8 => 1 } );