Bug 33547: (QA follow-up) Tidy
[koha.git] / Koha / Preservation / Train / Item.pm
1 package Koha::Preservation::Train::Item;
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::Database;
24
25 use base qw(Koha::Object);
26
27 use Koha::Items;
28 use Koha::Preservation::Processings;
29 use Koha::Preservation::Train::Item::Attributes;
30
31 =head1 NAME
32
33 Koha::Preservation::Train::Item - Koha Train::Item Object class
34
35 =head1 API
36
37 =head2 Class methods
38
39 =cut
40
41 =head3 processing
42
43 Return the processing object for this item
44
45 =cut
46
47 sub processing {
48     my ($self) = @_;
49     my $rs = $self->_result->processing;    # FIXME Should we return train's default processing if there is no specific?
50     return Koha::Preservation::Processing->_new_from_dbic($rs);
51 }
52
53 =head3 catalogue_item
54
55 Return the catalogue item object for this train item
56
57 =cut
58
59 sub catalogue_item {
60     my ($self) = @_;
61     my $item_rs = $self->_result->item;
62     return Koha::Item->_new_from_dbic($item_rs);
63 }
64
65
66 =head3 train
67
68 Return the train object for this item
69
70 =cut
71
72 sub train {
73     my ($self) = @_;
74     my $rs = $self->_result->train;
75     return Koha::Preservation::Train->_new_from_dbic($rs);
76 }
77
78 =head3 attributes
79
80 Getter and setter for the attributes
81
82 =cut
83
84 sub attributes {
85     my ( $self, $attributes ) = @_;
86
87     if ($attributes) {
88         my $schema = $self->_result->result_source->schema;
89         $schema->txn_do(
90             sub {
91                 $self->attributes->delete;
92
93                 for my $attribute (@$attributes) {
94                     $self->_result->add_to_preservation_processing_attributes_items($attribute);
95                 }
96             }
97         );
98
99     }
100     my $attributes_rs = $self->_result->preservation_processing_attributes_items;
101     return Koha::Preservation::Train::Item::Attributes->_new_from_dbic($attributes_rs);
102 }
103
104 =head2 Internal methods
105
106 =head3 _type
107
108 =cut
109
110 sub _type {
111     return 'PreservationTrainsItem';
112 }
113
114 1;