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

(-)a/C4/Circulation.pm (-2 / +2 lines)
Lines 1127-1134 sub CanBookBeIssued { Link Here
1127
        $issuingimpossible{RESTRICTED} = 1;
1127
        $issuingimpossible{RESTRICTED} = 1;
1128
    }
1128
    }
1129
    if ( $item_object->itemlost && C4::Context->preference("IssueLostItem") ne 'nothing' ) {
1129
    if ( $item_object->itemlost && C4::Context->preference("IssueLostItem") ne 'nothing' ) {
1130
        my $av   = Koha::AuthorisedValues->search( { category => 'LOST', authorised_value => $item_object->itemlost } );
1130
        my $code = Koha::AuthorisedValues->find_description(
1131
        my $code = $av->count ? $av->next->lib : '';
1131
            { category => 'LOST', authorised_value => $item_object->itemlost } );
1132
        $needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' );
1132
        $needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' );
1133
        $alerts{ITEM_LOST}            = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
1133
        $alerts{ITEM_LOST}            = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
1134
    }
1134
    }
(-)a/C4/Search.pm (-6 / +9 lines)
Lines 545-562 sub getRecords { Link Here
545
                        if ( $link_value =~ /location/ ) {
545
                        if ( $link_value =~ /location/ ) {
546
546
547
                            # TODO Retrieve all authorised values at once, instead of 1 query per entry
547
                            # TODO Retrieve all authorised values at once, instead of 1 query per entry
548
                            my $av =
548
                            $facet_label_value = Koha::AuthorisedValues->find_description(
549
                                Koha::AuthorisedValues->search( { category => 'LOC', authorised_value => $one_facet } );
549
                                { category => 'LOC', authorised_value => $one_facet, opac => 1, default_to_blank => 1 }
550
                            $facet_label_value = $av->count ? $av->next->opac_description : '';
550
                            );
551
                        }
551
                        }
552
552
553
                        # also, if it's a collection code, use the name instead of the code
553
                        # also, if it's a collection code, use the name instead of the code
554
                        if ( $link_value =~ /ccode/ ) {
554
                        if ( $link_value =~ /ccode/ ) {
555
555
556
                            # TODO Retrieve all authorised values at once, instead of 1 query per entry
556
                            # TODO Retrieve all authorised values at once, instead of 1 query per entry
557
                            my $av = Koha::AuthorisedValues->search(
557
                            $facet_label_value = Koha::AuthorisedValues->find_description(
558
                                { category => 'CCODE', authorised_value => $one_facet } );
558
                                {
559
                            $facet_label_value = $av->count ? $av->next->opac_description : '';
559
                                    category         => 'CCODE', authorised_value => $one_facet, opac => 1,
560
                                    default_to_blank => 1
561
                                }
562
                            );
560
                        }
563
                        }
561
564
562
                        # but we're down with the whole label being in the link's title.
565
                        # but we're down with the whole label being in the link's title.
(-)a/Koha/Acquisition/Bookseller/Issue.pm (-8 / +2 lines)
Lines 41-60 sub strings_map { Link Here
41
    my $strings = {};
41
    my $strings = {};
42
42
43
    if ( defined $self->type ) {
43
    if ( defined $self->type ) {
44
        my $av = Koha::AuthorisedValues->search(
44
        my $type_str = Koha::AuthorisedValues->find_description(
45
            {
45
            {
46
                category         => ISSUE_TYPE_CATEGORY,
46
                category         => ISSUE_TYPE_CATEGORY,
47
                authorised_value => $self->type,
47
                authorised_value => $self->type,
48
                opac             => $params->{public}
48
            }
49
            }
49
        );
50
        );
50
51
51
        my $type_str =
52
              $av->count
53
            ? $params->{public}
54
                ? $av->next->opac_description
55
                : $av->next->lib
56
            : $self->type;
57
58
        $strings->{type} = {
52
        $strings->{type} = {
59
            category => ISSUE_TYPE_CATEGORY,
53
            category => ISSUE_TYPE_CATEGORY,
60
            str      => $type_str,
54
            str      => $type_str,
(-)a/Koha/ArticleRequest.pm (-4 / +4 lines)
Lines 292-304 sub notify { Link Here
292
    my $status = $self->status;
292
    my $status = $self->status;
293
    my $reason = $self->notes;
293
    my $reason = $self->notes;
294
    if ( !defined $reason && $self->cancellation_reason ) {
294
    if ( !defined $reason && $self->cancellation_reason ) {
295
        my $av = Koha::AuthorisedValues->search(
295
        $reason = Koha::AuthorisedValues->find_description(
296
            {
296
            {
297
                category         => 'AR_CANCELLATION',
297
                category         => 'AR_CANCELLATION',
298
                authorised_value => $self->cancellation_reason
298
                authorised_value => $self->cancellation_reason,
299
                opac             => 1,
299
            }
300
            }
300
        )->next;
301
        );
301
        $reason = $av->lib_opac ? $av->lib_opac : $av->lib if $av;
302
    }
302
    }
303
303
304
    require C4::Letters;
304
    require C4::Letters;
(-)a/Koha/AuthorisedValues.pm (+31 lines)
Lines 20-25 package Koha::AuthorisedValues; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Caches;
23
24
24
use Koha::AuthorisedValue;
25
use Koha::AuthorisedValue;
25
use Koha::MarcSubfieldStructures;
26
use Koha::MarcSubfieldStructures;
Lines 37-42 Koha::AuthorisedValues - Koha Authorised value Object set class Link Here
37
38
38
=cut
39
=cut
39
40
41
=head2 
42
43
44
45
=cut
46
47
sub find_description_by_code {
48
    my ( $self, $params ) = @_;
49
    my $category         = $params->{category};
50
    my $value            = $params->{value};
51
    my $opac             = $params->{opac};
52
    my $default_to_blank = $params->{default_to_blank};
53
54
    return unless $category || $value;
55
56
    # Is this cached already?
57
    my $cache_key = "AuthorisedValues-$category-values-$value-$opac-$default_to_blank";
58
    my $cache     = Koha::Caches->get_instance();
59
    my $result    = $cache->get_from_cache($cache_key);
60
    return $result if $result;
61
62
    my $av = $self->find( { category => $category, authorised_value => $value } );
63
64
    my $description = $av ? $opac ? $av->opac_description : $av->lib : $default_to_blank ? q{} : $value;
65
66
    $cache->set_in_cache( $cache_key, $description, { expiry => 5 } );
67
68
    return $description;
69
}
70
40
=head2 search_by_marc_field
71
=head2 search_by_marc_field
41
72
42
Missing POD for search_by_marc_field.
73
Missing POD for search_by_marc_field.
(-)a/Koha/ILL/Request.pm (-7 / +4 lines)
Lines 182-198 sub statusalias { Link Here
182
    my ($self) = @_;
182
    my ($self) = @_;
183
    return unless $self->status_alias;
183
    return unless $self->status_alias;
184
184
185
    # We can't know which result is the right one if there are multiple
185
    # FIXME We should use Koha::AuthorisedValues->find_description where this method is called
186
    # ILL_STATUS_ALIAS authorised values with the same authorised_value column value
186
    # to retrieve the value from the cache
187
    # so we just use the first
187
    return Koha::AuthorisedValues->find(
188
    return Koha::AuthorisedValues->search(
189
        {
188
        {
190
            category         => 'ILL_STATUS_ALIAS',
189
            category         => 'ILL_STATUS_ALIAS',
191
            authorised_value => $self->get_column('status_alias'),
190
            authorised_value => $self->get_column('status_alias'),
192
        },
191
        },
193
        {},
192
    );
194
        $self->branchcode
195
    )->next;
196
}
193
}
197
194
198
=head3 illrequestattributes
195
=head3 illrequestattributes
(-)a/Koha/Object/Mixin/AdditionalFields.pm (-4 / +2 lines)
Lines 271-285 sub strings_map { Link Here
271
271
272
        foreach my $av_value ( @{ $afvs->{$af_id} } ) {
272
        foreach my $av_value ( @{ $afvs->{$af_id} } ) {
273
            if ($av_cat) {
273
            if ($av_cat) {
274
                my $av = Koha::AuthorisedValues->search(
274
                $value_to_push = Koha::AuthorisedValues->find_description(
275
                    {
275
                    {
276
                        category         => $av_cat,
276
                        category         => $av_cat,
277
                        authorised_value => $av_value,
277
                        authorised_value => $av_value,
278
                        opac             => $params->{public},
278
                    }
279
                    }
279
                );
280
                );
280
281
                $value_to_push =
282
                    $av->count ? $params->{public} ? $av->next->opac_description : $av->next->lib : $av_value;
283
            } else {
281
            } else {
284
                $value_to_push = $av_value;
282
                $value_to_push = $av_value;
285
            }
283
            }
(-)a/Koha/Patron/Attribute.pm (-2 / +10 lines)
Lines 110-115 Return undef if this attribute is not attached to an authorised value Link Here
110
110
111
=cut
111
=cut
112
112
113
# FIXME Can this method be removed?
113
sub authorised_value {
114
sub authorised_value {
114
    my ($self) = @_;
115
    my ($self) = @_;
115
116
Lines 138-147 displayed instead of the code. Link Here
138
139
139
sub description {
140
sub description {
140
    my ($self) = @_;
141
    my ($self) = @_;
142
141
    if ( $self->type->authorised_value_category ) {
143
    if ( $self->type->authorised_value_category ) {
142
        my $av = $self->authorised_value;
144
        return Koha::AuthorisedValues->find_description(
143
        return $av ? $av->lib : "";
145
            {
146
                category         => $self->type->authorised_value_category,
147
                authorised_value => $self->attribute,
148
                default_to_blank => 1,
149
            }
150
        );
144
    }
151
    }
152
145
    return $self->attribute;
153
    return $self->attribute;
146
}
154
}
147
155
(-)a/Koha/Preservation/Train/Item/Attribute.pm (-4 / +1 lines)
Lines 60-74 sub strings_map { Link Here
60
    my ($self) = @_;
60
    my ($self) = @_;
61
    my $str = $self->value;
61
    my $str = $self->value;
62
    if ( $self->processing_attribute->type eq 'authorised_value' ) {
62
    if ( $self->processing_attribute->type eq 'authorised_value' ) {
63
        my $av = Koha::AuthorisedValues->search(
63
        $str = Koha::AuthorisedValues->find_description(
64
            {
64
            {
65
                category         => $self->processing_attribute->option_source,
65
                category         => $self->processing_attribute->option_source,
66
                authorised_value => $self->value,
66
                authorised_value => $self->value,
67
            }
67
            }
68
        );
68
        );
69
        if ( $av->count ) {
70
            $str = $av->next->lib || $self->value;
71
        }
72
    }
69
    }
73
70
74
    return {
71
    return {
(-)a/Koha/Suggestion.pm (-10 / +4 lines)
Lines 56-67 sub store { Link Here
56
    my @status_constants = qw(ASKED CHECKED ACCEPTED REJECTED ORDERED AVAILABLE);
56
    my @status_constants = qw(ASKED CHECKED ACCEPTED REJECTED ORDERED AVAILABLE);
57
    Koha::Exceptions::Suggestion::StatusForbidden->throw( STATUS => $self->STATUS )
57
    Koha::Exceptions::Suggestion::StatusForbidden->throw( STATUS => $self->STATUS )
58
        unless ( grep { $self->STATUS eq $_ } @status_constants )
58
        unless ( grep { $self->STATUS eq $_ } @status_constants )
59
        || Koha::AuthorisedValues->search(
59
        || Koha::AuthorisedValues->find(
60
        {
60
        {
61
            category         => 'SUGGEST_STATUS',
61
            category         => 'SUGGEST_STATUS',
62
            authorised_value => $self->STATUS
62
            authorised_value => $self->STATUS
63
        }
63
        }
64
    )->count;
64
        );
65
65
66
    $self->branchcode(undef) if defined $self->branchcode && $self->branchcode eq '';
66
    $self->branchcode(undef) if defined $self->branchcode && $self->branchcode eq '';
67
    unless ( $self->suggesteddate() ) {
67
    unless ( $self->suggesteddate() ) {
Lines 312-325 sub strings_map { Link Here
312
    };
312
    };
313
313
314
    foreach my $key ( keys %$required_strings ) {
314
    foreach my $key ( keys %$required_strings ) {
315
        my $av = Koha::AuthorisedValues->search(
315
        my $status_str = Koha::AuthorisedValues->find_description(
316
            { category => $required_strings->{$key}, authorised_value => $self->$key } );
316
            { category => $required_strings->{$key}, authorised_value => $self->$key, opac => $params->{public} } );
317
        my $status_str =
318
              $av->count
319
            ? $params->{public}
320
                ? $av->next->opac_description
321
                : $av->next->lib
322
            : $self->$key;
323
317
324
        $strings->{$key} = {
318
        $strings->{$key} = {
325
            category => $required_strings->{$key},
319
            category => $required_strings->{$key},
(-)a/Koha/Template/Plugin/AuthorisedValues.pm (-7 / +2 lines)
Lines 26-38 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
    return Koha::AuthorisedValues->find_description_by_code(
30
    return
30
        { category => $category, authorised_value => $code, opac => $opac, } );
31
          $av->count
32
        ? $opac
33
            ? $av->next->opac_description
34
            : $av->next->lib
35
        : $code;
36
}
31
}
37
32
38
sub Get {
33
sub Get {
(-)a/Koha/Ticket.pm (-3 / +3 lines)
Lines 245-251 sub strings_map { Link Here
245
    my $strings = {};
245
    my $strings = {};
246
246
247
    if ( defined $self->status ) {
247
    if ( defined $self->status ) {
248
        my $av = Koha::AuthorisedValues->search(
248
        my $av = Koha::AuthorisedValues->find(
249
            {
249
            {
250
                category         => 'TICKET_STATUS',
250
                category         => 'TICKET_STATUS',
251
                authorised_value => $self->status,
251
                authorised_value => $self->status,
Lines 253-260 sub strings_map { Link Here
253
        );
253
        );
254
254
255
        # Fall back to TICKET_RESOLUTION as needed
255
        # Fall back to TICKET_RESOLUTION as needed
256
        if ( !$av->count ) {
256
        unless ($av) {
257
            $av = Koha::AuthorisedValues->search(
257
            $av = Koha::AuthorisedValues->find(
258
                {
258
                {
259
                    category         => 'TICKET_RESOLUTION',
259
                    category         => 'TICKET_RESOLUTION',
260
                    authorised_value => $self->status,
260
                    authorised_value => $self->status,
(-)a/Koha/Ticket/Update.pm (-3 / +3 lines)
Lines 91-97 sub strings_map { Link Here
91
    my $strings = {};
91
    my $strings = {};
92
92
93
    if ( defined $self->status ) {
93
    if ( defined $self->status ) {
94
        my $av = Koha::AuthorisedValues->search(
94
        my $av = Koha::AuthorisedValues->find(
95
            {
95
            {
96
                category         => 'TICKET_STATUS',
96
                category         => 'TICKET_STATUS',
97
                authorised_value => $self->status,
97
                authorised_value => $self->status,
Lines 99-106 sub strings_map { Link Here
99
        );
99
        );
100
100
101
        # Fall back to TICKET_RESOLUTION as needed
101
        # Fall back to TICKET_RESOLUTION as needed
102
        if ( !$av->count ) {
102
        unless ($av) {
103
            $av = Koha::AuthorisedValues->search(
103
            $av = Koha::AuthorisedValues->find(
104
                {
104
                {
105
                    category         => 'TICKET_RESOLUTION',
105
                    category         => 'TICKET_RESOLUTION',
106
                    authorised_value => $self->status,
106
                    authorised_value => $self->status,
(-)a/admin/patron-attr-types.pl (-2 / +1 lines)
Lines 266-273 sub patron_attribute_type_list { Link Here
266
            next if $attr->class ne $class;
266
            next if $attr->class ne $class;
267
            push @items, $attr;
267
            push @items, $attr;
268
        }
268
        }
269
        my $av  = Koha::AuthorisedValues->search( { category => 'PA_CLASS', authorised_value => $class } );
269
        my $lib = Koha::AuthorisedValues->find_description( { category => 'PA_CLASS', authorised_value => $class } );
270
        my $lib = $av->count ? $av->next->lib : $class;
271
        push @attributes_loop, {
270
        push @attributes_loop, {
272
            class => $class,
271
            class => $class,
273
            items => \@items,
272
            items => \@items,
(-)a/circ/circulation.pl (-2 / +2 lines)
Lines 740-747 my $relatives_issues_count = Link Here
740
    Koha::Database->new()->schema()->resultset('Issue')->count( { borrowernumber => \@relatives } );
740
    Koha::Database->new()->schema()->resultset('Issue')->count( { borrowernumber => \@relatives } );
741
741
742
if ($patron) {
742
if ($patron) {
743
    my $av = Koha::AuthorisedValues->search( { category => 'ROADTYPE', authorised_value => $patron->streettype } );
743
    my $roadtype = Koha::AuthorisedValues->find_description(
744
    my $roadtype = $av->count ? $av->next->lib : '';
744
        { category => 'ROADTYPE', authorised_value => $patron->streettype, default_to_blank => 1 } );
745
    $template->param(
745
    $template->param(
746
        roadtype     => $roadtype,
746
        roadtype     => $roadtype,
747
        patron       => $patron,
747
        patron       => $patron,
(-)a/members/memberentry.pl (-2 / +1 lines)
Lines 988-995 sub patron_attributes_form { Link Here
988
        }
988
        }
989
    }
989
    }
990
    for my $class ( sort keys %items_by_class ) {
990
    for my $class ( sort keys %items_by_class ) {
991
        my $av  = Koha::AuthorisedValues->search( { category => 'PA_CLASS', authorised_value => $class } );
991
        my $lib = Koha::AuthorisedValues->find_descriptoin( { category => 'PA_CLASS', authorised_value => $class } );
992
        my $lib = $av->count ? $av->next->lib : $class;
993
        push @attribute_loop, {
992
        push @attribute_loop, {
994
            class => $class,
993
            class => $class,
995
            items => $items_by_class{$class},
994
            items => $items_by_class{$class},
(-)a/members/moremember.pl (-2 / +1 lines)
Lines 152-159 if ( C4::Context->preference('ExtendedPatronAttributes') ) { Link Here
152
        for my $attr (@attributes) {
152
        for my $attr (@attributes) {
153
            push @items, $attr if $attr->type->class eq $class;
153
            push @items, $attr if $attr->type->class eq $class;
154
        }
154
        }
155
        my $av  = Koha::AuthorisedValues->search( { category => 'PA_CLASS', authorised_value => $class } );
155
        my $lib = Koha::AuthorisedValues->find_description( { category => 'PA_CLASS', authorised_value => $class } );
156
        my $lib = $av->count ? $av->next->lib : $class;
157
156
158
        push @attributes_loop, {
157
        push @attributes_loop, {
159
            class => $class,
158
            class => $class,
(-)a/opac/opac-memberentry.pl (-3 / +2 lines)
Lines 740-748 sub GeneratePatronAttributesForm { Link Here
740
    foreach my $class (@classes) {
740
    foreach my $class (@classes) {
741
        next unless ( $items_by_class{$class} );
741
        next unless ( $items_by_class{$class} );
742
742
743
        my $av = Koha::AuthorisedValues->search( { category => 'PA_CLASS', authorised_value => $class } );
743
        my $lib = Koha::AuthorisedValues->find_description(
744
744
            { category => 'PA_CLASS', authorised_value => $class, opac => 1 } );
745
        my $lib = $av->count ? $av->next->opac_description : $class;
746
745
747
        push @class_loop,
746
        push @class_loop,
748
            {
747
            {
(-)a/reports/borrowers_stats.pl (-2 / +1 lines)
Lines 524-531 sub patron_attributes_form { Link Here
524
524
525
    my @attribute_loop;
525
    my @attribute_loop;
526
    foreach my $class ( sort keys %items_by_class ) {
526
    foreach my $class ( sort keys %items_by_class ) {
527
        my $av  = Koha::AuthorisedValues->search( { category => 'PA_CLASS', authorised_value => $class } );
527
        my $lib = Koha::AuthorisedValues->find_description( { category => 'PA_CLASS', authorised_value => $class } );
528
        my $lib = $av->count ? $av->next->lib : $class;
529
        push @attribute_loop, {
528
        push @attribute_loop, {
530
            class => $class,
529
            class => $class,
531
            items => $items_by_class{$class},
530
            items => $items_by_class{$class},
(-)a/serials/subscription-detail.pl (-4 / +4 lines)
Lines 119-128 for my $date (qw(startdate enddate firstacquidate histstartdate histenddate)) { Link Here
119
    $subs->{$date} = output_pref( { str => $subs->{$date}, dateonly => 1 } )
119
    $subs->{$date} = output_pref( { str => $subs->{$date}, dateonly => 1 } )
120
        if $subs->{$date};
120
        if $subs->{$date};
121
}
121
}
122
my $av = Koha::AuthorisedValues->search( { category => 'LOC', authorised_value => $subs->{location} } );
122
$subs->{location} = Koha::AuthorisedValues->find_description(
123
$subs->{location}      = $av->count ? $av->next->lib : '';
123
    { category => 'LOC', authorised_value => $subs->{location}, default_to_blank => 1 } );
124
$av                    = Koha::AuthorisedValues->search( { category => 'CCODE', authorised_value => $subs->{ccode} } );
124
$subs->{ccode} = Koha::AuthorisedValues->find_description(
125
$subs->{ccode}         = $av->count ? $av->next->lib : '';
125
    { category => 'CCODE', authorised_value => $subs->{ccode}, default_to_blank => 1 } );
126
$subs->{abouttoexpire} = abouttoexpire( $subs->{subscriptionid} );
126
$subs->{abouttoexpire} = abouttoexpire( $subs->{subscriptionid} );
127
$template->param( %{$subs} );
127
$template->param( %{$subs} );
128
$template->param( biblionumber_for_new_subscription => $subs->{bibnum} );
128
$template->param( biblionumber_for_new_subscription => $subs->{bibnum} );
(-)a/t/db_dependent/Koha/Item.t (-1 / +1 lines)
Lines 2564-2570 subtest 'strings_map() tests' => sub { Link Here
2564
        }
2564
        }
2565
    );
2565
    );
2566
2566
2567
    Koha::AuthorisedValues->search( { authorised_value => 3, category => 'LOST' } )->delete;
2567
    Koha::AuthorisedValues->find( { authorised_value => 3, category => 'LOST' } )->delete;
2568
    my $lost_av = $builder->build_object(
2568
    my $lost_av = $builder->build_object(
2569
        {
2569
        {
2570
            class => 'Koha::AuthorisedValues',
2570
            class => 'Koha::AuthorisedValues',
(-)a/t/db_dependent/XSLT.t (-2 / +1 lines)
Lines 120-126 subtest 'buildKohaItemsNamespace status tests' => sub { Link Here
120
        like( $xml, qr{<status>reference</status>}, "reference if positive itemtype notforloan value" );
120
        like( $xml, qr{<status>reference</status>}, "reference if positive itemtype notforloan value" );
121
        Koha::ItemTypes->find( $item->itype )->notforloan(0)->store;
121
        Koha::ItemTypes->find( $item->itype )->notforloan(0)->store;
122
122
123
        my $substatus = Koha::AuthorisedValues->search( { category => 'NOT_LOAN', authorised_value => -1 } )->next->lib;
123
        my $substatus = Koha::AuthorisedValues->find_description( { category => 'NOT_LOAN', authorised_value => -1 } );
124
        $item->notforloan(-1)->store;
124
        $item->notforloan(-1)->store;
125
        $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber, [] );
125
        $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber, [] );
126
        like( $xml, qr{<status>reallynotforloan</status>}, "reallynotforloan if negative notforloan value" );
126
        like( $xml, qr{<status>reallynotforloan</status>}, "reallynotforloan if negative notforloan value" );
127
- 

Return to bug 40554