Lines 998-1032
sub GetAuthValCodeFromField {
Link Here
|
998 |
|
998 |
|
999 |
=head2 GetAuthorisedValues |
999 |
=head2 GetAuthorisedValues |
1000 |
|
1000 |
|
1001 |
$authvalues = GetAuthorisedValues([$category], [$selected]); |
1001 |
$authvalues = GetAuthorisedValues([$category]); |
1002 |
|
1002 |
|
1003 |
This function returns all authorised values from the'authorised_value' table in a reference to array of hashrefs. |
1003 |
This function returns all authorised values from the'authorised_value' table in a reference to array of hashrefs. |
1004 |
|
1004 |
|
1005 |
C<$category> returns authorised values for just one category (optional). |
1005 |
C<$category> returns authorised values for just one category (optional). |
1006 |
|
1006 |
|
1007 |
C<$selected> adds a "selected => 1" entry to the hash if the |
|
|
1008 |
authorised_value matches it. B<NOTE:> this feature should be considered |
1009 |
deprecated as it may be removed in the future. |
1010 |
|
1011 |
C<$opac> If set to a true value, displays OPAC descriptions rather than normal ones when they exist. |
1007 |
C<$opac> If set to a true value, displays OPAC descriptions rather than normal ones when they exist. |
1012 |
|
1008 |
|
1013 |
=cut |
1009 |
=cut |
1014 |
|
1010 |
|
1015 |
sub GetAuthorisedValues { |
1011 |
sub GetAuthorisedValues { |
1016 |
my ( $category, $selected, $opac ) = @_; |
1012 |
my ( $category, $opac ) = @_; |
1017 |
|
|
|
1018 |
# TODO: the "selected" feature should be replaced by a utility function |
1019 |
# somewhere else, it doesn't belong in here. For starters it makes |
1020 |
# caching much more complicated. Or just let the UI logic handle it, it's |
1021 |
# what it's for. |
1022 |
|
1013 |
|
1023 |
# Is this cached already? |
1014 |
# Is this cached already? |
1024 |
$opac = $opac ? 1 : 0; # normalise to be safe |
1015 |
$opac = $opac ? 1 : 0; # normalise to be safe |
1025 |
my $branch_limit = |
1016 |
my $branch_limit = |
1026 |
C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; |
1017 |
C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; |
1027 |
my $selected_key = defined($selected) ? $selected : ''; |
|
|
1028 |
my $cache_key = |
1018 |
my $cache_key = |
1029 |
"AuthorisedValues-$category-$selected_key-$opac-$branch_limit"; |
1019 |
"AuthorisedValues-$category-$opac-$branch_limit"; |
1030 |
my $cache = Koha::Cache->get_instance(); |
1020 |
my $cache = Koha::Cache->get_instance(); |
1031 |
my $result = $cache->get_from_cache($cache_key); |
1021 |
my $result = $cache->get_from_cache($cache_key); |
1032 |
return $result if $result; |
1022 |
return $result if $result; |
Lines 1063-1075
sub GetAuthorisedValues {
Link Here
|
1063 |
|
1053 |
|
1064 |
$sth->execute( @where_args ); |
1054 |
$sth->execute( @where_args ); |
1065 |
while (my $data=$sth->fetchrow_hashref) { |
1055 |
while (my $data=$sth->fetchrow_hashref) { |
1066 |
if ( defined $selected and $selected eq $data->{authorised_value} ) { |
|
|
1067 |
$data->{selected} = 1; |
1068 |
} |
1069 |
else { |
1070 |
$data->{selected} = 0; |
1071 |
} |
1072 |
|
1073 |
if ($opac && $data->{lib_opac}) { |
1056 |
if ($opac && $data->{lib_opac}) { |
1074 |
$data->{lib} = $data->{lib_opac}; |
1057 |
$data->{lib} = $data->{lib_opac}; |
1075 |
} |
1058 |
} |
Lines 1077-1085
sub GetAuthorisedValues {
Link Here
|
1077 |
} |
1060 |
} |
1078 |
$sth->finish; |
1061 |
$sth->finish; |
1079 |
|
1062 |
|
1080 |
# We can't cache for long because of that "selected" thing which |
|
|
1081 |
# makes it impossible to clear the cache without iterating through every |
1082 |
# value, which sucks. This'll cover this request, and not a whole lot more. |
1083 |
$cache->set_in_cache( $cache_key, \@results, { deepcopy => 1, expiry => 5 } ); |
1063 |
$cache->set_in_cache( $cache_key, \@results, { deepcopy => 1, expiry => 5 } ); |
1084 |
return \@results; |
1064 |
return \@results; |
1085 |
} |
1065 |
} |