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

(-)a/C4/Letters.pm (-12 / +13 lines)
Lines 749-766 sub _parseletter_sth { Link Here
749
    #       broke things for the rest of us. prepare_cached is a better
749
    #       broke things for the rest of us. prepare_cached is a better
750
    #       way to cache statement handles anyway.
750
    #       way to cache statement handles anyway.
751
    my $query = 
751
    my $query = 
752
    ($table eq 'biblio'       ) ? "SELECT * FROM $table WHERE   biblionumber = ?"                                  :
752
    ($table eq 'biblio'       )    ? "SELECT * FROM $table WHERE   biblionumber = ?"                                  :
753
    ($table eq 'biblioitems'  ) ? "SELECT * FROM $table WHERE   biblionumber = ?"                                  :
753
    ($table eq 'biblioitems'  )    ? "SELECT * FROM $table WHERE   biblionumber = ?"                                  :
754
    ($table eq 'items'        ) ? "SELECT * FROM $table WHERE     itemnumber = ?"                                  :
754
    ($table eq 'items'        )    ? "SELECT * FROM $table WHERE     itemnumber = ?"                                  :
755
    ($table eq 'issues'       ) ? "SELECT * FROM $table WHERE     itemnumber = ?"                                  :
755
    ($table eq 'issues'       )    ? "SELECT * FROM $table WHERE     itemnumber = ?"                                  :
756
    ($table eq 'old_issues'   ) ? "SELECT * FROM $table WHERE     itemnumber = ? ORDER BY timestamp DESC LIMIT 1"  :
756
    ($table eq 'old_issues'   )    ? "SELECT * FROM $table WHERE     itemnumber = ? ORDER BY timestamp DESC LIMIT 1"  :
757
    ($table eq 'reserves'     ) ? "SELECT * FROM $table WHERE borrowernumber = ? and biblionumber = ?"             :
757
    ($table eq 'reserves'     )    ? "SELECT * FROM $table WHERE borrowernumber = ? and biblionumber = ?"             :
758
    ($table eq 'borrowers'    ) ? "SELECT * FROM $table WHERE borrowernumber = ?"                                  :
758
    ($table eq 'borrowers'    )    ? "SELECT * FROM $table WHERE borrowernumber = ?"                                  :
759
    ($table eq 'branches'     ) ? "SELECT * FROM $table WHERE     branchcode = ?"                                  :
759
    ($table eq 'branches'     )    ? "SELECT * FROM $table WHERE     branchcode = ?"                                  :
760
    ($table eq 'suggestions'  ) ? "SELECT * FROM $table WHERE   suggestionid = ?"                                  :
760
    ($table eq 'suggestions'  )    ? "SELECT * FROM $table WHERE   suggestionid = ?"                                  :
761
    ($table eq 'aqbooksellers') ? "SELECT * FROM $table WHERE             id = ?"                                  :
761
    ($table eq 'aqbooksellers')    ? "SELECT * FROM $table WHERE             id = ?"                                  :
762
    ($table eq 'aqorders'     ) ? "SELECT * FROM $table WHERE    ordernumber = ?"                                  :
762
    ($table eq 'aqorders'     )    ? "SELECT * FROM $table WHERE    ordernumber = ?"                                  :
763
    ($table eq 'opac_news'    ) ? "SELECT * FROM $table WHERE          idnew = ?"                                  :
763
    ($table eq 'opac_news'    )    ? "SELECT * FROM $table WHERE          idnew = ?"                                  :
764
    ($table eq 'article_requests') ? "SELECT * FROM $table WHERE             id = ?"                                  :
764
    ($table eq 'borrower_modifications') ? "SELECT * FROM $table WHERE verification_token = ?" :
765
    ($table eq 'borrower_modifications') ? "SELECT * FROM $table WHERE verification_token = ?" :
765
    ($table eq 'subscription') ? "SELECT * FROM $table WHERE subscriptionid = ?" :
766
    ($table eq 'subscription') ? "SELECT * FROM $table WHERE subscriptionid = ?" :
766
    ($table eq 'serial') ? "SELECT * FROM $table WHERE serialid = ?" :
767
    ($table eq 'serial') ? "SELECT * FROM $table WHERE serialid = ?" :
(-)a/Koha/ArticleRequest.pm (+223 lines)
Line 0 Link Here
1
package Koha::ArticleRequest;
2
3
# Copyright ByWater Solutions 2015
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use Koha::Database;
25
use Koha::Patrons;
26
use Koha::Biblios;
27
use Koha::Items;
28
use Koha::Libraries;
29
use Koha::ArticleRequest::Status;
30
use Koha::DateUtils qw(dt_from_string);
31
32
use base qw(Koha::Object);
33
34
=head1 NAME
35
36
Koha::ArticleRequest - Koha Article Request Object class
37
38
=head1 API
39
40
=head2 Class Methods
41
42
=cut
43
44
=head3 open
45
46
=cut
47
48
sub open {
49
    my ($self) = @_;
50
51
    $self->status(Koha::ArticleRequest::Status::Pending);
52
    $self->notify();
53
    return $self;
54
}
55
56
=head3 process
57
58
=cut
59
60
sub process {
61
    my ($self) = @_;
62
63
    $self->status(Koha::ArticleRequest::Status::Processing);
64
    $self->store();
65
    $self->notify();
66
    return $self;
67
}
68
69
=head3 complete
70
71
=cut
72
73
sub complete {
74
    my ($self) = @_;
75
76
    $self->status(Koha::ArticleRequest::Status::Completed);
77
    $self->store();
78
    $self->notify();
79
    return $self;
80
}
81
82
=head3 cancel
83
84
=cut
85
86
sub cancel {
87
    my ( $self, $notes ) = @_;
88
89
    $self->status(Koha::ArticleRequest::Status::Canceled);
90
    $self->notes($notes) if $notes;
91
    $self->store();
92
    $self->notify();
93
    return $self;
94
}
95
96
=head3 notify
97
98
=cut
99
100
sub notify {
101
    my ($self) = @_;
102
103
    my $status = $self->status;
104
105
    if (
106
        my $letter = C4::Letters::GetPreparedLetter(
107
            module                 => 'circulation',
108
            letter_code            => "AR_$status",
109
            message_transport_type => 'email',
110
            tables                 => {
111
                article_requests => $self->id,
112
                borrowers        => $self->borrowernumber,
113
                biblio           => $self->biblionumber,
114
                biblioitems      => $self->biblionumber,
115
                items            => $self->itemnumber,
116
                branches         => $self->branchcode,
117
            },
118
        )
119
      )
120
    {
121
        C4::Letters::EnqueueLetter(
122
            {
123
                letter                 => $letter,
124
                borrowernumber         => $self->borrowernumber,
125
                message_transport_type => 'email',
126
            }
127
        ) or warn "can't enqueue letter $letter";
128
    }
129
}
130
131
=head3 biblio
132
133
Returns the Koha::Biblio object for this article request
134
135
=cut
136
137
sub biblio {
138
    my ($self) = @_;
139
140
    $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );
141
142
    return $self->{_biblio};
143
}
144
145
=head3 item
146
147
Returns the Koha::Item object for this article request
148
149
=cut
150
151
sub item {
152
    my ($self) = @_;
153
154
    $self->{_item} ||= Koha::Items->find( $self->itemnumber() );
155
156
    return $self->{_item};
157
}
158
159
=head3 borrower
160
161
Returns the Koha::Patron object for this article request
162
163
=cut
164
165
sub borrower {
166
    my ($self) = @_;
167
168
    $self->{_borrower} ||= Koha::Patrons->find( $self->borrowernumber() );
169
170
    return $self->{_borrower};
171
}
172
173
=head3 branch
174
175
Returns the Koha::Library object for this article request
176
177
=cut
178
179
sub branch {
180
    my ($self) = @_;
181
182
    $self->{_branch} ||= Koha::Libraries->find( $self->branchcode() );
183
184
    return $self->{_branch};
185
}
186
187
=head3 store
188
189
Override the default store behavior so that new opan requests
190
will have notifications sent.
191
192
=cut
193
194
sub store {
195
    my ($self) = @_;
196
197
    if ( $self->in_storage() ) {
198
        my $now = dt_from_string();
199
        $self->updated_on($now);
200
201
        return $self->SUPER::store();
202
    }
203
    else {
204
        $self->open();
205
        return $self->SUPER::store();
206
    }
207
}
208
209
=head3 _type
210
211
=cut
212
213
sub _type {
214
    return 'ArticleRequest';
215
}
216
217
=head1 AUTHOR
218
219
Kyle M Hall <kyle@bywatersolutions.com>
220
221
=cut
222
223
1;
(-)a/Koha/ArticleRequest/Status.pm (+44 lines)
Line 0 Link Here
1
package Koha::ArticleRequest::Status;
2
3
# Copyright ByWater Solutions 2015
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
sub Pending {
23
    return 'PENDING';
24
}
25
26
sub Processing {
27
    return 'PROCESSING';
28
}
29
30
sub Completed {
31
    return 'COMPLETED';
32
}
33
34
sub Canceled {
35
    return 'CANCELED';
36
}
37
38
=head1 AUTHOR
39
40
Kyle M Hall <kyle@bywatersolutions.com>
41
42
=cut
43
44
1;
(-)a/Koha/ArticleRequests.pm (+103 lines)
Line 0 Link Here
1
package Koha::ArticleRequests;
2
3
# Copyright ByWater Solutions 2015
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use Koha::Database;
25
26
use Koha::ArticleRequest;
27
use Koha::ArticleRequest::Status;
28
29
use base qw(Koha::Objects);
30
31
=head1 NAME
32
33
Koha::ArticleRequests - Koha ArticleRequests Object class
34
35
=head1 API
36
37
=head2 Class Methods
38
39
=cut
40
41
=head3 pending
42
43
=cut
44
45
sub pending {
46
    my ( $self, $branchcode ) = @_;
47
    my $params = { status => Koha::ArticleRequest::Status::Pending };
48
    $params->{branchcode} = $branchcode if $branchcode;
49
    return Koha::ArticleRequests->search( $params );
50
}
51
52
=head3 processing
53
54
=cut
55
56
sub processing {
57
    my ( $self, $branchcode ) = @_;
58
    my $params = { status => Koha::ArticleRequest::Status::Processing };
59
    $params->{branchcode} = $branchcode if $branchcode;
60
    return Koha::ArticleRequests->search( $params );
61
}
62
63
=head3 completed
64
65
=cut
66
67
sub completed {
68
    my ( $self, $branchcode ) = @_;
69
    my $params = { status => Koha::ArticleRequest::Status::Completed };
70
    $params->{branchcode} = $branchcode if $branchcode;
71
    return Koha::ArticleRequests->search( $params );
72
}
73
74
=head3 canceled
75
76
=cut
77
78
sub canceled {
79
    my ( $self, $branchcode ) = @_;
80
    my $params = { status => Koha::ArticleRequest::Status::Canceled };
81
    $params->{branchcode} = $branchcode if $branchcode;
82
    return Koha::ArticleRequests->search( $params );
83
}
84
85
=head3 _type
86
87
=cut
88
89
sub _type {
90
    return 'ArticleRequest';
91
}
92
93
sub object_class {
94
    return 'Koha::ArticleRequest';
95
}
96
97
=head1 AUTHOR
98
99
Kyle M Hall <kyle@bywatersolutions.com>
100
101
=cut
102
103
1;
(-)a/Koha/Biblio.pm (+198 lines)
Lines 27-32 use Koha::Database; Link Here
27
27
28
use base qw(Koha::Object);
28
use base qw(Koha::Object);
29
29
30
use C4::Circulation qw(GetIssuingRule);
31
use Koha::Items;
32
use Koha::Biblioitems;
33
use Koha::ArticleRequests;
34
use Koha::ArticleRequest::Status;
35
30
=head1 NAME
36
=head1 NAME
31
37
32
Koha::Biblio - Koha Biblio Object class
38
Koha::Biblio - Koha Biblio Object class
Lines 53-60 sub subtitles { Link Here
53
    return map { $_->{subfield} } @{ GetRecordValue( 'subtitle', GetMarcBiblio( $self->id ), $self->frameworkcode ) };
59
    return map { $_->{subfield} } @{ GetRecordValue( 'subtitle', GetMarcBiblio( $self->id ), $self->frameworkcode ) };
54
}
60
}
55
61
62
=head3 can_article_request
63
64
my $bool = $biblio->can_article_request( $borrower );
65
66
Returns true if article requests can be made for this record
67
68
$borrower must be a Koha::Patron object
69
70
=cut
71
72
sub can_article_request {
73
    my ( $self, $borrower ) = @_;
74
75
    my $rule = $self->article_request_type($borrower);
76
    return q{} if $rule eq 'item_only' && !$self->items()->count();
77
    return 1 if $rule && $rule ne 'no';
78
79
    return q{};
80
}
81
82
=head3 article_request_type
83
84
my $type = $biblio->article_request_type( $borrower );
85
86
Returns the article request type based on items, or on the record
87
itself if there are no items.
88
89
$borrower must be a Koha::Patron object
90
91
=cut
92
93
sub article_request_type {
94
    my ( $self, $borrower ) = @_;
95
96
    return q{} unless $borrower;
97
98
    my $rule = $self->article_request_type_for_items( $borrower );
99
    return $rule if $rule;
100
101
    # If the record has no items that are requestable, go by the record itemtype
102
    $rule = $self->article_request_type_for_bib($borrower);
103
    return $rule if $rule;
104
105
    return q{};
106
}
107
108
=head3 article_request_type_for_bib
109
110
my $type = $biblio->article_request_type_for_bib
111
112
Returns the article request type 'yes', 'no', 'item_only', 'bib_only', for the given record
113
114
=cut
115
116
sub article_request_type_for_bib {
117
    my ( $self, $borrower ) = @_;
118
119
    return q{} unless $borrower;
120
121
    my $borrowertype = $borrower->categorycode;
122
    my $itemtype     = $self->itemtype();
123
124
    my $rules        = C4::Circulation::GetIssuingRule( $borrowertype, $itemtype );
125
126
    return $rules->{article_requests} || q{};
127
}
128
129
=head3 article_request_type_for_items
130
131
my $type = $biblio->article_request_type_for_items
132
133
Returns the article request type 'yes', 'no', 'item_only', 'bib_only', for the given record's items
134
135
If there is a conflict where some items are 'bib_only' and some are 'item_only', 'bib_only' will be returned.
136
137
=cut
138
139
sub article_request_type_for_items {
140
    my ( $self, $borrower ) = @_;
141
142
    my $counts;
143
    foreach my $item ( $self->items()->as_list() ) {
144
        my $rule = $item->article_request_type($borrower);
145
        return $rule if $rule eq 'bib_only';    # we don't need to go any further
146
        $counts->{$rule}++;
147
    }
148
149
    return 'item_only' if $counts->{item_only};
150
    return 'yes'       if $counts->{yes};
151
    return 'no'        if $counts->{no};
152
    return q{};
153
}
154
155
=head3 article_requests
156
157
my @requests = $biblio->article_requests
158
159
Returns the article requests associated with this Biblio
160
161
=cut
162
163
sub article_requests {
164
    my ( $self, $borrower ) = @_;
165
166
    $self->{_article_requests} ||= Koha::ArticleRequests->search( { biblionumber => $self->biblionumber() } );
167
168
    return wantarray ? $self->{_article_requests}->as_list : $self->{_article_requests};
169
}
170
171
=head3 article_requests_current
172
173
my @requests = $biblio->article_requests_current
174
175
Returns the article requests associated with this Biblio that are incomplete
176
177
=cut
178
179
sub article_requests_current {
180
    my ( $self, $borrower ) = @_;
181
182
    $self->{_article_requests_current} ||= Koha::ArticleRequests->search(
183
        {
184
            biblionumber => $self->biblionumber(),
185
            -or          => [
186
                { status => Koha::ArticleRequest::Status::Pending },
187
                { status => Koha::ArticleRequest::Status::Processing }
188
            ]
189
        }
190
    );
191
192
    return wantarray ? $self->{_article_requests_current}->as_list : $self->{_article_requests_current};
193
}
194
195
=head3 article_requests_finished
196
197
my @requests = $biblio->article_requests_finished
198
199
Returns the article requests associated with this Biblio that are completed
200
201
=cut
202
203
sub article_requests_finished {
204
    my ( $self, $borrower ) = @_;
205
206
    $self->{_article_requests_finished} ||= Koha::ArticleRequests->search(
207
        {
208
            biblionumber => $self->biblionumber(),
209
            -or          => [
210
                { status => Koha::ArticleRequest::Status::Completed },
211
                { status => Koha::ArticleRequest::Status::Canceled }
212
            ]
213
        }
214
    );
215
216
    return wantarray ? $self->{_article_requests_finished}->as_list : $self->{_article_requests_finished};
217
}
218
219
=head3 items
220
56
=head3 items
221
=head3 items
57
222
223
my @items = $biblio->items();
224
my $items = $biblio->items();
225
58
Returns the related Koha::Items object for this biblio in scalar context,
226
Returns the related Koha::Items object for this biblio in scalar context,
59
or list of Koha::Item objects in list context.
227
or list of Koha::Item objects in list context.
60
228
Lines 68-73 sub items { Link Here
68
    return wantarray ? $self->{_items}->as_list : $self->{_items};
236
    return wantarray ? $self->{_items}->as_list : $self->{_items};
69
}
237
}
70
238
239
=head3 itemtype
240
241
my $itemtype = $biblio->itemtype();
242
243
Returns the itemtype for this record.
244
245
=cut
246
247
sub itemtype {
248
    my ( $self ) = @_;
249
250
    return $self->_biblioitem()->itemtype();
251
}
252
253
=head3 _biblioitem
254
255
my $field = $self->_biblioitem()->itemtype
256
257
Returns the related Koha::Biblioitem object for this Biblio object
258
259
=cut
260
261
sub _biblioitem {
262
    my ($self) = @_;
263
264
    $self->{_biblioitem} ||= Koha::Biblioitems->find( { biblionumber => $self->biblionumber() } );
265
266
    return $self->{_biblioitem};
267
}
268
71
=head3 type
269
=head3 type
72
270
73
=cut
271
=cut
(-)a/Koha/Biblios.pm (-1 / +1 lines)
Lines 1-6 Link Here
1
package Koha::Biblios;
1
package Koha::Biblios;
2
2
3
# Copyright ByWater Solutions 2014
3
# Copyright ByWater Solutions 2015
4
#
4
#
5
# This file is part of Koha.
5
# This file is part of Koha.
6
#
6
#
(-)a/Koha/Item.pm (+47 lines)
Lines 23-28 use Carp; Link Here
23
23
24
use Koha::Database;
24
use Koha::Database;
25
25
26
use C4::Context;
27
use C4::Circulation qw(GetIssuingRule);
28
use Koha::Patrons;
26
use Koha::Patrons;
29
use Koha::Patrons;
27
use Koha::Libraries;
30
use Koha::Libraries;
28
31
Lines 107-112 sub last_returned_by { Link Here
107
    }
