View | Details | Raw Unified | Return to bug 30275
Collapse All | Expand All

(-)a/Koha/Checkouts/Renewal.pm (+135 lines)
Line 0 Link Here
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::Checkout;
25
use Koha::Checkouts;
26
use Koha::Exceptions;
27
use Koha::Exceptions::Checkouts::Renewals;
28
use Koha::Old::Checkouts;
29
use Koha::Patron;
30
31
=head1 NAME
32
33
Koha::Checkouts::Renewal - Koha Renewal object class
34
35
=head1 API
36
37
=head2 Class methods
38
39
=cut
40
41
=head3 store
42
43
    my $return_claim = Koha::Checkout::Renewal->new($args)->store;
44
45
Overloaded I<store> method that validates the attributes and raises relevant
46
exceptions as needed.
47
48
=cut
49
50
sub store {
51
    my ( $self ) = @_;
52
53
    unless ( $self->in_storage || $self->renewed_by ) {
54
        Koha::Exceptions::Checkouts::Renewals::NoRenewedBy->throw();
55
    }
56
57
    unless ( !$self->issue_id
58
        || Koha::Checkouts->find( $self->issue_id )
59
        || Koha::Old::Checkouts->find( $self->issue_id ) )
60
    {
61
        Koha::Exceptions::Object::FKConstraint->throw(
62
            error     => 'Broken FK constraint',
63
            broken_fk => 'issue_id'
64
        );
65
    }
66
67
    return $self->SUPER::store;
68
}
69
70
=head3 checkout
71
72
=cut
73
74
sub checkout {
75
    my ($self) = @_;
76
77
    my $checkout_rs = $self->_result->checkout;
78
    return unless $checkout_rs;
79
    return Koha::Checkout->_new_from_dbic($checkout_rs);
80
}
81
82
=head3 old_checkout
83
84
=cut
85
86
sub old_checkout {
87
    my ($self) = @_;
88
89
    my $old_checkout_rs = $self->_result->old_checkout;
90
    return unless $old_checkout_rs;
91
    return Koha::Old::Checkout->_new_from_dbic($old_checkout_rs);
92
}
93
94
=head3 renewer
95
96
=cut
97
98
sub renewer {
99
    my ( $self ) = @_;
100
101
    my $renewer = $self->_result->renewed_by;
102
    return Koha::Patron->_new_from_dbic( $renewer ) if $renewer;
103
}
104
105
=head3 to_api_mapping
106
107
This method returns the mapping for representing a Koha::Checkouts::Renewal object
108
on the API.
109
110
=cut
111
112
sub to_api_mapping {
113
    return {
114
        id       => 'renew_id',
115
        issue_id => 'checkout_id'
116
    };
117
}
118
119
=head2 Internal methods
120
121
=head3 _type
122
123
=cut
124
125
sub _type {
126
    return 'CheckoutRenewal';
127
}
128
129
=head1 AUTHOR
130
131
Martin Renvoize <martin.renvoize@ptfs-europe.com>
132
133
=cut
134
135
1;
(-)a/Koha/Checkouts/Renewals.pm (+61 lines)
Line 0 Link Here
1
package oha::Checkouts::Renewals;
2
3
# Copyright PTFS Europe 2022
4
#
5
# This file is part of oha.
6
#
7
# oha 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
# oha 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 oha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
23
use oha::Database;
24
25
use oha::Checkouts::Renewal;
26
27
use base qw(oha::Objects);
28
29
=head1 NAME
30
31
oha::Checkouts::Renewals - Koha Renewal object set class
32
33
=head1 API
34
35
=head2 Class Methods
36
37
=cut
38
39
=head3 type
40
41
=cut
42
43
sub _type {
44
    return 'CheckoutRenewal';
45
}
46
47
=head3 object_class
48
49
=cut
50
51
sub object_class {
52
    return 'Koha::Checkouts::Renewal';
53
}
54
55
=head1 AUTHOR
56
57
Martin Renvoize <martin.renvoize@ptfs-europe.com>
58
59
=cut
60
61
1;
(-)a/Koha/Exceptions/Checkouts/Renewals.pm (-1 / +49 lines)
Line 0 Link Here
0
- 
1
package Koha::Exceptions::Checkouts::Renewals;
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::Exception;
21
22
use Exception::Class (
23
    'Koha::Exceptions::Checkouts::Renewals' => {
24
        isa         => 'Koha::Exception',
25
    },
26
    'Koha::Exceptions::Checkouts::Renewals::NoRenewedBy' => {
27
        isa         => 'Koha::Exceptions::Checkouts::Renewals',
28
        description => 'renewed_by is mandatory'
29
    },
30
);
31
32
=head1 NAME
33
34
Koha::Exceptions::Checkouts - Base class for Checkouts exceptions
35
36
=head1 Exceptions
37
38
=head2 Koha::Exceptions::Checkouts::Renewals
39
40
Generic return claim exception
41
42
=head2 Koha::Exceptions::Checkouts::Renewals::NoRenewedBy
43
44
Exception to be used when a return claim is requested to be store but
45
the 'renewed_by' param is not passed.
46
47
=cut
48
49
1;

Return to bug 30275