Bug 21125: Shortcut moredetail.pl on nonexistent biblionumber
[koha.git] / catalogue / getitem-ajax.pl
index c296257..10df69e 100755 (executable)
@@ -29,6 +29,7 @@ use C4::Output;
 use Koha::Libraries;
 
 use Koha::AuthorisedValues;
+use Koha::ItemTypes;
 
 my $cgi = new CGI;
 
@@ -55,24 +56,24 @@ if($itemnumber) {
         $item->{holdingbranchname} = Koha::Libraries->find($item->{holdingbranch})->branchname;
     }
 
-    my $av;
-    $av = Koha::AuthorisedValues->search_by_koha_field({ frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $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} // '';
 
-    $av = Koha::AuthorisedValues->search_by_koha_field({ frameworkcode => $fw, kohafield => 'items.restricted', authorised_value => $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} // '';
 
-    $av = Koha::AuthorisedValues->search_by_koha_field({ frameworkcode => $fw, kohafield => 'items.location', authorised_value => $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} // '';
 
-    $av = Koha::AuthorisedValues->search_by_koha_field({ frameworkcode => $fw, kohafield => 'items.collection', authorised_value => $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} // '';
 
-    $av = Koha::AuthorisedValues->search_by_koha_field({ frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $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 } );