Bug 17253: Koha::AuthorisedValues - Remove GetKohaAuthorisedValues
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 31 Aug 2016 09:55:25 +0000 (10:55 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 21 Oct 2016 15:35:34 +0000 (15:35 +0000)
This patch replaces the call to C4::Koha::GetKohaAuthorisedValues with
Koha::AuthorisedValues->search_by_koha_field

Test plan:
AV descriptions should be displayed on the following pages:
- XSLT view - location and ccode
- Bibliographic detail, moredetail and OPAC pages - location, ccode, copynumber
- returns - location
- opac-basket - ccode, location
- The 3 reports: catalogue_stats.pl, issues_stats.pl and
  reserves_stats.pl - location, ccode

Signed-off-by: Claire Gravely <claire_gravely@hotmail.com>

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

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

13 files changed:
C4/Koha.pm
C4/Search.pm
C4/XSLT.pm
acqui/orderreceive.pl
basket/basket.pl
catalogue/detail.pl
catalogue/moredetail.pl
circ/returns.pl
opac/opac-basket.pl
opac/opac-detail.pl
reports/catalogue_stats.pl
reports/issues_stats.pl
reports/reserves_stats.pl

index df7b7cc..fb7f30c 100644 (file)
@@ -54,7 +54,6 @@ BEGIN {
                &getitemtypeimagelocation
                &GetAuthorisedValues
                &GetAuthorisedValueCategories
-               &GetKohaAuthorisedValues
                &GetNormalizedUPC
                &GetNormalizedISBN
                &GetNormalizedEAN
@@ -965,33 +964,6 @@ sub GetAuthorisedValueCategories {
     return \@results;
 }
 
-=head2 GetKohaAuthorisedValues
-
-Takes $kohafield, $fwcode as parameters.
-
-If $opac parameter is set to a true value, displays OPAC descriptions rather than normal ones when they exist.
-
-Returns hashref of Code => description
-
-Returns undef if no authorised value category is defined for the kohafield.
-
-=cut
-
-sub GetKohaAuthorisedValues {
-    my ( $kohafield, $fwcode, $opac ) = @_;
-    $fwcode = '' unless $fwcode;
-    my %values;
-    my $dbh = C4::Context->dbh;
-
-    my $avs = Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $fwcode, kohafield => $kohafield } );
-    return {} unless $avs->count;
-    my $values;
-    while ( my $av = $avs->next ) {
-        $values->{ $av->authorised_value } = $opac ? $av->opac_description : $av->lib;
-    }
-    return $values;
-}
-
 =head2 xml_escape
 
   my $escaped_string = C4::Koha::xml_escape($string);
index 829d950..9379eeb 100644 (file)
@@ -1849,7 +1849,8 @@ sub searchResults {
 # 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 =GetKohaAuthorisedValues('items.location','');
+    my $shelflocations =
+      { map { $_->authorised_value => $_->lib } Koha::AuthorisedValues->search_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 => { not => undef } });
index 534226c..518f59d 100644 (file)
@@ -29,6 +29,7 @@ use C4::Koha;
 use C4::Biblio;
 use C4::Circulation;
 use C4::Reserves;
+use Koha::AuthorisedValues;
 use Koha::XSLT_Handler;
 use Koha::Libraries;
 
@@ -272,8 +273,10 @@ sub buildKohaItemsNamespace {
         @items = grep { !$hi{$_->{itemnumber}} } @items;
     }
 
-    my $shelflocations = GetKohaAuthorisedValues('items.location',GetFrameworkCode($biblionumber), 'opac');
-    my $ccodes         = GetKohaAuthorisedValues('items.ccode',GetFrameworkCode($biblionumber), 'opac');
+    my $shelflocations =
+      { map { $_->authorised_value => $_->opac_description } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => GetFrameworkCode($biblionumber), kohafield => 'items.location' } ) };
+    my $ccodes =
+      { map { $_->authorised_value => $_->opac_description } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => GetFrameworkCode($biblionumber), kohafield => 'items.ccode' } ) };
 
     my %branches = map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' });
 
index 7b05013..671cc46 100755 (executable)
@@ -63,7 +63,7 @@ use warnings;
 
 use CGI qw ( -utf8 );
 use C4::Context;
-use C4::Koha;   # GetKohaAuthorisedValues GetItemTypes
+use C4::Koha;   # GetItemTypes
 use C4::Acquisition;
 use C4::Auth;
 use C4::Output;
index ec5e485..83cb180 100755 (executable)
@@ -24,6 +24,7 @@ use C4::Items;
 use C4::Auth;
 use C4::Output;
 
+use Koha::AuthorisedValues;
 use Koha::CsvProfiles;
 
 my $query = new CGI;
@@ -75,8 +76,8 @@ foreach my $biblionumber ( @bibs ) {
       $hasauthors = 1;
     }
        
