Bug 32030: ERM - Vue version
[koha.git] / Koha / ERM / Agreement.pm
1 package Koha::ERM::Agreement;
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 Koha::Database;
21
22 use base qw(Koha::Object);
23
24 use Koha::ERM::Agreement::Periods;
25 use Koha::ERM::Agreement::UserRoles;
26
27 =head1 NAME
28
29 Koha::ERM::Agreement - Koha ErmAgreement Object class
30
31 =head1 API
32
33 =head2 Class Methods
34
35 =cut
36
37 =head3 periods
38
39 Returns the periods for this agreement
40
41 =cut
42
43 sub periods {
44     my ( $self, $periods ) = @_;
45
46     if ( $periods ) {
47         my $schema = $self->_result->result_source->schema;
48         $schema->txn_do(
49             sub {
50                 $self->periods->delete;
51
52                 for my $period (@$periods) {
53                     $self->_result->add_to_erm_agreement_periods($period);
54                 }
55             }
56         );
57     }
58
59     my $periods_rs = $self->_result->erm_agreement_periods;
60     return Koha::ERM::Agreement::Periods->_new_from_dbic($periods_rs);
61 }
62
63 =head3 user_roles
64
65 Returns the user roles for this agreement
66
67 =cut
68
69 sub user_roles {
70     my ( $self, $user_roles ) = @_;
71
72     if ( $user_roles ) {
73         my $schema = $self->_result->result_source->schema;
74         $schema->txn_do(
75             sub {
76                 $self->user_roles->delete;
77
78                 for my $user_role (@$user_roles) {
79                     $self->_result->add_to_erm_agreement_user_roles($user_role);
80                 }
81             }
82         );
83     }
84     my $user_roles_rs = $self->_result->erm_agreement_user_roles;
85     return Koha::ERM::Agreement::UserRoles->_new_from_dbic($user_roles_rs);
86 }
87
88 =head2 Internal methods
89
90 =head3 _type
91
92 =cut
93
94 sub _type {
95     return 'ErmAgreement';
96 }
97
98 1;