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

(-)a/C4/Serials.pm (-4 / +12 lines)
Lines 36-41 use C4::Biblio qw( GetMarcFromKohaField ModBiblio ); Link Here
36
use C4::Log qw( logaction );    # logaction
36
use C4::Log qw( logaction );    # logaction
37
use C4::Serials::Frequency qw( GetSubscriptionFrequency );
37
use C4::Serials::Frequency qw( GetSubscriptionFrequency );
38
use C4::Serials::Numberpattern;
38
use C4::Serials::Numberpattern;
39
use Koha::AdditionalFields;
39
use Koha::AdditionalFieldValues;
40
use Koha::AdditionalFieldValues;
40
use Koha::Biblios;
41
use Koha::Biblios;
41
use Koha::Serial;
42
use Koha::Serial;
Lines 617-630 sub SearchSubscriptions { Link Here
617
    $sth->execute(@where_args);
618
    $sth->execute(@where_args);
618
    my $results =  $sth->fetchall_arrayref( {} );
619
    my $results =  $sth->fetchall_arrayref( {} );
619
620
621
    my %additional_fields_by_id = map { $_->id => $_->name } Koha::AdditionalFields->search( { tablename => 'subscription' } )->as_list;
622
620
    for my $subscription ( @$results ) {
623
    for my $subscription ( @$results ) {
621
        $subscription->{cannotedit} = not can_edit_subscription( $subscription );
624
        $subscription->{cannotedit} = not can_edit_subscription( $subscription );
622
        $subscription->{cannotdisplay} = not can_show_subscription( $subscription );
625
        $subscription->{cannotdisplay} = not can_show_subscription( $subscription );
626
        my @additional_field_values = Koha::AdditionalFieldValues->search(
627
            {
628
                field_id => { -in => [ keys %additional_fields_by_id ] },
629
                record_id => $subscription->{subscriptionid}
630
            }
631
        )->as_list;
623
632
624
        my $subscription_object = Koha::Subscriptions->find($subscription->{subscriptionid});
633
        $subscription->{additional_fields} = {
625
        $subscription->{additional_fields} = { map { $_->field->name => $_->value }
634
            map { $additional_fields_by_id{$_->field_id} => $_->value } @additional_field_values
626
            $subscription_object->additional_field_values->as_list };
635
        };
627
628
    }
636
    }
629
637
630
    return @$results;
638
    return @$results;
(-)a/Koha/AuthorisedValues.pm (-21 / +52 lines)
Lines 93-99 sub find_by_koha_field { Link Here
93
            distinct => 1,
93
            distinct => 1,
94
        }
94
        }
95
    );
95
    );
96
    return $av->count ? $av->next : undef;
96
    return $av->next;