-    my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'});
-    my $collections =  GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'});
+    my $shelflocations =
+      { map { $_->authorised_value => $_->lib } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) };
 
        for my $itm (@items) {
            if ($itm->{'location'}){
index 46387a9..09aa55c 100755 (executable)
@@ -189,9 +189,12 @@ $dat->{'count'} = scalar @all_items + @hostitems;
 $dat->{'showncount'} = scalar @items + @hostitems;
 $dat->{'hiddencount'} = scalar @all_items + @hostitems - scalar @items;
 
-my $shelflocations = GetKohaAuthorisedValues('items.location', $fw);
-my $collections    = GetKohaAuthorisedValues('items.ccode'   , $fw);
-my $copynumbers    = GetKohaAuthorisedValues('items.copynumber', $fw);
+my $shelflocations =
+  { map { $_->authorised_value => $_->lib } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $fw, kohafield => 'items.location' } ) };
+my $collections =
+  { map { $_->authorised_value => $_->lib } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $fw, kohafield => 'items.ccode' } ) };
+my $copynumbers =
+  { map { $_->authorised_value => $_->lib } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $fw, kohafield => 'items.copynumber' } ) };
 my (@itemloop, @otheritemloop, %itemfields);
 my $norequests = 1;
 
index 1a1adec..80409d7 100755 (executable)
@@ -119,8 +119,10 @@ $data->{'count'}=$totalcount;
 $data->{'showncount'}=$showncount;
 $data->{'hiddencount'}=$hiddencount;  # can be zero
 
-my $ccodes= GetKohaAuthorisedValues('items.ccode',$fw);
-my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$fw);
+my $ccodes =
+  { map { $_->authorised_value => $_->lib } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $fw, kohafield => 'items.ccode' } ) };
+my $copynumbers =
+  { map { $_->authorised_value => $_->lib } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $fw, kohafield => 'items.copynumber' } ) };
 my $itemtypes = GetItemTypes;
 
 $data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'translated_description'};
index 1d2340d..619228f 100755 (executable)
@@ -551,7 +551,8 @@ $template->param( errmsgloop => \@errmsgloop );
 my $returned_counter = ( C4::Context->preference('numReturnedItemsToShow') ) ? C4::Context->preference('numReturnedItemsToShow') : 8;
 my $count = 0;
 my @riloop;
