From baf78b2a332aa5416f7cbf2020609aa753debda2 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 31 Aug 2016 10:55:25 +0100 Subject: [PATCH] Bug 17253: Koha::AuthorisedValues - Remove GetKohaAuthorisedValues 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 Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall --- C4/Koha.pm | 28 ---------------------------- C4/Search.pm | 3 ++- C4/XSLT.pm | 7 +++++-- acqui/orderreceive.pl | 2 +- basket/basket.pl | 5 +++-- catalogue/detail.pl | 9 ++++++--- catalogue/moredetail.pl | 6 ++++-- circ/returns.pl | 3 ++- opac/opac-basket.pl | 8 ++++++-- opac/opac-detail.pl | 11 ++++++++--- reports/catalogue_stats.pl | 18 +++++------------- reports/issues_stats.pl | 6 ++++-- reports/reserves_stats.pl | 11 +++++------ 13 files changed, 51 insertions(+), 66 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index df7b7cc1c2..fb7f30c25b 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -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); diff --git a/C4/Search.pm b/C4/Search.pm index 829d950b03..9379eebf27 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -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 } }); diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 534226c7d7..518f59de92 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -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' }); diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl index 7b05013424..671cc4669c 100755 --- a/acqui/orderreceive.pl +++ b/acqui/orderreceive.pl @@ -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; diff --git a/basket/basket.pl b/basket/basket.pl index ec5e485892..83cb18027d 100755 --- a/basket/basket.pl +++ b/basket/basket.pl @@ -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'}){ diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 46387a9921..09aa55c909 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -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; diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl index 1a1adecd4b..80409d71f9 100755 --- a/catalogue/moredetail.pl +++ b/catalogue/moredetail.pl @@ -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'}; diff --git a/circ/returns.pl b/circ/returns.pl index 1d2340d4ab..619228f0fb 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -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 ) { diff --git a/opac/opac-basket.pl b/opac/opac-basket.pl index 4c2d73285d..82734b1c48 100755 --- a/opac/opac-basket.pl +++ b/opac/opac-basket.pl @@ -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; diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 5d0eeffcf7..41c1d22a6b 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -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); diff --git a/reports/catalogue_stats.pl b/reports/catalogue_stats.pl index b0a72b0094..97a450939c 100755 --- a/reports/catalogue_stats.pl +++ b/reports/catalogue_stats.pl @@ -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 '') { diff --git a/reports/issues_stats.pl b/reports/issues_stats.pl index 665e02b886..648efe11fe 100755 --- a/reports/issues_stats.pl +++ b/reports/issues_stats.pl @@ -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"); diff --git a/reports/reserves_stats.pl b/reports/reserves_stats.pl index fe1d73c370..f591be1f51 100755 --- a/reports/reserves_stats.pl +++ b/reports/reserves_stats.pl @@ -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 = -- 2.39.5