View | Details | Raw Unified | Return to bug 20307
Collapse All | Expand All

(-)a/C4/Items.pm (-2 / +2 lines)
Lines 1086-1093 sub GetItemsLocationInfo { Link Here
1086
        while ( my $data = $sth->fetchrow_hashref ) {
1086
        while ( my $data = $sth->fetchrow_hashref ) {
1087
             my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $data->{location} });
1087
             my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $data->{location} });
1088
             $av = $av->count ? $av->next : undef;
1088
             $av = $av->count ? $av->next : undef;
1089
             $data->{location_intranet} = $av ? $av->lib : '';
1089
             $data->{location_intranet} = $av ? $av->translated_description : '';
1090
             $data->{location_opac}     = $av ? $av->opac_description : '';
1090
             $data->{location_opac}     = $av ? $av->opac_translated_description : '';
1091
	     push @results, $data;
1091
	     push @results, $data;
1092
	}
1092
	}
1093
	return @results;
1093
	return @results;
(-)a/C4/Koha.pm (-3 / +3 lines)
Lines 547-553 sub GetAuthorisedValues { Link Here
547
    my $result = $cache->get_from_cache($cache_key);
547
    my $result = $cache->get_from_cache($cache_key);
548
    return $result if $result;
548
    return $result if $result;
549
549
550
    # FIXME Need to deal with $opac
551
    my $avs = Koha::AuthorisedValues->search_with_localization(
550
    my $avs = Koha::AuthorisedValues->search_with_localization(
552
        {
551
        {
553
            ( $category ? ( category => $category ) : () ),
552
            ( $category ? ( category => $category ) : () ),
Lines 558-565 sub GetAuthorisedValues { Link Here
558
    while ( my $av = $avs->next ) {
557
    while ( my $av = $avs->next ) {
559
        my $av_unblessed = $av->unblessed;
558
        my $av_unblessed = $av->unblessed;
560
        $av_unblessed->{translated_description} = $av->translated_description;
559
        $av_unblessed->{translated_description} = $av->translated_description;
561
        $av_unblessed->{lib} = $av->translated_description;
560
        $av_unblessed->{opac_translated_description} = $av->opac_translated_description;
562
        $av_unblessed->{lib_opac} = $av->translated_description;
561
        $av_unblessed->{lib} = $av->lib;
562
        $av_unblessed->{lib_opac} = $av->lib_opac;
563
        push @results, $av_unblessed;
563
        push @results, $av_unblessed;
564
564
565
    }
565
    }
(-)a/C4/Search.pm (-4 / +4 lines)
Lines 574-588 sub getRecords { Link Here
574
           # also, if it's a location code, use the name instead of the code
574
           # also, if it's a location code, use the name instead of the code
575
                            if ( $link_value =~ /location/ ) {
575
                            if ( $link_value =~ /location/ ) {
576
                                # TODO Retrieve all authorised values at once, instead of 1 query per entry
576
                                # TODO Retrieve all authorised values at once, instead of 1 query per entry
577
                                my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $one_facet });
577
                                my $av = Koha::AuthorisedValues->search_with_localization({ category => 'LOC', authorised_value => $one_facet });
578
                                $facet_label_value = $av->count ? $av->next->opac_description : '';
578
                                $facet_label_value = $av->count ? $av->next->opac_translated_description : ''; # FIXME: Why are we displaying the opac description for staff?
579
                            }
579
                            }
580
580
581
                            # also, if it's a collection code, use the name instead of the code
581
                            # also, if it's a collection code, use the name instead of the code
582
                            if ( $link_value =~ /ccode/ ) {
582
                            if ( $link_value =~ /ccode/ ) {
583
                                # TODO Retrieve all authorised values at once, instead of 1 query per entry
583
                                # TODO Retrieve all authorised values at once, instead of 1 query per entry
584
                                my $av = Koha::AuthorisedValues->search({ category => 'CCODE', authorised_value => $one_facet });
584
                                my $av = Koha::AuthorisedValues->search_with_localization({ category => 'CCODE', authorised_value => $one_facet });
585
                                $facet_label_value = $av->count ? $av->next->opac_description : '';
585
                                $facet_label_value = $av->count ? $av->next->opac_translated_description : '';
586
                            }
586
                            }
587
587
588
            # but we're down with the whole label being in the link's title.
588
            # but we're down with the whole label being in the link's title.
(-)a/Koha/AuthorisedValue.pm (-1 / +27 lines)
Lines 145-150 sub opac_description { Link Here
145
    return $self->lib_opac() || $self->lib();
145
    return $self->lib_opac() || $self->lib();
146
}
146
}
147
147
148
=head3 opac_translated_description
149
150
=cut
151
152
sub opac_translated_description {
153
    my ( $self, $lang ) = @_;
154
    if ( my $translated_description = eval { $self->get_column('opac_translated_description') } ) {
155
        # If the value has already been fetched (eg. from sarch_with_localization),
156
        # do not search for it again
157
        # Note: This is a bit hacky but should be fast
158
        return $translated_description
159
             ? $translated_description
160
             : $self->lib;
161
    }
162
    $lang ||= C4::Languages::getlanguage;
163
    my $translated_description = Koha::Localizations->search({
164
        code => $self->authorised_value,
165
        entity => 'avs',
166
        lang => $lang,
167
        interface => 'opac',
168
    })->next;
169
    return $translated_description
170
         ? $translated_description->translation
171
         : $self->translated_description; # FIXME Is that what we really want?
172
}
173
148
=head3 translated_description
174
=head3 translated_description
149
175
150
=cut
176
=cut
Lines 163-169 sub translated_description { Link Here
163
    my $translated_description = Koha::Localizations->search({
189
    my $translated_description = Koha::Localizations->search({
164
        code => $self->authorised_value,
190
        code => $self->authorised_value,
165
        entity => 'avs',
191
        entity => 'avs',
166
        lang => $lang
192
        lang => $lang,
167
    })->next;
193
    })->next;
168
    return $translated_description
194
    return $translated_description
169
         ? $translated_description->translation
195
         ? $translated_description->translation
(-)a/Koha/AuthorisedValues.pm (-9 / +17 lines)
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,     # Rename with opac_translated_description to avoid confusion
144
        opac_description => $av->opac_translated_description # Same with 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
(-)a/Koha/Template/Plugin/AuthorisedValues.pm (-4 / +4 lines)
Lines 29-36 sub GetByCode { Link Here
29
    my $av = Koha::AuthorisedValues->search({ category => $category, authorised_value => $code });
29
    my $av = Koha::AuthorisedValues->search({ category => $category, authorised_value => $code });
30
    return $av->count
30
    return $av->count
31
            ? $opac
31
            ? $opac
32
                ? $av->next->opac_description
32
                ? $av->next->opac_translated_description
33
                : $av->next->lib
33
                : $av->next->translated_description
34
            : $code;
34
            : $code;
35
}
35
}
36
36
Lines 83-90 sub GetDescriptionByKohaField { Link Here
83
    );
83
    );
84
    return %$av
84
    return %$av
85
            ? $params->{opac}
85
            ? $params->{opac}
86
                ? $av->{opac_description}
86
                ? $av->{opac_description} # Rename with opac_translated_description to avoid confusion
87
                : $av->{lib}
87
                : $av->{lib}              # Same with translated_description
88
            : ''; # Maybe we should return $params->{authorised_value}?
88
            : ''; # Maybe we should return $params->{authorised_value}?
89
89
90
}
90
}
(-)a/admin/authorised_values.pl (-1 / +1 lines)
Lines 224-230 if ( $op eq 'list' ) { Link Here
224
224
225
    $searchfield ||= $category_list[0];
225
    $searchfield ||= $category_list[0];
226
226
227
    my $avs_by_category = Koha::AuthorisedValues->search_with_localization( { category => $searchfield } );
227
    my $avs_by_category = Koha::AuthorisedValues->search( { category => $searchfield } );
228
228
229
    $template->param(
229
    $template->param(
230
        authorised_values => $avs_by_category,
230
        authorised_values => $avs_by_category,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt (-11 / +14 lines)
Lines 74-79 Link Here
74
        </li>
74
        </li>
75
        <li>
75
        <li>
76
            <label for="lib">Description: </label>
76
            <label for="lib">Description: </label>
77
            <input type="text" name="lib" id="lib" value="[% lib | html %]" maxlength="200" />
77
            [% IF can_be_translated %]
78
            [% IF can_be_translated %]
78
                <a href="/cgi-bin/koha/admin/localization.pl?entity=avs&code=[% authorised_value | uri %]&interface=intranet"" title="Translate description" rel="gb_page_center[600,500]"><i class="fa fa-pencil"></i> Translate into other languages</a>
79
                <a href="/cgi-bin/koha/admin/localization.pl?entity=avs&code=[% authorised_value | uri %]&interface=intranet"" title="Translate description" rel="gb_page_center[600,500]"><i class="fa fa-pencil"></i> Translate into other languages</a>
79
            [% END %]
80
            [% END %]
Lines 227-245 Link Here
227
    [% FOREACH av IN authorised_values %]
228
    [% FOREACH av IN authorised_values %]
228
    <tr>
229
    <tr>
229
        <td>[% av.authorised_value | html %]</td>
230
        <td>[% av.authorised_value | html %]</td>
230
        [% IF av.translated_descriptions.size %]
231
        <td>
231
            [% av.lib | html %] (default)<br/>
232
            [% IF av.translated_descriptions.size %]
232
            [% FOR description IN av.translated_descriptions %]
233
                [% av.lib | html %] (default)<br/>
233
                [% IF description.translation == av.translated_description %]
234
                [% FOR description IN av.translated_descriptions %]
234
                    <b>[% description.translation | html %]</b>
235
                    [% IF description.translation == av.translated_description %]
235
                [% ELSE %]
236
                        <b>[% description.translation | html %]</b>
236
                    [% description.translation | html %] ([% description.lang | html %])
237
                    [% ELSE %]
238
                        [% description.translation | html %] ([% description.lang | html %])
239
                    [% END %]
240
                    <br/>
237
                [% END %]
241
                [% END %]
238
                <br/>
242
            [% ELSE %]
243
                [% av.lib |html %]
239
            [% END %]
244
            [% END %]
240
        [% ELSE %]
245
        </td>
241
            [% av.lib |html %]
242
        [% END %]
243
246
244
        <td>[% av.lib_opac | html %]</td>
247
        <td>[% av.lib_opac | html %]</td>
245
        <td>[% IF ( av.imageurl ) %]<img src="[% av.imageurl | url %]" alt=""/>[% ELSE %]&nbsp;[% END %]</td>
248
        <td>[% IF ( av.imageurl ) %]<img src="[% av.imageurl | url %]" alt=""/>[% ELSE %]&nbsp;[% END %]</td>
(-)a/opac/opac-memberentry.pl (-1 / +1 lines)
Lines 617-623 sub GeneratePatronAttributesForm { Link Here
617
        my $av = Koha::AuthorisedValues->search(
617
        my $av = Koha::AuthorisedValues->search(
618
            { category => 'PA_CLASS', authorised_value => $class } );
618
            { category => 'PA_CLASS', authorised_value => $class } );
619
619
620
        my $lib = $av->count ? $av->next->opac_description : $class;
620
        my $lib = $av->count ? $av->next->opac_translated_description : $class;
621
621
622
        push @class_loop,
622
        push @class_loop,
623
            {
623
            {
(-)a/opac/opac-reserve.pl (-1 / +1 lines)
Lines 444-450 foreach my $biblioNum (@biblionumbers) { Link Here
444
    }
444
    }
445
445
446
    my @notforloan_avs = Koha::AuthorisedValues->search_by_koha_field({ kohafield => 'items.notforloan', frameworkcode => $frameworkcode });
446
    my @notforloan_avs = Koha::AuthorisedValues->search_by_koha_field({ kohafield => 'items.notforloan', frameworkcode => $frameworkcode });
447
    my $notforloan_label_of = { map { $_->authorised_value => $_->opac_description } @notforloan_avs };
447
    my $notforloan_label_of = { map { $_->authorised_value => $_->opac_translated_description } @notforloan_avs };
448
448
449
    $biblioLoopIter{itemLoop} = [];
449
    $biblioLoopIter{itemLoop} = [];
450
    my $numCopiesAvailable = 0;
450
    my $numCopiesAvailable = 0;
(-)a/opac/opac-suggestions.pl (-2 / +1 lines)
Lines 188-194 foreach my $suggestion(@$suggestions_loop) { Link Here
188
    }
188
    }
189
    if($suggestion->{'patronreason'}){
189
    if($suggestion->{'patronreason'}){
190
        my $av = Koha::AuthorisedValues->search({ category => 'OPAC_SUG', authorised_value => $suggestion->{patronreason} });
190
        my $av = Koha::AuthorisedValues->search({ category => 'OPAC_SUG', authorised_value => $suggestion->{patronreason} });
191
        $suggestion->{'patronreason'} = $av->count ? $av->next->opac_description : '';
191
        $suggestion->{'patronreason'} = $av->count ? $av->next->opac_translated_description : '';
192
    }
192
    }
193
}
193
}
194
194
195
- 

Return to bug 20307