Lines 25-32
use strict;
Link Here
|
25 |
|
25 |
|
26 |
use C4::Context; |
26 |
use C4::Context; |
27 |
use C4::Branch qw(GetBranchesCount); |
27 |
use C4::Branch qw(GetBranchesCount); |
|
|
28 |
use Koha::Cache; |
28 |
use Koha::DateUtils qw(dt_from_string); |
29 |
use Koha::DateUtils qw(dt_from_string); |
29 |
use Memoize; |
|
|
30 |
use DateTime::Format::MySQL; |
30 |
use DateTime::Format::MySQL; |
31 |
use Business::ISBN; |
31 |
use Business::ISBN; |
32 |
use autouse 'Data::Dumper' => qw(Dumper); |
32 |
use autouse 'Data::Dumper' => qw(Dumper); |
Lines 82-90
BEGIN {
Link Here
|
82 |
@EXPORT_OK = qw( GetDailyQuote ); |
82 |
@EXPORT_OK = qw( GetDailyQuote ); |
83 |
} |
83 |
} |
84 |
|
84 |
|
85 |
# expensive functions |
|
|
86 |
memoize('GetAuthorisedValues'); |
87 |
|
88 |
=head1 NAME |
85 |
=head1 NAME |
89 |
|
86 |
|
90 |
C4::Koha - Perl Module containing convenience functions for Koha scripts |
87 |
C4::Koha - Perl Module containing convenience functions for Koha scripts |
Lines 1071-1083
This function returns all authorised values from the'authorised_value' table in
Link Here
|
1071 |
|
1068 |
|
1072 |
C<$category> returns authorised values for just one category (optional). |
1069 |
C<$category> returns authorised values for just one category (optional). |
1073 |
|
1070 |
|
|
|
1071 |
C<$selected> adds a "selected => 1" entry to the hash if the |
1072 |
authorised_value matches it. B<NOTE:> this feature should be considered |
1073 |
deprecated as it may be removed in the future. |
1074 |
|
1074 |
C<$opac> If set to a true value, displays OPAC descriptions rather than normal ones when they exist. |
1075 |
C<$opac> If set to a true value, displays OPAC descriptions rather than normal ones when they exist. |
1075 |
|
1076 |
|
1076 |
=cut |
1077 |
=cut |
1077 |
|
1078 |
|
1078 |
sub GetAuthorisedValues { |
1079 |
sub GetAuthorisedValues { |
1079 |
my ( $category, $selected, $opac ) = @_; |
1080 |
my ( $category, $selected, $opac ) = @_; |
1080 |
my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; |
1081 |
|
|
|
1082 |
# TODO: the "selected" feature should be replaced by a utility function |
1083 |
# somewhere else, it doesn't belong in here. For starters it makes |
1084 |
# caching much more complicated. Or just let the UI logic handle it, it's |
1085 |
# what it's for. |
1086 |
|
1087 |
# Is this cached already? |
1088 |
$opac = $opac ? 1 : 0; # normalise to be safe |
1089 |
my $selected_key = defined($selected) ? $selected : ''; |
1090 |
my $cache_key = "AuthorisedValues-$category-$selected_key-$opac"; |
1091 |
my $cache = Koha::Cache->get_instance(); |
1092 |
my $result = $cache->get_from_cache($cache_key); |
1093 |
warn "fetched $result from cache"; |
1094 |
return $result if $result; |
1095 |
|
1096 |
my $branch_limit = |
1097 |
C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; |
1081 |
my @results; |
1098 |
my @results; |
1082 |
my $dbh = C4::Context->dbh; |
1099 |
my $dbh = C4::Context->dbh; |
1083 |
my $query = qq{ |
1100 |
my $query = qq{ |
Lines 1123-1128
sub GetAuthorisedValues {
Link Here
|
1123 |
push @results, $data; |
1140 |
push @results, $data; |
1124 |
} |
1141 |
} |
1125 |
$sth->finish; |
1142 |
$sth->finish; |
|
|
1143 |
|
1144 |
# We can't cache for long because of that "selected" thing which |
1145 |
# makes it impossible to clear the cache without iterating through every |
1146 |
# value, which sucks. This'll cover this request, and not a whole lot more. |
1147 |
$cache->set_in_cache( $cache_key, \@results, { deepcopy => 1, expiry => 5 } ); |
1126 |
return \@results; |
1148 |
return \@results; |
1127 |
} |
1149 |
} |
1128 |
|
1150 |
|
1129 |
- |
|
|