110
    }
108
}
111
}
109
112
113
=head3 can_article_request
114
115
my $bool = $item->can_article_request( $borrower )
116
117
Returns true if item can be specifically requested
118
119
$borrower must be a Koha::Patron object
120
121
=cut
122
123
sub can_article_request {
124
    my ( $self, $borrower ) = @_;
125
126
    my $rule = $self->article_request_type($borrower);
127
128
    return 1 if $rule && $rule ne 'no' && $rule ne 'bib_only';
129
    return q{};
130
}
131
132
=head3 article_request_type
133
134
my $type = $item->article_request_type( $borrower )
135
136
returns 'yes', 'no', 'bib_only', or 'item_only'
137
138
$borrower must be a Koha::Patron object
139
140
=cut
141
142
sub article_request_type {
143
    my ( $self, $borrower ) = @_;
144
145
    my $branch_control = C4::Context->preference('HomeOrHoldingBranch');
146
    my $branchcode =
147
        $branch_control eq 'homebranch'    ? $self->homebranch
148
      : $branch_control eq 'holdingbranch' ? $self->holdingbranch
149
      :                                      undef;
150
    my $borrowertype = $borrower->categorycode;
151
    my $itemtype = $self->effective_itemtype();
152
    my $rules = GetIssuingRule( $borrowertype, $itemtype, $branchcode );
153
154
    return $rules->{article_requests} || q{};
155
}
156
110
=head3 type
157
=head3 type
111
158
112
=cut
159
=cut
(-)a/Koha/Patron.pm (+67 lines)
Lines 95-100 sub siblings { Link Here
95
    );
