Bug 30708: Display AV descriptions instead of codes
[koha.git] / Koha / Preservation / Train / Item / Attribute.pm
1 package Koha::Preservation::Train::Item::Attribute;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use JSON qw( to_json );
21 use Try::Tiny;
22
23 use Koha::AuthorisedValues;
24
25 use base qw(Koha::Object);
26
27 use Koha::Preservation::Processing::Attributes;
28
29 =head1 NAME
30
31 Koha::Preservation::Train::Item::Attribute - Koha Train::Item::Attribute Object class
32
33 =head1 API
34
35 =head2 Class methods
36
37 =cut
38
39 =head3 processing_attribute
40
41 my $processing_attribute = $attribute->processing_attribute;
42
43 Return the Koha::Preservation::Processing::Attribute object
44
45 =cut
46
47 sub processing_attribute {
48     my ( $self ) = @_;
49     my $processing_attribute_rs = $self->_result->processing_attribute;
50     return Koha::Preservation::Processing::Attribute->_new_from_dbic($processing_attribute_rs)
51 }
52
53 =head3 strings_map
54
55 Returns a map of column name to string representations including the string.
56
57 =cut
58
59 sub strings_map {
60     my ($self) = @_;
61     my $str = $self->value;
62     if ( $self->processing_attribute->type eq 'authorised_value' ) {
63         my $av = Koha::AuthorisedValues->search(
64             {
65                 category         => $self->processing_attribute->option_source,
66                 authorised_value => $self->value,
67             }
68         );
69         if ( $av->count ) {
70             $str = $av->next->lib || $self->value;
71         }
72     }
73
74     return {
75         value => { str => $str, type => 'authorised_value' },
76     };
77 }
78
79 =head2 Internal methods
80
81 =head3 _type
82
83 =cut
84
85 sub _type {
86     return 'PreservationProcessingAttributesItem';
87 }
88
89 1;