|
Lines 39-44
Koha::AuthorisedValues - Koha Authorised value Object set class
Link Here
|
| 39 |
|
39 |
|
| 40 |
=cut |
40 |
=cut |
| 41 |
|
41 |
|
|
|
42 |
=head3 get_from_cache |
| 43 |
|
| 44 |
my $avs = Koha::AuthorisedValues->get_from_cache($category, [{ library_limit => $library_id } ]); |
| 45 |
|
| 46 |
Returns an array of hashrefs representing authorised values. |
| 47 |
|
| 48 |
A library_limit parameter can be passed to limit the result to a given library. |
| 49 |
|
| 50 |
The translation_key is added to the list of authorised value's attributes |
| 51 |
|
| 52 |
=cut |
| 53 |
|
| 54 |
sub get_from_cache { |
| 55 |
my ($self, $category, $params) = @_; |
| 56 |
|
| 57 |
my $library_limit = |
| 58 |
( $params && $params->{library_limit} ) |
| 59 |
? $params->{library_limit} || q{} |
| 60 |
: q{}; |
| 61 |
|
| 62 |
my $cache = Koha::Caches->get_instance('authorised_values'); |
| 63 |
my $cache_key = "AuthorisedValues:$category:$library_limit"; |
| 64 |
# FIXME Maybe we should pass unsafe here, for perf purpose, but too many callers |
| 65 |
# that could modify it |
| 66 |
my $cached = $cache->get_from_cache($cache_key); |
| 67 |
return $cached if $cached; |
| 68 |
|
| 69 |
my $avs = |
| 70 |
$library_limit |
| 71 |
? $self->search_with_library_limits( |
| 72 |
{ category => $category }, |
| 73 |
undef, |
| 74 |
$params->{library_limit} |
| 75 |
) |
| 76 |
: $self->search; |
| 77 |
|
| 78 |
return [ |
| 79 |
map { |
| 80 |
{ |
| 81 |
%{ $_->unblessed }, |
| 82 |
translation_key_opac => $_->translation_key('opac'), |
| 83 |
translation_key_staff => $_->translation_key('staff'), |
| 84 |
} |
| 85 |
} $avs->as_list |
| 86 |
]; |
| 87 |
} |
| 88 |
|
| 42 |
sub search_by_marc_field { |
89 |
sub search_by_marc_field { |
| 43 |
my ( $self, $params ) = @_; |
90 |
my ( $self, $params ) = @_; |
| 44 |
my $frameworkcode = $params->{frameworkcode} || ''; |
91 |
my $frameworkcode = $params->{frameworkcode} || ''; |
|
Lines 114-121
sub get_description_by_koha_field {
Link Here
|
| 114 |
return {} unless defined $av; |
161 |
return {} unless defined $av; |
| 115 |
my $l10n_group = 'authorised_value:' . $av->category; |
162 |
my $l10n_group = 'authorised_value:' . $av->category; |
| 116 |
my $descriptions = { |
163 |
my $descriptions = { |
| 117 |
lib => db_t($l10n_group, $av->lib), |
164 |
lib => db_t($l10n_group, $av->translation_key('staff')), |
| 118 |
opac_description => db_t($l10n_group, $av->opac_description), |
165 |
opac_description => db_t($l10n_group, $av->translation_key('opac')), |
| 119 |
}; |
166 |
}; |
| 120 |
$memory_cache->set_in_cache( $cache_key, $descriptions ); |
167 |
$memory_cache->set_in_cache( $cache_key, $descriptions ); |
| 121 |
return $descriptions; |
168 |
return $descriptions; |
|
Lines 133-142
sub get_descriptions_by_koha_field {
Link Here
|
| 133 |
|
180 |
|
| 134 |
my @avs = $self->search_by_koha_field($params)->as_list; |
181 |
my @avs = $self->search_by_koha_field($params)->as_list; |
| 135 |
my @descriptions = map { |
182 |
my @descriptions = map { |
|
|
183 |
my $l10n_group = 'authorised_value:' . $_->category; |
| 136 |
{ |
184 |
{ |
| 137 |
authorised_value => $_->authorised_value, |
185 |
authorised_value => $_->authorised_value, |
| 138 |
lib => db_t('authorised_value:' . $_->category, $_->lib), |
186 |
lib => db_t($l10n_group, $_->translation_key('staff')), |
| 139 |
opac_description => db_t('authorised_value:' . $_->category, $_->opac_description), |
187 |
opac_description => db_t($l10n_group, $_->translation_key('opac')), |
| 140 |
} |
188 |
} |
| 141 |
} @avs; |
189 |
} @avs; |
| 142 |
$memory_cache->set_in_cache( $cache_key, \@descriptions ); |
190 |
$memory_cache->set_in_cache( $cache_key, \@descriptions ); |