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

(-)a/C4/Biblio.pm (-19 / +5 lines)
Lines 1435-1459 sub GetAuthorisedValueDesc { Link Here
1435
    my $dbh = C4::Context->dbh;
1435
    my $dbh = C4::Context->dbh;
1436
    if ( $category ne "" ) {
1436
    if ( $category ne "" ) {
1437
        my $cache     = Koha::Caches->get_instance();
1437
        my $cache     = Koha::Caches->get_instance();
1438
        my $cache_key = "AV_descriptions:" . $category;
1438
        my $av = Koha::AuthorisedValue->get_from_cache($category, $value);
1439
        my $av_descriptions = $cache->get_from_cache( $cache_key, { unsafe => 1 } );
1439
        return db_t(
1440
        if ( !$av_descriptions ) {
1440
            'authorised_value:' . $category,
1441
            $av_descriptions = {
1441
            $opac ? $av->{translation_key_opac} : $av->{translation_key_staff}
1442
                map {
1442
        );
1443
                    $_->authorised_value =>
1444
                      { lib => $_->lib, lib_opac => $_->lib_opac }
1445
                } Koha::AuthorisedValues->search(
1446
                    { category => $category },
1447
                    {
1448
                        columns => [ 'authorised_value', 'lib_opac', 'lib' ]
1449
                    }
1450
                )->as_list
1451
            };
1452
            $cache->set_in_cache($cache_key, $av_descriptions);
1453
        }
1454
        return ( $opac && $av_descriptions->{$value}->{'lib_opac'} )
1455
          ? $av_descriptions->{$value}->{'lib_opac'}
1456
          : $av_descriptions->{$value}->{'lib'};
1457
    } else {
1443
    } else {
1458
        return $value;    # if nothing is found return the original value
1444
        return $value;    # if nothing is found return the original value
1459
    }
1445
    }
(-)a/Koha/AuthorisedValue.pm (+36 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use Koha::Caches;
22
use Koha::Caches;
23
use Koha::Database;
23
use Koha::Database;
24
24
25
use Koha::I18N;
26
25
use base qw(Koha::Object Koha::Object::Limit::Library);
27
use base qw(Koha::Object Koha::Object::Limit::Library);
26
28
27
my $cache = Koha::Caches->get_instance();
29
my $cache = Koha::Caches->get_instance();
Lines 83-88 sub delete { Link Here
83
    $self->SUPER::delete(@_);
85
    $self->SUPER::delete(@_);
84
}
86
}
85
87
88
=head3 translation_description
89
90
  my $translated_description = $av->translated_description;
91
92
Returns a localized string for the Koha::AuthorisedValue lib or lib_opac field.
93
94
=cut
95
96
sub translated_description {
97
    my ( $self, $interface ) = @_;
98
    return db_t(sprintf('authorised_value:%s', $self->category), $self->translation_key);
99
}
100
101
=head3 translation_key
102
103
   db_t('authorised_value', $av->translation_key);
104
105
Returns the translation key for this authorised value object.
106
107
=cut
108
109
sub translation_key {
110
    my ( $self, $interface ) = @_;
111
    return sprintf "%s:%s", $self->authorised_value, ( $interface || 'opac' );
112
}
113
114
sub get_from_cache {
115
    my ( $class, $category, $av ) = @_;
116
    my @avs = @{Koha::AuthorisedValues->get_from_cache($category)};
117
    # FIXME Maybe we should store a hashref instead of an array
118
    my ( $cached ) = grep {($_->{authorised_value} eq $av) ? $_ : ()} @avs;
119
    return $cached;
120
}
121
86
=head3 opac_description
122
=head3 opac_description
87
123
88
my $description = $av->opac_description();
124
my $description = $av->opac_description();
(-)a/Koha/AuthorisedValues.pm (-4 / +52 lines)
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 );
(-)a/Koha/Schema/Result/AuthorisedValue.pm (-3 / +3 lines)
Lines 185-191 sub insert { Link Here
185
185
186
    my $group = sprintf('authorised_value:%s', $self->get_column('category'));
186
    my $group = sprintf('authorised_value:%s', $self->get_column('category'));
187
    $self->update_l10n_source( $group,
187
    $self->update_l10n_source( $group,
188
        $self->authorised_value . ':intranet',
188
        $self->authorised_value . ':staff',
189
        $self->lib );
189
        $self->lib );
190
    $self->update_l10n_source( $group,
190
    $self->update_l10n_source( $group,
191
        $self->authorised_value . ':opac',
191
        $self->authorised_value . ':opac',
Lines 205-211 sub update { Link Here
205
    my $group = sprintf('authorised_value:%s', $self->get_column('category'));
205
    my $group = sprintf('authorised_value:%s', $self->get_column('category'));
206
    if ($is_lib_changed) {
206
    if ($is_lib_changed) {
207
        $self->update_l10n_source( $group,
207
        $self->update_l10n_source( $group,
208
            $self->authorised_value . ':intranet',
208
            $self->authorised_value . ':staff',
209
            $self->lib );
209
            $self->lib );
210
    }
210
    }
211
    if ($is_lib_opac_changed) {
211
    if ($is_lib_opac_changed) {
Lines 223-229 sub delete { Link Here
223
    my $result = $self->next::method(@_);
223
    my $result = $self->next::method(@_);
224
224
225
    my $group = sprintf('authorised_value:%s', $self->get_column('category'));
225
    my $group = sprintf('authorised_value:%s', $self->get_column('category'));
226
    $self->delete_l10n_source($group, sprintf('%s:intranet', $self->authorised_value));
226
    $self->delete_l10n_source($group, sprintf('%s:staff', $self->authorised_value));
227
    $self->delete_l10n_source($group, sprintf('%s:opac', $self->authorised_value));
227
    $self->delete_l10n_source($group, sprintf('%s:opac', $self->authorised_value));
228
228
229
    return $result;
229
    return $result;
(-)a/Koha/UI/Form/Builder/Item.pm (-4 / +5 lines)
Lines 189-198 sub generate_subfield_form { Link Here
189
            $subfield_data{IS_LOST_AV} = 1;
189
            $subfield_data{IS_LOST_AV} = 1;
190
190
191
            push @authorised_values, qq{};
191
            push @authorised_values, qq{};
192
            my $av = GetAuthorisedValues( $subfield->{authorised_value} );
192
            my $avs = Koha::AuthorisedValues->get_from_cache({ library_limit => $branch_limit });
193
            for my $r (@$av) {
193
            for my $av (@$avs) {
194
                push @authorised_values, $r->{authorised_value};
194
                push @authorised_values, $av->{authorised_value};
195
                $authorised_lib{ $r->{authorised_value} } = $r->{lib};
195
                $authorised_lib{ $av->{authorised_value} } =
196
                  db_t('authorised_value', $av->{translation_key});
196
            }
197
            }
197
        }
198
        }
198
        elsif ( $subfield->{authorised_value} eq "branches" ) {
199
        elsif ( $subfield->{authorised_value} eq "branches" ) {
(-)a/installer/data/mysql/atomicupdate/bug-24977.perl (-2 / +1 lines)
Lines 2-8 $DBversion = 'XXX'; Link Here
2
if( CheckVersion( $DBversion ) ) {
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do(q{
3
    $dbh->do(q{
4
        INSERT IGNORE INTO l10n_source (`group`, `key`, `text`)
4
        INSERT IGNORE INTO l10n_source (`group`, `key`, `text`)
5
        SELECT DISTINCT CONCAT('authorised_value:', category), CONCAT(authorised_value, ':intranet'), lib FROM authorised_values WHERE lib IS NOT NULL AND lib != ''
5
        SELECT DISTINCT CONCAT('authorised_value:', category), CONCAT(authorised_value, ':staff'), lib FROM authorised_values WHERE lib IS NOT NULL AND lib != ''
6
        UNION
6
        UNION
7
        SELECT DISTINCT CONCAT('authorised_value:', category), CONCAT(authorised_value, ':opac'), lib_opac FROM authorised_values WHERE lib_opac IS NOT NULL AND lib_opac != ''
7
        SELECT DISTINCT CONCAT('authorised_value:', category), CONCAT(authorised_value, ':opac'), lib_opac FROM authorised_values WHERE lib_opac IS NOT NULL AND lib_opac != ''
8
    });
8
    });
9
- 

Return to bug 24977