95
    );
96
}
96
}
97
97
98
=head3 article_requests
99
100
my @requests = $borrower->article_requests();
101
my $requests = $borrower->article_requests();
102
103
Returns either a list of ArticleRequests objects,
104
or an ArtitleRequests object, depending on the
105
calling context.
106
107
=cut
108
109
sub article_requests {
110
    my ( $self ) = @_;
111
112
    $self->{_article_requests} ||= Koha::ArticleRequests->search({ borrowernumber => $self->borrowernumber() });
113
114
    return $self->{_article_requests};
115
}
116
117
=head3 article_requests_current
118
119
my @requests = $patron->article_requests_current
120
121
Returns the article requests associated with this patron that are incomplete
122
123
=cut
124
125
sub article_requests_current {
126
    my ( $self ) = @_;
127
128
    $self->{_article_requests_current} ||= Koha::ArticleRequests->search(
129
        {
130
            borrowernumber => $self->id(),
131
            -or          => [
132
                { status => Koha::ArticleRequest::Status::Pending },
133
                { status => Koha::ArticleRequest::Status::Processing }
134
            ]
135
        }
136
    );
137
138
    return $self->{_article_requests_current};
139
}
140
141
=head3 article_requests_finished
142
143
my @requests = $biblio->article_requests_finished
144
145
Returns the article requests associated with this patron that are completed
146
147
=cut
148
149
sub article_requests_finished {
150
    my ( $self, $borrower ) = @_;
151
152
    $self->{_article_requests_finished} ||= Koha::ArticleRequests->search(
153
        {
154
            borrowernumber => $self->id(),
155
            -or          => [
156
                { status => Koha::ArticleRequest::Status::Completed },
157
                { status => Koha::ArticleRequest::Status::Canceled }
158
            ]
159
        }
160
    );
161
162
    return $self->{_article_requests_finished};
163
}
164
98
=head3 type
165
=head3 type
99
166
100
=cut
167
=cut
(-)a/Koha/Patrons.pm (+81 lines)
Lines 23-28 use Carp; Link Here
23
23
24
use Koha::Database;
24
use Koha::Database;
25
25
26
use Koha::ArticleRequests;
27
use Koha::ArticleRequest::Status;
26
use Koha::Patron;
28
use Koha::Patron;
27
29
28
use base qw(Koha::Objects);
30
use base qw(Koha::Objects);
Lines 37-42 Koha::Patron - Koha Patron Object class Link Here
37
39
38
=cut
40
=cut
39
41
42
=head3 guarantor
43
44
Returns a Koha::Patron object for this borrower's guarantor
45
46
=cut
47
48
sub guarantor {
49
    my ( $self ) = @_;
50
51
    return Koha::Patrons->find( $self->guarantorid() );
52
}
53
54
=head3 article_requests
55
56
my @requests = $borrower->article_requests();
57
my $requests = $borrower->article_requests();
58
59
Returns either a list of ArticleRequests objects,
60
or an ArtitleRequests object, depending on the
61
calling context.
62
63
=cut
64
65
sub article_requests {
66
    my ( $self ) = @_;
67
68
    $self->{_article_requests} ||= Koha::ArticleRequests->search({ borrowernumber => $self->borrowernumber() });
69
70
    return $self->{_article_requests};
71
}
72
73
=head3 article_requests_current
74
75
my @requests = $patron->article_requests_current
76
77
Returns the article requests associated with this patron that are incomplete
78
79
=cut
80
81
sub article_requests_current {
82
    my ( $self ) = @_;
83
84
    $self->{_article_requests_current} ||= Koha::ArticleRequests->search(
85
        {
86
            borrowernumber => $self->id(),
87
            -or          => [
88
                { status => Koha::ArticleRequest::Status::Pending },
89
                { status => Koha::ArticleRequest::Status::Processing }
90
            ]
91
        }
92
    );
93
94
    return $self->{_article_requests_current};
95
}
96
97
=head3 article_requests_finished
98
99
my @requests = $biblio->article_requests_finished
100
101
Returns the article requests associated with this patron that are completed
102
103
=cut
104
105
sub article_requests_finished {
106
    my ( $self, $borrower ) = @_;
107
108
    $self->{_article_requests_finished} ||= Koha::ArticleRequests->search(
109
        {
110
            borrowernumber => $self->id(),
111
            -or          => [
112
                { status => Koha::ArticleRequest::Status::Completed },
113
                { status => Koha::ArticleRequest::Status::Canceled }
114
            ]
115
        }
116
    );
117
118
    return $self->{_article_requests_finished};
119
}
120
40
=head3 type
121
=head3 type
41
122
42
=cut
123
=cut
(-)a/Koha/Template/Plugin/Biblio.pm (-1 / +31 lines)
Lines 23-28 use Template::Plugin; Link Here
23
use base qw( Template::Plugin );
23
use base qw( Template::Plugin );
24
24
25
use Koha::Holds;
25
use Koha::Holds;
26
use Koha::Biblios;
27
use Koha::Patrons;
28
use Koha::ArticleRequests;
29
use Koha::ArticleRequest::Status;
26
30
27
sub HoldsCount {
31
sub HoldsCount {
28
    my ( $self, $biblionumber ) = @_;
32
    my ( $self, $biblionumber ) = @_;
Lines 32-35 sub HoldsCount { Link Here
32
    return $holds->count();
36
    return $holds->count();
33
}
37
}
34
38
39
sub ArticleRequestsActiveCount {
40
    my ( $self, $biblionumber ) = @_;
41
42
    my $ar = Koha::ArticleRequests->search(
43
        {
44
            biblionumber => $biblionumber,
45
            status       => [
46
                -or => [
47
                    status => Koha::ArticleRequest::Status::Pending,
48
                    status => Koha::ArticleRequest::Status::Processing
49
                ]
50
            ]
51
        }
52
    );
53
54
    return $ar->count();
55
}
56
57
sub CanArticleRequest {
58
    my ( $self, $biblionumber, $borrowernumber ) = @_;
59
60
    my $biblio = Koha::Biblios->find( $biblionumber );
61
    my $borrower = Koha::Patrons->find( $borrowernumber );
62
63
    return $biblio ? $biblio->can_article_request( $borrower ) : 0;
64
}
65
35
1;
66
1;
36
- 

Return to bug 14610