Bug 30275: (QA follow-up) Rename columns to match API
[koha.git] / Koha / Checkouts / Renewal.pm
1 package Koha::Checkouts::Renewal;
2
3 # Copyright PTFS Europe 2022
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use base qw(Koha::Object);
23
24 use Koha::Checkouts;
25 use Koha::Exceptions::Checkouts::Renewals;
26 use Koha::Exceptions::Object;
27 use Koha::Old::Checkouts;
28 use Koha::Patrons;
29
30 =head1 NAME
31
32 Koha::Checkouts::Renewal - Koha Renewal object class
33
34 =head1 API
35
36 =head2 Class methods
37
38 =cut
39
40 =head3 store
41
42     my $return_claim = Koha::Checkout::Renewal->new($args)->store;
43
44 Overloaded I<store> method that validates the attributes and raises relevant
45 exceptions as needed.
46
47 =cut
48
49 sub store {
50     my ( $self ) = @_;
51
52     unless ( $self->in_storage || $self->renewer_id ) {
53         Koha::Exceptions::Checkouts::Renewals::NoRenewerID->throw();
54     }
55
56     unless ( ( !$self->checkout_id && $self->in_storage )
57         || Koha::Checkouts->find( $self->checkout_id )
58         || Koha::Old::Checkouts->find( $self->checkout_id ) )
59     {
60         Koha::Exceptions::Object::FKConstraint->throw(
61             error     => 'Broken FK constraint',
62             broken_fk => 'checkout_id'
63         );
64     }
65
66     return $self->SUPER::store;
67 }
68
69 =head3 checkout
70
71 =cut
72
73 sub checkout {
74     my ($self) = @_;
75
76     my $checkout_rs = $self->_result->checkout;
77     return unless $checkout_rs;
78     return Koha::Checkout->_new_from_dbic($checkout_rs);
79 }
80
81 =head3 old_checkout
82
83 =cut
84
85 sub old_checkout {
86     my ($self) = @_;
87
88     my $old_checkout_rs = $self->_result->old_checkout;
89     return unless $old_checkout_rs;
90     return Koha::Old::Checkout->_new_from_dbic($old_checkout_rs);
91 }
92
93 =head3 renewer
94
95 =cut
96
97 sub renewer {
98     my ( $self ) = @_;
99
100     my $renewer = $self->_result->renewer;
101     return Koha::Patron->_new_from_dbic( $renewer ) if $renewer;
102 }
103
104 =head2 Internal methods
105
106 =head3 _type
107
108 =cut
109
110 sub _type {
111     return 'CheckoutRenewal';
112 }
113
114 =head1 AUTHOR
115
116 Martin Renvoize <martin.renvoize@ptfs-europe.com>
117
118 =cut
119
120 1;