Bug 30275: (follow-up) Drop renewer_id constraint
[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::Object;
26 use Koha::Old::Checkouts;
27 use Koha::Patrons;
28
29 =head1 NAME
30
31 Koha::Checkouts::Renewal - Koha Renewal object class
32
33 =head1 API
34
35 =head2 Class methods
36
37 =cut
38
39 =head3 store
40
41     my $renewal = Koha::Checkout::Renewal->new($args)->store;
42
43 Overloaded I<store> method that validates the attributes and raises relevant
44 exceptions as needed.
45
46 =cut
47
48 sub store {
49     my ( $self ) = @_;
50
51     unless ( ( !$self->checkout_id && $self->in_storage )
52         || Koha::Checkouts->find( $self->checkout_id )
53         || Koha::Old::Checkouts->find( $self->checkout_id ) )
54     {
55         Koha::Exceptions::Object::FKConstraint->throw(
56             error     => 'Broken FK constraint',
57             broken_fk => 'checkout_id'
58         );
59     }
60
61     return $self->SUPER::store;
62 }
63
64 =head3 checkout
65
66 =cut
67
68 sub checkout {
69     my ($self) = @_;
70
71     my $checkout_rs = $self->_result->checkout;
72     return unless $checkout_rs;
73     return Koha::Checkout->_new_from_dbic($checkout_rs);
74 }
75
76 =head3 old_checkout
77
78 =cut
79
80 sub old_checkout {
81     my ($self) = @_;
82
83     my $old_checkout_rs = $self->_result->old_checkout;
84     return unless $old_checkout_rs;
85     return Koha::Old::Checkout->_new_from_dbic($old_checkout_rs);
86 }
87
88 =head3 renewer
89
90 =cut
91
92 sub renewer {
93     my ( $self ) = @_;
94
95     my $renewer = $self->_result->renewer;
96     return Koha::Patron->_new_from_dbic( $renewer ) if $renewer;
97 }
98
99 =head2 Internal methods
100
101 =head3 _type
102
103 =cut
104
105 sub _type {
106     return 'CheckoutRenewal';
107 }
108
109 =head1 AUTHOR
110
111 Martin Renvoize <martin.renvoize@ptfs-europe.com>
112
113 =cut
114
115 1;