Lines 77-83
sub search_by_marc_field {
Link Here
|
77 |
|
77 |
|
78 |
return unless $tagfield or $tagsubfield; |
78 |
return unless $tagfield or $tagsubfield; |
79 |
|
79 |
|
80 |
return $self->SUPER::search( |
80 |
return $self->search_with_localization( |
81 |
{ 'marc_subfield_structures.frameworkcode' => $frameworkcode, |
81 |
{ 'marc_subfield_structures.frameworkcode' => $frameworkcode, |
82 |
( defined $tagfield ? ( 'marc_subfield_structures.tagfield' => $tagfield ) : () ), |
82 |
( defined $tagfield ? ( 'marc_subfield_structures.tagfield' => $tagfield ) : () ), |
83 |
( defined $tagsubfield ? ( 'marc_subfield_structures.tagsubfield' => $tagsubfield ) : () ), |
83 |
( defined $tagsubfield ? ( 'marc_subfield_structures.tagsubfield' => $tagsubfield ) : () ), |
Lines 94-100
sub search_by_koha_field {
Link Here
|
94 |
|
94 |
|
95 |
return unless $kohafield; |
95 |
return unless $kohafield; |
96 |
|
96 |
|
97 |
return $self->SUPER::search( |
97 |
return $self->search_with_localization( |
98 |
{ 'marc_subfield_structures.frameworkcode' => $frameworkcode, |
98 |
{ 'marc_subfield_structures.frameworkcode' => $frameworkcode, |
99 |
'marc_subfield_structures.kohafield' => $kohafield, |
99 |
'marc_subfield_structures.kohafield' => $kohafield, |
100 |
( defined $category ? ( category_name => $category ) : () ), |
100 |
( defined $category ? ( category_name => $category ) : () ), |
Lines 111-117
sub find_by_koha_field {
Link Here
|
111 |
my $kohafield = $params->{kohafield}; |
111 |
my $kohafield = $params->{kohafield}; |
112 |
my $authorised_value = $params->{authorised_value}; |
112 |
my $authorised_value = $params->{authorised_value}; |
113 |
|
113 |
|
114 |
my $av = $self->search( |
114 |
my $av = $self->search_with_localization( |
115 |
{ 'marc_subfield_structures.frameworkcode' => $frameworkcode, |
115 |
{ 'marc_subfield_structures.frameworkcode' => $frameworkcode, |
116 |
'marc_subfield_structures.kohafield' => $kohafield, |
116 |
'marc_subfield_structures.kohafield' => $kohafield, |
117 |
'me.authorised_value' => $authorised_value, |
117 |
'me.authorised_value' => $authorised_value, |
Lines 132-144
sub get_description_by_koha_field {
Link Here
|
132 |
return {} unless defined $authorised_value; |
132 |
return {} unless defined $authorised_value; |
133 |
|
133 |
|
134 |
my $memory_cache = Koha::Cache::Memory::Lite->get_instance; |
134 |
my $memory_cache = Koha::Cache::Memory::Lite->get_instance; |
135 |
my $cache_key = "AV_descriptions:$frameworkcode:$kohafield:$authorised_value"; |
135 |
my $language = C4::Languages::getlanguage(); |
|
|
136 |
my $cache_key = "AV_descriptions:$language:$frameworkcode:$kohafield:$authorised_value"; |
136 |
my $cached = $memory_cache->get_from_cache($cache_key); |
137 |
my $cached = $memory_cache->get_from_cache($cache_key); |
137 |
return $cached if $cached; |
138 |
return $cached if $cached; |
138 |
|
139 |
|
139 |
my $av = $self->find_by_koha_field($params); |
140 |
my $av = $self->find_by_koha_field($params); |
140 |
return {} unless defined $av; |
141 |
return {} unless defined $av; |
141 |
my $descriptions = { lib => $av->lib, opac_description => $av->opac_description }; |
142 |
my $descriptions = { |
|
|
143 |
lib => $av->translated_description, |
144 |
opac_description => $av->opac_translated_description, |
145 |
}; |
142 |
$memory_cache->set_in_cache( $cache_key, $descriptions ); |
146 |
$memory_cache->set_in_cache( $cache_key, $descriptions ); |
143 |
return $descriptions; |
147 |
return $descriptions; |
144 |
} |
148 |
} |
Lines 149-155
sub get_descriptions_by_koha_field {
Link Here
|
149 |
my $kohafield = $params->{kohafield}; |
153 |
my $kohafield = $params->{kohafield}; |
150 |
|
154 |
|
151 |
my $memory_cache = Koha::Cache::Memory::Lite->get_instance; |
155 |
my $memory_cache = Koha::Cache::Memory::Lite->get_instance; |
152 |
my $cache_key = "AV_descriptions:$frameworkcode:$kohafield"; |
156 |
my $language = C4::Languages::getlanguage(); |
|
|
157 |
my $cache_key = "AV_descriptions:$language:$frameworkcode:$kohafield"; |
153 |
my $cached = $memory_cache->get_from_cache($cache_key); |
158 |
my $cached = $memory_cache->get_from_cache($cache_key); |
154 |
return @$cached if $cached; |
159 |
return @$cached if $cached; |
155 |
|
160 |
|
Lines 157-164
sub get_descriptions_by_koha_field {
Link Here
|
157 |
my @descriptions = map { |
162 |
my @descriptions = map { |
158 |
{ |
163 |
{ |
159 |
authorised_value => $_->authorised_value, |
164 |
authorised_value => $_->authorised_value, |
160 |
lib => $_->lib, |
165 |
lib => $_->translated_description, |
161 |
opac_description => $_->opac_description |
166 |
opac_description => $_->opac_translated_description |
162 |
} |
167 |
} |
163 |
} @avs; |
168 |
} @avs; |
164 |
$memory_cache->set_in_cache( $cache_key, \@descriptions ); |
169 |
$memory_cache->set_in_cache( $cache_key, \@descriptions ); |
Lines 190-202
sub search_with_localization {
Link Here
|
190 |
my $language = C4::Languages::getlanguage(); |
195 |
my $language = C4::Languages::getlanguage(); |
191 |
$Koha::Schema::Result::AuthorisedValue::LANGUAGE = $language; |
196 |
$Koha::Schema::Result::AuthorisedValue::LANGUAGE = $language; |
192 |
$attributes->{order_by} = 'translated_description' unless exists $attributes->{order_by}; |
197 |
$attributes->{order_by} = 'translated_description' unless exists $attributes->{order_by}; |
193 |
$attributes->{join} = 'localization'; |
198 |
my @join = $attributes->{join} || (); |
|
|
199 |
push @join, 'localization'; |
200 |
my $join = { join => \@join }; |
194 |
$attributes->{'+select'} = [ |
201 |
$attributes->{'+select'} = [ |
195 |
{ |
202 |
{ |
196 |
coalesce => [qw( localization.translation me.lib )], |
203 |
coalesce => [qw( localization.translation me.lib )], |
197 |
-as => 'translated_description' |
204 |
-as => 'translated_description' |
198 |
} |
205 |
} |
199 |
]; |
206 |
]; |
|
|
207 |
$attributes = { %$attributes, %$join }; |
200 |
$self->search( $params, $attributes ); |
208 |
$self->search( $params, $attributes ); |
201 |
} |
209 |
} |
202 |
|
210 |
|