|
Lines 23-31
use Koha::Database;
Link Here
|
| 23 |
|
23 |
|
| 24 |
use Koha::AuthorisedValue; |
24 |
use Koha::AuthorisedValue; |
| 25 |
use Koha::MarcSubfieldStructures; |
25 |
use Koha::MarcSubfieldStructures; |
| 26 |
use Koha::Cache::Memory::Lite; |
|
|
| 27 |
|
26 |
|
| 28 |
use base qw(Koha::Objects Koha::Objects::Limit::Library); |
27 |
use base qw(Koha::Objects::Cached Koha::Objects::Limit::Library); |
| 29 |
|
28 |
|
| 30 |
=head1 NAME |
29 |
=head1 NAME |
| 31 |
|
30 |
|
|
Lines 115-121
sub find_by_koha_field {
Link Here
|
| 115 |
distinct => 1, |
114 |
distinct => 1, |
| 116 |
} |
115 |
} |
| 117 |
); |
116 |
); |
| 118 |
return $av->count ? $av->next : undef; |
117 |
return $av->next; |
| 119 |
} |
118 |
} |
| 120 |
|
119 |
|
| 121 |
=head2 get_description_by_koha_field |
120 |
=head2 get_description_by_koha_field |
|
Lines 126-150
Missing POD for get_description_by_koha_field.
Link Here
|
| 126 |
|
125 |
|
| 127 |
sub get_description_by_koha_field { |
126 |
sub get_description_by_koha_field { |
| 128 |
my ( $self, $params ) = @_; |
127 |
my ( $self, $params ) = @_; |
| 129 |
my $frameworkcode = $params->{frameworkcode} || ''; |
128 |
$params->{frameworkcode} //= ''; |
| 130 |
my $kohafield = $params->{kohafield}; |
|
|
| 131 |
my $authorised_value = $params->{authorised_value}; |
| 132 |
|
129 |
|
| 133 |
return {} unless defined $authorised_value; |
130 |
return {} unless defined $params->{authorised_value}; |
| 134 |
|
|
|
| 135 |
my $memory_cache = Koha::Cache::Memory::Lite->get_instance; |
| 136 |
my $cache_key = "AV_descriptions:$frameworkcode:$kohafield:$authorised_value"; |
| 137 |
my $cached = $memory_cache->get_from_cache($cache_key); |
| 138 |
return $cached if $cached; |
| 139 |
|
131 |
|
| 140 |
my $av = $self->find_by_koha_field($params); |
132 |
my $av = $self->find_by_koha_field($params); |
| 141 |
if ( !defined $av ) { |
133 |
return defined $av ? { lib => $av->lib, opac_description => $av->opac_description } : {}; |
| 142 |
$memory_cache->set_in_cache( $cache_key, {} ); |
|
|
| 143 |
return {}; |
| 144 |
} |
| 145 |
my $descriptions = { lib => $av->lib, opac_description => $av->opac_description }; |
| 146 |
$memory_cache->set_in_cache( $cache_key, $descriptions ); |
| 147 |
return $descriptions; |
| 148 |
} |
134 |
} |
| 149 |
|
135 |
|
| 150 |
=head2 get_descriptions_by_koha_field |
136 |
=head2 get_descriptions_by_koha_field |
|
Lines 155-178
Missing POD for get_descriptions_by_koha_field.
Link Here
|
| 155 |
|
141 |
|
| 156 |
sub get_descriptions_by_koha_field { |
142 |
sub get_descriptions_by_koha_field { |
| 157 |
my ( $self, $params ) = @_; |
143 |
my ( $self, $params ) = @_; |
| 158 |
my $frameworkcode = $params->{frameworkcode} || ''; |
144 |
$params->{frameworkcode} //= ''; |
| 159 |
my $kohafield = $params->{kohafield}; |
|
|
| 160 |
|
| 161 |
my $memory_cache = Koha::Cache::Memory::Lite->get_instance; |
| 162 |
my $cache_key = "AV_descriptions:$frameworkcode:$kohafield"; |
| 163 |
my $cached = $memory_cache->get_from_cache($cache_key); |
| 164 |
return @$cached if $cached; |
| 165 |
|
145 |
|
| 166 |
my @avs = $self->search_by_koha_field($params)->as_list; |
146 |
my @avs = $self->search_by_koha_field($params)->as_list; |
| 167 |
my @descriptions = map { |
147 |
my $descriptions = [ |
|
|
148 |
map { |
| 149 |
{ |
| 150 |
authorised_value => $_->authorised_value, |
| 151 |
lib => $_->lib, |
| 152 |
opac_description => $_->opac_description |
| 153 |
} |
| 154 |
} @avs |
| 155 |
]; |
| 156 |
return @{$descriptions}; |
| 157 |
} |
| 158 |
|
| 159 |
sub get_description_by_category_and_authorised_value { |
| 160 |
my ( $self, $params ) = @_; |
| 161 |
return unless defined $params->{category} and defined $params->{authorised_value}; |
| 162 |
|
| 163 |
my $av = $self->search( |
| 168 |
{ |
164 |
{ |
| 169 |
authorised_value => $_->authorised_value, |
165 |
category => $params->{category}, |
| 170 |
lib => $_->lib, |
166 |
authorised_value => $params->{authorised_value}, |
| 171 |
opac_description => $_->opac_description |
|
|
| 172 |
} |
167 |
} |
| 173 |
} @avs; |
168 |
)->next; |
| 174 |
$memory_cache->set_in_cache( $cache_key, \@descriptions ); |
169 |
|
| 175 |
return @descriptions; |
170 |
return $av |
|
|
171 |
? { |
| 172 |
lib => $av->lib, |
| 173 |
opac_description => $av->opac_description |
| 174 |
} |
| 175 |
: {}; |
| 176 |
} |
176 |
} |
| 177 |
|
177 |
|
| 178 |
=head3 get_descriptions_by_marc_field |
178 |
=head3 get_descriptions_by_marc_field |
|
Lines 183-209
sub get_descriptions_by_koha_field {
Link Here
|
| 183 |
|
183 |
|
| 184 |
sub get_descriptions_by_marc_field { |
184 |
sub get_descriptions_by_marc_field { |
| 185 |
my ( $self, $params ) = @_; |
185 |
my ( $self, $params ) = @_; |
| 186 |
my $frameworkcode = $params->{frameworkcode} || ''; |
186 |
$params->{frameworkcode} //= ''; |
| 187 |
my $tagfield = $params->{tagfield}; |
|
|
| 188 |
my $tagsubfield = $params->{tagsubfield}; |
| 189 |
|
187 |
|
| 190 |
return {} unless defined $params->{tagfield}; |
188 |
return {} unless defined $params->{tagfield}; |
| 191 |
|
189 |
|
| 192 |
my $memory_cache = Koha::Cache::Memory::Lite->get_instance; |
|
|
| 193 |
my $cache_key = "AV_descriptions_by_MARC:$frameworkcode:$tagfield"; |
| 194 |
if ($tagsubfield) { |
| 195 |
$cache_key .= ":$tagsubfield"; |
| 196 |
} |
| 197 |
|
| 198 |
my $cached = $memory_cache->get_from_cache($cache_key); |
| 199 |
return $cached if $cached; |
| 200 |
|
| 201 |
my $descriptions = {}; |
190 |
my $descriptions = {}; |
| 202 |
my @avs = $self->search_by_marc_field($params)->as_list; |
191 |
my @avs = $self->search_by_marc_field($params)->as_list; |
| 203 |
foreach my $av (@avs) { |
192 |
foreach my $av (@avs) { |
| 204 |
$descriptions->{ $av->authorised_value } = $av->lib; |
193 |
$descriptions->{ $av->authorised_value } = $av->lib; |
| 205 |
} |
194 |
} |
| 206 |
$memory_cache->set_in_cache( $cache_key, $descriptions ); |
|
|
| 207 |
return $descriptions; |
195 |
return $descriptions; |
| 208 |
} |
196 |
} |
| 209 |
|
197 |
|