|
Lines 1013-1018
C<$opac> If set to a true value, displays OPAC descriptions rather than normal o
Link Here
|
| 1013 |
|
1013 |
|
| 1014 |
=cut |
1014 |
=cut |
| 1015 |
|
1015 |
|
|
|
1016 |
sub _AddSelectedAuthVal { |
| 1017 |
my ( $authorised_values, $selected ) = @_; |
| 1018 |
foreach my $data ( @$authorised_values ) { |
| 1019 |
$data->{selected} = $selected eq $data->{authorised_value} ? 1 : 0; |
| 1020 |
} |
| 1021 |
} |
| 1022 |
|
| 1016 |
sub GetAuthorisedValues { |
1023 |
sub GetAuthorisedValues { |
| 1017 |
my ( $category, $selected, $opac ) = @_; |
1024 |
my ( $category, $selected, $opac ) = @_; |
| 1018 |
|
1025 |
|
|
Lines 1025-1036
sub GetAuthorisedValues {
Link Here
|
| 1025 |
$opac = $opac ? 1 : 0; # normalise to be safe |
1032 |
$opac = $opac ? 1 : 0; # normalise to be safe |
| 1026 |
my $branch_limit = |
1033 |
my $branch_limit = |
| 1027 |
C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; |
1034 |
C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; |
| 1028 |
my $selected_key = defined($selected) ? $selected : ''; |
|
|
| 1029 |
my $cache_key = |
1035 |
my $cache_key = |
| 1030 |
"AuthorisedValues-$category-$selected_key-$opac-$branch_limit"; |
1036 |
"AuthorisedValues-$category-$opac-$branch_limit"; |
| 1031 |
my $cache = Koha::Cache->get_instance(); |
1037 |
my $cache = Koha::Cache->get_instance(); |
| 1032 |
my $result = $cache->get_from_cache($cache_key); |
1038 |
my $result = $cache->get_from_cache($cache_key); |
| 1033 |
return $result if $result; |
1039 |
if ($result) { |
|
|
1040 |
_AddSelectedAuthVal( $result, $selected ) if defined $selected; |
| 1041 |
return $result; |
| 1042 |
} |
| 1034 |
|
1043 |
|
| 1035 |
my @results; |
1044 |
my @results; |
| 1036 |
my $dbh = C4::Context->dbh; |
1045 |
my $dbh = C4::Context->dbh; |
|
Lines 1064-1076
sub GetAuthorisedValues {
Link Here
|
| 1064 |
|
1073 |
|
| 1065 |
$sth->execute( @where_args ); |
1074 |
$sth->execute( @where_args ); |
| 1066 |
while (my $data=$sth->fetchrow_hashref) { |
1075 |
while (my $data=$sth->fetchrow_hashref) { |
| 1067 |
if ( defined $selected and $selected eq $data->{authorised_value} ) { |
|
|
| 1068 |
$data->{selected} = 1; |
| 1069 |
} |
| 1070 |
else { |
| 1071 |
$data->{selected} = 0; |
| 1072 |
} |
| 1073 |
|
| 1074 |
if ($opac && $data->{lib_opac}) { |
1076 |
if ($opac && $data->{lib_opac}) { |
| 1075 |
$data->{lib} = $data->{lib_opac}; |
1077 |
$data->{lib} = $data->{lib_opac}; |
| 1076 |
} |
1078 |
} |
|
Lines 1078-1087
sub GetAuthorisedValues {
Link Here
|
| 1078 |
} |
1080 |
} |
| 1079 |
$sth->finish; |
1081 |
$sth->finish; |
| 1080 |
|
1082 |
|
| 1081 |
# We can't cache for long because of that "selected" thing which |
1083 |
$cache->set_in_cache( $cache_key, \@results, { deepcopy => 1 } ); |
| 1082 |
# makes it impossible to clear the cache without iterating through every |
1084 |
_AddSelectedAuthVal( \@results, $selected ); |
| 1083 |
# value, which sucks. This'll cover this request, and not a whole lot more. |
|
|
| 1084 |
$cache->set_in_cache( $cache_key, \@results, { deepcopy => 1, expiry => 5 } ); |
| 1085 |
return \@results; |
1085 |
return \@results; |
| 1086 |
} |
1086 |
} |
| 1087 |
|
1087 |
|