97
}
97
}
98
98
99
sub get_description_by_koha_field {
99
sub get_description_by_koha_field {
Lines 106-119 sub get_description_by_koha_field { Link Here
106
106
107
    my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
107
    my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
108
    my $cache_key    = "AV_descriptions:$frameworkcode:$kohafield:$authorised_value";
108
    my $cache_key    = "AV_descriptions:$frameworkcode:$kohafield:$authorised_value";
109
    my $cached       = $memory_cache->get_from_cache($cache_key);
109
    my $description = $memory_cache->get_from_cache($cache_key);
110
    return $cached if $cached;
110
111
111
    unless (defined $description) {
112
    my $av = $self->find_by_koha_field($params);
112
        my $av = $self->find_by_koha_field($params);
113
    return {} unless defined $av;
113
        $description = defined $av ? { lib => $av->lib, opac_description => $av->opac_description } : {};
114
    my $descriptions = { lib => $av->lib, opac_description => $av->opac_description };
114
        $memory_cache->set_in_cache( $cache_key, $description );
115
    $memory_cache->set_in_cache( $cache_key, $descriptions );
115
    }
116
    return $descriptions;
116
    return $description;
117
}
117
}
118
118
119
sub get_descriptions_by_koha_field {
119
sub get_descriptions_by_koha_field {
Lines 123-141 sub get_descriptions_by_koha_field { Link Here
123
123
124
    my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
124
    my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
125
    my $cache_key    = "AV_descriptions:$frameworkcode:$kohafield";
125
    my $cache_key    = "AV_descriptions:$frameworkcode:$kohafield";
126
    my $cached       = $memory_cache->get_from_cache($cache_key);
126
    my $descriptions = $memory_cache->get_from_cache($cache_key);
127
    return @$cached if $cached;
127
128
    unless (defined $descriptions) {
129
        my @avs = $self->search_by_koha_field($params)->as_list;
130
        $descriptions = [
131
            map {
132
                {
133
                    authorised_value => $_->authorised_value,
134
                    lib              => $_->lib,
135
                    opac_description => $_->opac_description
136
                }
137
            } @avs
138
        ];
139
        $memory_cache->set_in_cache( $cache_key, $descriptions );
140
    }
141
    return @{$descriptions};
142
}
128
143
129
    my @avs          = $self->search_by_koha_field($params)->as_list;
144
sub get_description_by_category_and_authorised_value {
130
    my @descriptions = map {
145
    my ( $self, $params ) = @_;
131
        {
146
    return unless defined $params->{category} && defined $params->{authorised_value};
132
            authorised_value => $_->authorised_value,
147
133
            lib              => $_->lib,
148
    my $category = $params->{category};
134
            opac_description => $_->opac_description
149
    my $value = $params->{authorised_value};
135
        }
150
136
    } @avs;
151
    my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
137
    $memory_cache->set_in_cache( $cache_key, \@descriptions );
152
    my $cache_key = "AV_description_by_category_and_authorised_value:$category:$value";
138
    return @descriptions;
153
    my $description = $memory_cache->get_from_cache($cache_key);
154
155
    unless (defined $description) {
156
        my $av = $self->search(
157
            {
158
                category => $category,
159
                authorised_value => $value
160
            }
161
        )->next;
162
        $description = defined $av ? {
163
            lib => $av->lib,
164
            opac_description => $av->opac_description
165
        } : {};
166
        $memory_cache->set_in_cache( $cache_key, $description );
167
    }
168
169
    return $description;
139
}
170
}
140
171
141
sub categories {
172
sub categories {
(-)a/Koha/Template/Plugin/AuthorisedValues.pm (-8 / +15 lines)
Lines 26-42 use Koha::AuthorisedValues; Link Here
26
26
27
sub GetByCode {
27
sub GetByCode {
28
    my ( $self, $category, $code, $opac ) = @_;
28
    my ( $self, $category, $code, $opac ) = @_;
29
    my $av = Koha::AuthorisedValues->search({ category => $category, authorised_value => $code });
29
    my $av = Koha::AuthorisedValues->get_description_by_category_and_authorised_value(
30
    return $av->count
30
        {
31
            ? $opac
31
            category => $category,
32
                ? $av->next->opac_description
32
            authorised_value => $code
33
                : $av->next->lib
33
        }
34
            : $code;
34
    );
35
36
    my $description;
37
    if ($av) {
38
        $description = $opac ? $av->{opac_description} : $av->{lib};
39
    }
40
41
    return $description || $code;
35
}
42
}
36
43
37
sub Get {
44
sub Get {
38
    my ( $self, $category, $selected, $opac ) = @_;
45
    my ( $self, $category, $opac ) = @_;
39
    return GetAuthorisedValues( $category, $selected, $opac );
46
    return GetAuthorisedValues( $category, $opac );
40
}
47
}
41
48
42
sub GetAuthValueDropbox {
49
sub GetAuthValueDropbox {
(-)a/t/db_dependent/AuthorisedValues.t (-7 / +2 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 16;
4
use Test::More tests => 15;
5
use Try::Tiny;
5
use Try::Tiny;
6
6
7
use t::lib::TestBuilder;
7
use t::lib::TestBuilder;
Lines 136-147 my $limits = $av1->library_limits->as_list; Link Here
136
is( @$limits, 2, 'library_limits functions correctly both as setter and getter' );
136
is( @$limits, 2, 'library_limits functions correctly both as setter and getter' );
137
137
138
my @categories = Koha::AuthorisedValues->new->categories;
138
my @categories = Koha::AuthorisedValues->new->categories;
139
139
is( @categories, @existing_categories+3, 'There should have 3 categories inserted' );
140
is( @categories, @existing_categories+3, 'There should have 3 categories inserted' );
140
is_deeply(
141
    \@categories,
142
    [ sort { uc $a cmp uc $b } @categories ],
143
    'categories must be ordered by category names'
144
);
145
141
146
subtest 'search_by_*_field + find_by_koha_field + get_description' => sub {
142
subtest 'search_by_*_field + find_by_koha_field + get_description' => sub {
147
    plan tests => 5;
143
    plan tests => 5;
148
- 

Return to bug 31856