@@ -, +, @@ --- C4/Search.pm | 2 +- C4/XSLT.pm | 4 ++-- Koha/AuthorisedValues.pm | 22 ++++++++++++++++++++++ basket/basket.pl | 2 +- catalogue/detail.pl | 6 +++--- catalogue/moredetail.pl | 4 ++-- circ/returns.pl | 2 +- opac/opac-basket.pl | 4 ++-- opac/opac-detail.pl | 6 +++--- reports/catalogue_stats.pl | 8 ++++---- reports/issues_stats.pl | 4 ++-- reports/reserves_stats.pl | 8 ++++---- t/db_dependent/AuthorisedValues.t | 21 ++++++++++++++++++++- 13 files changed, 67 insertions(+), 26 deletions(-) --- a/C4/Search.pm +++ a/C4/Search.pm @@ -1850,7 +1850,7 @@ sub searchResults { # though it is possible to have different authvals for different fws. my $shelflocations = - { map { $_->authorised_value => $_->lib } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => '', kohafield => 'items.location' } ) }; + { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_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 } }); --- a/C4/XSLT.pm +++ a/C4/XSLT.pm @@ -274,9 +274,9 @@ sub buildKohaItemsNamespace { } my $shelflocations = - { map { $_->authorised_value => $_->opac_description } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => GetFrameworkCode($biblionumber), kohafield => 'items.location' } ) }; + { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_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' } ) }; + { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => GetFrameworkCode($biblionumber), kohafield => 'items.ccode' } ) }; my %branches = map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' }); --- a/Koha/AuthorisedValues.pm +++ a/Koha/AuthorisedValues.pm @@ -139,6 +139,28 @@ sub get_description_by_koha_field { return $descriptions; } +sub get_descriptions_by_koha_field { + my ( $self, $params ) = @_; + my $frameworkcode = $params->{frameworkcode} || ''; + my $kohafield = $params->{kohafield}; + + my $memory_cache = Koha::Cache::Memory::Lite->get_instance; + my $cache_key = "AV_descriptions:$frameworkcode:$kohafield"; + my $cached = $memory_cache->get_from_cache($cache_key); + return @$cached if $cached; + + my @avs = $self->search_by_koha_field($params); + my @descriptions = map { + { + authorised_value => $_->authorised_value, + lib => $_->lib, + opac_description => $_->opac_description + } + } @avs; + $memory_cache->set_in_cache( $cache_key, \@descriptions ); + return @descriptions; +} + sub categories { my ( $self ) = @_; my $rs = $self->_resultset->search( --- a/basket/basket.pl +++ a/basket/basket.pl @@ -77,7 +77,7 @@ foreach my $biblionumber ( @bibs ) { } my $shelflocations = - { map { $_->authorised_value => $_->lib } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) }; + { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) }; for my $itm (@items) { if ($itm->{'location'}){ --- a/catalogue/detail.pl +++ a/catalogue/detail.pl @@ -190,11 +190,11 @@ $dat->{'showncount'} = scalar @items + @hostitems; $dat->{'hiddencount'} = scalar @all_items + @hostitems - scalar @items; my $shelflocations = - { map { $_->authorised_value => $_->lib } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $fw, kohafield => 'items.location' } ) }; + { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_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' } ) }; + { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_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' } ) }; + { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.copynumber' } ) }; my (@itemloop, @otheritemloop, %itemfields); my $norequests = 1; --- a/catalogue/moredetail.pl +++ a/catalogue/moredetail.pl @@ -120,9 +120,9 @@ $data->{'showncount'}=$showncount; $data->{'hiddencount'}=$hiddencount; # can be zero my $ccodes = - { map { $_->authorised_value => $_->lib } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $fw, kohafield => 'items.ccode' } ) }; + { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_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' } ) }; + { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.copynumber' } ) }; my $itemtypes = GetItemTypes; $data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'translated_description'}; --- a/circ/returns.pl +++ a/circ/returns.pl @@ -552,7 +552,7 @@ my $returned_counter = ( C4::Context->preference('numReturnedItemsToShow') ) ? C my $count = 0; my @riloop; my $shelflocations = - { map { $_->authorised_value => $_->lib } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => '', kohafield => 'items.location' } ) }; + { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' } ) }; foreach ( sort { $a <=> $b } keys %returneditems ) { my %ri; if ( $count++ < $returned_counter ) { --- a/opac/opac-basket.pl +++ a/opac/opac-basket.pl @@ -86,9 +86,9 @@ foreach my $biblionumber ( @bibs ) { $hasauthors = 1; } my $collections = - { map { $_->authorised_value => $_->opac_description } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.ccode' } ) }; + { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_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' } ) }; + { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) }; # COinS format FIXME: for books Only my $coins_format; --- a/opac/opac-detail.pl +++ a/opac/opac-detail.pl @@ -546,11 +546,11 @@ if ( $itemtype ) { } my $shelflocations = - { map { $_->authorised_value => $_->opac_description } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) }; + { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_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' } ) }; + { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_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' } ) }; + { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.copynumber' } ) }; #coping with subscriptions my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber); --- a/reports/catalogue_stats.pl +++ a/reports/catalogue_stats.pl @@ -122,8 +122,8 @@ if ($do_it) { my $itemtypes = GetItemTypes( style => 'array' ); - 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'] } ); + my @authvals = map { { code => $_->{authorised_value}, description => $_->{lib} } } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.ccode' }, { order_by => ['description'] } ); + my @locations = map { { code => $_->{authorised_value}, description => $_->{lib} } } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } ); foreach my $kohafield (qw(items.notforloan items.materials)) { my $subfield_structure = GetMarcSubfieldStructureFromKohaField($kohafield); @@ -314,7 +314,7 @@ sub calculate { } else { $sth->execute(); } - my $rowauthvals = { map { $_->authorised_value => $_->lib } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => '', kohafield => $origline } ) }; + my $rowauthvals = { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => $origline } ) }; while ( my ($celvalue) = $sth->fetchrow ) { my %cell; if (defined $celvalue and $celvalue ne '') { @@ -377,7 +377,7 @@ sub calculate { } else { $sth2->execute(); } - my $colauthvals = { map { $_->authorised_value => $_->lib } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => '', kohafield => $origcolumn } ) }; + my $colauthvals = { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => $origcolumn } ) }; while ( my ($celvalue) = $sth2->fetchrow ) { my %cell; if (defined $celvalue and $celvalue ne '') { --- a/reports/issues_stats.pl +++ a/reports/issues_stats.pl @@ -90,8 +90,8 @@ $template->param(do_it => $do_it, our $itemtypes = GetItemTypes(); our @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']}); -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 $locations = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } ) }; +my $ccodes = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.ccode' }, { order_by => ['description'] } ) }; our $Bsort1 = GetAuthorisedValues("Bsort1"); our $Bsort2 = GetAuthorisedValues("Bsort2"); --- a/reports/reserves_stats.pl +++ a/reports/reserves_stats.pl @@ -84,8 +84,8 @@ $template->param(do_it => $do_it, my $itemtypes = GetItemTypes(); my @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']}); -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 $locations = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } ) }; +my $ccodes = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.ccode' }, { order_by => ['description'] } ) }; my $Bsort1 = GetAuthorisedValues("Bsort1"); my $Bsort2 = GetAuthorisedValues("Bsort2"); @@ -330,8 +330,8 @@ sub null_to_zzempty ($) { } sub display_value { my ( $crit, $value ) = @_; - 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 $locations = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } ) }; + my $ccodes = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.ccode' }, { order_by => ['description'] } ) }; my $itemtypes = GetItemTypes(); my $Bsort1 = GetAuthorisedValues("Bsort1"); my $Bsort2 = GetAuthorisedValues("Bsort2"); --- a/t/db_dependent/AuthorisedValues.t +++ a/t/db_dependent/AuthorisedValues.t @@ -119,7 +119,7 @@ is( $categories[0], $av4->category, 'The first category should be correct (order is( $categories[1], $av1->category, 'The second category should be correct (ordered by category name)' ); subtest 'search_by_*_field + find_by_koha_field + get_description' => sub { - plan tests => 4; + plan tests => 5; my $loc_cat = Koha::AuthorisedValueCategories->find('LOC'); $loc_cat->delete if $loc_cat; my $mss = Koha::MarcSubfieldStructures->search( { tagfield => 952, tagsubfield => 'c', frameworkcode => '' } ); @@ -200,4 +200,23 @@ subtest 'search_by_*_field + find_by_koha_field + get_description' => sub { { kohafield => 'items.restricted', authorised_value => undef } ); is_deeply( $descriptions, {}, ) ; # This could be arguable, we could return undef instead }; + subtest 'get_descriptions_by_koha_field' => sub { + plan tests => 1; + my @descriptions = Koha::AuthorisedValues->get_descriptions_by_koha_field( { kohafield => 'items.restricted' } ); + is_deeply( + \@descriptions, + [ + { + authorised_value => '', + lib => $av_empty_string->lib, + opac_description => $av_empty_string->lib_opac + }, + { + authorised_value => $av_0->authorised_value, + lib => $av_0->lib, + opac_description => $av_0->lib_opac + } + ], + ); + }; }; --