Bug 17642: use get_description_by_koha_field when needed
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 16 Nov 2016 16:29:07 +0000 (17:29 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 18 Nov 2016 15:52:00 +0000 (15:52 +0000)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

C4/Items.pm
Koha/AuthorisedValues.pm
acqui/orderreceive.pl
catalogue/getitem-ajax.pl
circ/circulation.pl
circ/returns.pl
t/db_dependent/AuthorisedValues.t

index 8ed08d5..e02da3b 100644 (file)
@@ -1374,20 +1374,20 @@ sub GetItemsInfo {
 
         $serial ||= $data->{'serial'};
 
-        my $av;
+        my $descriptions;
         # get notforloan complete status if applicable
-        $av = Koha::AuthorisedValues->find_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.notforloan', authorised_value => $data->{itemnotforloan} });
-        $data->{notforloanvalue}     = $av ? $av->lib : '';
-        $data->{notforloanvalueopac} = $av ? $av->opac_description : '';
+        $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.notforloan', authorised_value => $data->{itemnotforloan} });
+        $data->{notforloanvalue}     = $descriptions->{lib} // '';
+        $data->{notforloanvalueopac} = $descriptions->{opac_description} // '';
 
         # get restricted status and description if applicable
-        $av = Koha::AuthorisedValues->find_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.restricted', authorised_value => $data->{restricted} });
-        $data->{restricted}     = $av ? $av->lib : '';
-        $data->{restrictedopac} = $av ? $av->opac_description : '';
+        $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.restricted', authorised_value => $data->{restricted} });
+        $data->{restricted}     = $descriptions->{lib} // '';
+        $data->{restrictedopac} = $descriptions->{opac_description} // '';
 
         # my stack procedures
-        $av = Koha::AuthorisedValues->find_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.stack', authorised_value => $data->{stack} });
-        $data->{stack}          = $av ? $av->lib : '';
+        $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $data->{frameworkcode}, kohafield => 'items.stack', authorised_value => $data->{stack} });
+        $data->{stack}          = $descriptions->{lib} // '';
 
         # Find the last 3 people who borrowed this item.
         my $sth2 = $dbh->prepare("SELECT * FROM old_issues,borrowers
index ad68904..7ceb77a 100644 (file)
@@ -129,7 +129,7 @@ sub get_description_by_koha_field {
     return {} unless defined $authorised_value;
 
     my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
-    my $cache_key    = "Av_descriptions:$frameworkcode:$kohafield:$authorised_value";
+    my $cache_key    = "AV_descriptions:$frameworkcode:$kohafield:$authorised_value";
     my $cached       = $memory_cache->get_from_cache($cache_key);
     return $cached if $cached;
 
index 1a48b3b..0e302bd 100755 (executable)
@@ -128,21 +128,21 @@ if ($AcqCreateItem eq 'receiving') {
     my @items;
     foreach (@itemnumbers) {
         my $item = GetItem($_);
-        my $av;
-        $av = Koha::AuthorisedValues->find_by_koha_field({frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->{notforloan} });
-        $item->{notforloan} = $av ? $av->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->find_by_koha_field({frameworkcode => $fw, kohafield => 'items.restricted', authorised_value => $item->{restricted} });
-        $item->{restricted} = $av ? $av->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->find_by_koha_field({frameworkcode => $fw, kohafield => 'items.location', authorised_value => $item->{location} });
-        $item->{location} = $av ? $av->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->find_by_koha_field({frameworkcode => $fw, kohafield => 'items.collection', authorised_value => $item->{collection} });
-        $item->{collection} = $av ? $av->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->find_by_koha_field({frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->{materials} });
-        $item->{materials} = $av ? $av->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};
index 6974a8f..99814dc 100755 (executable)
@@ -55,21 +55,21 @@ if($itemnumber) {
         $item->{holdingbranchname} = Koha::Libraries->find($item->{holdingbranch})->branchname;
     }
 
-    my $av;
-    $av = Koha::AuthorisedValues->find_by_koha_field({ frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->{notforloan} });
-    $item->{notforloan} = $av ? $av->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->find_by_koha_field({ frameworkcode => $fw, kohafield => 'items.restricted', authorised_value => $item->{restricted} });
-    $item->{restricted} = $av ? $av->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->find_by_koha_field({ frameworkcode => $fw, kohafield => 'items.location', authorised_value => $item->{location} });
-    $item->{location} = $av ? $av->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->find_by_koha_field({ frameworkcode => $fw, kohafield => 'items.collection', authorised_value => $item->{collection} });
-    $item->{collection} = $av ? $av->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->find_by_koha_field({ frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->{materials} });
-    $item->{materials} = $av ? $av->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};
index 340bae7..9a376a1 100755 (executable)
@@ -393,8 +393,8 @@ if (@$barcodes) {
         unless($issueconfirmed){
             #  Get the item title for more information
             my $materials = $iteminfo->{'materials'};
-            my $av = Koha::AuthorisedValues->find_by_koha_field({ frameworkcode => $getmessageiteminfo->{frameworkcode}, kohafield => 'items.materials', authorised_value => $materials });
-            $materials = $av ? $av->lib : '';
+            my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $getmessageiteminfo->{frameworkcode}, kohafield => 'items.materials', authorised_value => $materials });
+            $materials = $descriptions->{lib} // '';
             $template_params->{additional_materials} = $materials;
             $template_params->{itemhomebranch} = $iteminfo->{'homebranch'};
 
index ca56080..b91778a 100755 (executable)
@@ -279,8 +279,8 @@ if ($barcode) {
     $returnbranch = $biblio->{$hbr};
 
     my $materials = $biblio->{'materials'};
-    my $av = Koha::AuthorisedValues->find_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
-    $materials = $av ? $av->lib : '';
+    my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
+    $materials = $descriptions->{lib} // '';
 
     $template->param(
         title            => $biblio->{'title'},
index 7295d41..00ced7e 100644 (file)
@@ -118,7 +118,7 @@ is( @categories, 3, 'There should have 2 categories inserted' );
 is( $categories[0], $av4->category, 'The first category should be correct (ordered by category name)' );
 is( $categories[1], $av1->category, 'The second category should be correct (ordered by category name)' );
 
-subtest 'search_by_*_field + find_by_koha_field + search_for_descriptions' => sub {
+subtest 'search_by_*_field + find_by_koha_field + get_description' => sub {
     plan tests => 4;
     my $loc_cat = Koha::AuthorisedValueCategories->find('LOC');
     $loc_cat->delete if $loc_cat;