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 83-91
BEGIN {
Link Here
|
83 |
@EXPORT_OK = qw( GetDailyQuote ); |
83 |
@EXPORT_OK = qw( GetDailyQuote ); |
84 |
} |
84 |
} |
85 |
|
85 |
|
86 |
# expensive functions |
|
|
87 |
memoize('GetAuthorisedValues'); |
88 |
|
89 |
=head1 NAME |
86 |
=head1 NAME |
90 |
|
87 |
|
91 |
C4::Koha - Perl Module containing convenience functions for Koha scripts |
88 |
C4::Koha - Perl Module containing convenience functions for Koha scripts |
Lines 1126-1138
This function returns all authorised values from the'authorised_value' table in
Link Here
|
1126 |
|
1123 |
|
1127 |
C<$category> returns authorised values for just one category (optional). |
1124 |
C<$category> returns authorised values for just one category (optional). |
1128 |
|
1125 |
|
|
|
1126 |
C<$selected> adds a "selected => 1" entry to the hash if the |
1127 |
authorised_value matches it. B<NOTE:> this feature should be considered |
1128 |
deprecated as it may be removed in the future. |
1129 |
|
1129 |
C<$opac> If set to a true value, displays OPAC descriptions rather than normal ones when they exist. |
1130 |
C<$opac> If set to a true value, displays OPAC descriptions rather than normal ones when they exist. |
1130 |
|
1131 |
|
1131 |
=cut |
1132 |
=cut |
1132 |
|
1133 |
|
1133 |
sub GetAuthorisedValues { |
1134 |
sub GetAuthorisedValues { |
1134 |
my ( $category, $selected, $opac ) = @_; |
1135 |
my ( $category, $selected, $opac ) = @_; |
1135 |
my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; |
1136 |
|
|
|
1137 |
# TODO: the "selected" feature should be replaced by a utility function |
1138 |
# somewhere else, it doesn't belong in here. For starters it makes |
1139 |
# caching much more complicated. Or just let the UI logic handle it, it's |
1140 |
# what it's for. |
1141 |
|
1142 |
# Is this cached already? |
1143 |
$opac = $opac ? 1 : 0; # normalise to be safe |
1144 |
my $selected_key = defined($selected) ? $selected : ''; |
1145 |
my $cache_key = "AuthorisedValues-$category-$selected_key-$opac"; |
1146 |
my $cache = Koha::Cache->get_instance(); |
1147 |
my $result = $cache->get_from_cache($cache_key); |
1148 |
warn "fetched $result from cache"; |
1149 |
return $result if $result; |
1150 |
|
1151 |
my $branch_limit = |
1152 |
C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; |
1136 |
my @results; |
1153 |
my @results; |
1137 |
my $dbh = C4::Context->dbh; |
1154 |
my $dbh = C4::Context->dbh; |
1138 |
my $query = qq{ |
1155 |
my $query = qq{ |
Lines 1178-1183
sub GetAuthorisedValues {
Link Here
|
1178 |
push @results, $data; |
1195 |
push @results, $data; |
1179 |
} |
1196 |
} |
1180 |
$sth->finish; |
1197 |
$sth->finish; |
|
|
1198 |
|
1199 |
# We can't cache for long because of that "selected" thing which |
1200 |
# makes it impossible to clear the cache without iterating through every |
1201 |
# value, which sucks. This'll cover this request, and not a whole lot more. |
1202 |
$cache->set_in_cache( $cache_key, \@results, { deepcopy => 1, expiry => 5 } ); |
1181 |
return \@results; |
1203 |
return \@results; |
1182 |
} |
1204 |
} |
1183 |
|
1205 |
|
1184 |
- |
|
|