-my $shelflocations = GetKohaAuthorisedValues('items.location','');
+my $shelflocations =
+  { map { $_->authorised_value => $_->lib } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => '', kohafield => 'items.location' } ) };
 foreach ( sort { $a <=> $b } keys %returneditems ) {
     my %ri;
     if ( $count++ < $returned_counter ) {
index 4c2d732..82734b1 100755 (executable)
@@ -26,6 +26,8 @@ use C4::Auth;
 use C4::Output;
 use Koha::RecordProcessor;
 
+use Koha::AuthorisedValues;
+
 my $query = new CGI;
 
 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
@@ -83,8 +85,10 @@ foreach my $biblionumber ( @bibs ) {
     if($dat->{'author'} || @$marcauthorsarray) {
       $hasauthors = 1;
     }
-    my $collections =  GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac');
-    my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac');
+    my $collections =
+      { map { $_->authorised_value => $_->opac_description } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.ccode' } ) };
+    my $shelflocations =
+      { map { $_->authorised_value => $_->opac_description } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) };
 
        # COinS format FIXME: for books Only
         my $coins_format;
index 5d0eeff..41c1d22 100755 (executable)
@@ -48,6 +48,7 @@ use Koha::DateUtils;
 use C4::HTML5Media;
 use C4::CourseReserves qw(GetItemCourseReservesInfo);
 use Koha::RecordProcessor;
+use Koha::AuthorisedValues;
 use Koha::Virtualshelves;
 use Koha::Ratings;
 use Koha::Reviews;
@@ -543,9 +544,13 @@ if ( $itemtype ) {
     $dat->{'imageurl'}    = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
     $dat->{'description'} = $itemtypes->{$itemtype}->{translated_description};
 }
-my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac');
-my $collections =  GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac');
-my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$dat->{'frameworkcode'}, 'opac');
+
+my $shelflocations =
+  { map { $_->authorised_value => $_->opac_description } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) };
+my $collections =
+  { map { $_->authorised_value => $_->opac_description } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.ccode' } ) };
+my $copynumbers =
+  { map { $_->authorised_value => $_->opac_description } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.copynumber' } ) };
 
 #coping with subscriptions
 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
index b0a72b0..97a4509 100755 (executable)
@@ -29,6 +29,7 @@ use C4::Reports;
 use C4::Circulation;
 use C4::Biblio qw/GetMarcSubfieldStructureFromKohaField/;
 
+use Koha::AuthorisedValues;
 use Koha::DateUtils;
 
 =head1 NAME
@@ -121,17 +122,8 @@ if ($do_it) {
 
     my $itemtypes = GetItemTypes( style => 'array' );
 
-    my $authvals = GetKohaAuthorisedValues("items.ccode");
-    my @authvals;
-    foreach ( sort { $authvals->{$a} cmp $authvals->{$b} || $a cmp $b } keys %$authvals ) {
-        push @authvals, { code => $_, description => $authvals->{$_} };
-    }
-
-    my $locations = GetKohaAuthorisedValues("items.location");
-    my @locations;
-    foreach ( sort keys %$locations ) {
-        push @locations, { code => $_, description => "$_ - " . $locations->{$_} };
-    }
+    my @authvals = map { { code => $_->authorised_value, description => $_->lib } } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => '', kohafield => 'items.ccode' }, { order_by => ['description'] } );
+    my @locations = map { { code => $_->authorised_value, description => $_->lib } } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } );
 
     foreach my $kohafield (qw(items.notforloan items.materials)) {
         my $subfield_structure = GetMarcSubfieldStructureFromKohaField($kohafield);
@@ -322,7 +314,7 @@ sub calculate {
     } else {
         $sth->execute();
     }
-    my $rowauthvals = GetKohaAuthorisedValues($origline);
+    my $rowauthvals = { map { $_->authorised_value => $_->lib } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => '', kohafield => $origline } ) };
     while ( my ($celvalue) = $sth->fetchrow ) {
         my %cell;
         if (defined $celvalue and $celvalue ne '') {
@@ -385,7 +377,7 @@ sub calculate {
     } else {
         $sth2->execute();
     }
-    my $colauthvals = GetKohaAuthorisedValues($origcolumn);
+    my $colauthvals = { map { $_->authorised_value => $_->lib } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => '', kohafield => $origcolumn } ) };
     while ( my ($celvalue) = $sth2->fetchrow ) {
         my %cell;
         if (defined $celvalue and $celvalue ne '') {
index 665e02b..648efe1 100755 (executable)
@@ -31,6 +31,8 @@ use C4::Output;
 use C4::Circulation;
 use C4::Reports;
 use C4::Members;
+
+use Koha::AuthorisedValues;
 use Koha::DateUtils;
 
 =head1 NAME
@@ -77,8 +79,8 @@ $template->param(do_it => $do_it,
 our $itemtypes = GetItemTypes();
 our @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']});
 
-our $ccodes    = GetKohaAuthorisedValues("items.ccode");
-our $locations = GetKohaAuthorisedValues("items.location");
+my $locations = { map { ( $_->authorised_value => $_->lib ) } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } ) };
+my $ccodes = { map { ( $_->authorised_value => $_->lib ) } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => '', kohafield => 'items.ccode' }, { order_by => ['description'] } ) };
 
 our $Bsort1 = GetAuthorisedValues("Bsort1");
 our $Bsort2 = GetAuthorisedValues("Bsort2");
index fe1d73c..f591be1 100755 (executable)
@@ -30,6 +30,7 @@ use C4::Koha;
 use C4::Output;
 use C4::Reports;
 use C4::Members;
+use Koha::AuthorisedValues;
 use Koha::DateUtils;
 use Koha::Libraries;
 use Koha::Patron::Categories;
@@ -83,9 +84,8 @@ $template->param(do_it => $do_it,
 my $itemtypes = GetItemTypes();
 my @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']});
 
-my $ccodes    = GetKohaAuthorisedValues("items.ccode");
-my $locations = GetKohaAuthorisedValues("items.location");
-my $authvalue = GetKohaAuthorisedValues("items.authvalue");
+my $locations = { map { ( $_->authorised_value => $_->lib ) } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } ) };
+my $ccodes = { map { ( $_->authorised_value => $_->lib ) } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => '', kohafield => 'items.ccode' }, { order_by => ['description'] } ) };
 
 my $Bsort1 = GetAuthorisedValues("Bsort1");
 my $Bsort2 = GetAuthorisedValues("Bsort2");
@@ -330,10 +330,9 @@ sub null_to_zzempty ($) {
 }
 sub display_value {
     my ( $crit, $value ) = @_;
-    my $ccodes    = GetKohaAuthorisedValues("items.ccode");
-    my $locations = GetKohaAuthorisedValues("items.location");
+    my $locations = { map { ( $_->authorised_value => $_->lib ) } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } ) };
+    my $ccodes = { map { ( $_->authorised_value => $_->lib ) } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => '', kohafield => 'items.ccode' }, { order_by => ['description'] } ) };
     my $itemtypes = GetItemTypes();
-    my $authvalue = GetKohaAuthorisedValues("items.authvalue");
     my $Bsort1 = GetAuthorisedValues("Bsort1");
     my $Bsort2 = GetAuthorisedValues("Bsort2");
     my $display_value =