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 autouse 'Data::Dumper' => qw(Dumper); |
31 |
use autouse 'Data::Dumper' => qw(Dumper); |
32 |
use DBI qw(:sql_types); |
32 |
use DBI qw(:sql_types); |
Lines 77-85
BEGIN {
Link Here
|
77 |
@EXPORT_OK = qw( GetDailyQuote ); |
77 |
@EXPORT_OK = qw( GetDailyQuote ); |
78 |
} |
78 |
} |
79 |
|
79 |
|
80 |
# expensive functions |
|
|
81 |
memoize('GetAuthorisedValues'); |
82 |
|
83 |
=head1 NAME |
80 |
=head1 NAME |
84 |
|
81 |
|
85 |
C4::Koha - Perl Module containing convenience functions for Koha scripts |
82 |
C4::Koha - Perl Module containing convenience functions for Koha scripts |
Lines 1024-1036
This function returns all authorised values from the'authorised_value' table in
Link Here
|
1024 |
|
1021 |
|
1025 |
C<$category> returns authorised values for just one category (optional). |
1022 |
C<$category> returns authorised values for just one category (optional). |
1026 |
|
1023 |
|
|
|
1024 |
C<$selected> adds a "selected => 1" entry to the hash if the |
1025 |
authorised_value matches it. B<NOTE:> this feature should be considered |
1026 |
deprecated as it may be removed in the future. |
1027 |
|
1027 |
C<$opac> If set to a true value, displays OPAC descriptions rather than normal ones when they exist. |
1028 |
C<$opac> If set to a true value, displays OPAC descriptions rather than normal ones when they exist. |
1028 |
|
1029 |
|
1029 |
=cut |
1030 |
=cut |
1030 |
|
1031 |
|
1031 |
sub GetAuthorisedValues { |
1032 |
sub GetAuthorisedValues { |
1032 |
my ( $category, $selected, $opac ) = @_; |
1033 |
my ( $category, $selected, $opac ) = @_; |
1033 |
my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; |
1034 |
|
|
|
1035 |
# TODO: the "selected" feature should be replaced by a utility function |
1036 |
# somewhere else, it doesn't belong in here. For starters it makes |
1037 |
# caching much more complicated. Or just let the UI logic handle it, it's |
1038 |
# what it's for. |
1039 |
|
1040 |
# Is this cached already? |
1041 |
$opac = $opac ? 1 : 0; # normalise to be safe |
1042 |
my $selected_key = defined($selected) ? $selected : ''; |
1043 |
my $cache_key = "AuthorisedValues-$category-$selected_key-$opac"; |
1044 |
my $cache = Koha::Cache->get_instance(); |
1045 |
my $result = $cache->get_from_cache($cache_key); |
1046 |
warn "fetched $result from cache"; |
1047 |
return $result if $result; |
1048 |
|
1049 |
my $branch_limit = |
1050 |
C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; |
1034 |
my @results; |
1051 |
my @results; |
1035 |
my $dbh = C4::Context->dbh; |
1052 |
my $dbh = C4::Context->dbh; |
1036 |
my $query = qq{ |
1053 |
my $query = qq{ |
Lines 1076-1081
sub GetAuthorisedValues {
Link Here
|
1076 |
push @results, $data; |
1093 |
push @results, $data; |
1077 |
} |
1094 |
} |
1078 |
$sth->finish; |
1095 |
$sth->finish; |
|
|
1096 |
|
1097 |
# We can't cache for long because of that "selected" thing which |
1098 |
# makes it impossible to clear the cache without iterating through every |
1099 |
# value, which sucks. This'll cover this request, and not a whole lot more. |
1100 |
$cache->set_in_cache( $cache_key, \@results, { deepcopy => 1, expiry => 5 } ); |
1079 |
return \@results; |
1101 |
return \@results; |
1080 |
} |
1102 |
} |
1081 |
|
1103 |
|
1082 |
- |
|
|