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

(-)a/C4/Letters.pm (-12 / +13 lines)
Lines 766-783 sub _parseletter_sth { Link Here
766
    #       broke things for the rest of us. prepare_cached is a better
766
    #       broke things for the rest of us. prepare_cached is a better
767
    #       way to cache statement handles anyway.
767
    #       way to cache statement handles anyway.
768
    my $query = 
768
    my $query = 
769
    ($table eq 'biblio'       ) ? "SELECT * FROM $table WHERE   biblionumber = ?"                                  :
769
    ($table eq 'biblio'       )    ? "SELECT * FROM $table WHERE   biblionumber = ?"                                  :
770
    ($table eq 'biblioitems'  ) ? "SELECT * FROM $table WHERE   biblionumber = ?"                                  :
770
    ($table eq 'biblioitems'  )    ? "SELECT * FROM $table WHERE   biblionumber = ?"                                  :
771
    ($table eq 'items'        ) ? "SELECT * FROM $table WHERE     itemnumber = ?"                                  :
771
    ($table eq 'items'        )    ? "SELECT * FROM $table WHERE     itemnumber = ?"                                  :
772
    ($table eq 'issues'       ) ? "SELECT * FROM $table WHERE     itemnumber = ?"                                  :
772
    ($table eq 'issues'       )    ? "SELECT * FROM $table WHERE     itemnumber = ?"                                  :
773
    ($table eq 'old_issues'   ) ? "SELECT * FROM $table WHERE     itemnumber = ? ORDER BY timestamp DESC LIMIT 1"  :
773
    ($table eq 'old_issues'   )    ? "SELECT * FROM $table WHERE     itemnumber = ? ORDER BY timestamp DESC LIMIT 1"  :
774
    ($table eq 'reserves'     ) ? "SELECT * FROM $table WHERE borrowernumber = ? and biblionumber = ?"             :
774
    ($table eq 'reserves'     )    ? "SELECT * FROM $table WHERE borrowernumber = ? and biblionumber = ?"             :
775
    ($table eq 'borrowers'    ) ? "SELECT * FROM $table WHERE borrowernumber = ?"                                  :
775
    ($table eq 'borrowers'    )    ? "SELECT * FROM $table WHERE borrowernumber = ?"                                  :
776
    ($table eq 'branches'     ) ? "SELECT * FROM $table WHERE     branchcode = ?"                                  :
776
    ($table eq 'branches'     )    ? "SELECT * FROM $table WHERE     branchcode = ?"                                  :
777
    ($table eq 'suggestions'  ) ? "SELECT * FROM $table WHERE   suggestionid = ?"                                  :
777
    ($table eq 'suggestions'  )    ? "SELECT * FROM $table WHERE   suggestionid = ?"                                  :
778
    ($table eq 'aqbooksellers') ? "SELECT * FROM $table WHERE             id = ?"                                  :
778
    ($table eq 'aqbooksellers')    ? "SELECT * FROM $table WHERE             id = ?"                                  :
779
    ($table eq 'aqorders'     ) ? "SELECT * FROM $table WHERE    ordernumber = ?"                                  :
779
    ($table eq 'aqorders'     )    ? "SELECT * FROM $table WHERE    ordernumber = ?"                                  :
780
    ($table eq 'opac_news'    ) ? "SELECT * FROM $table WHERE          idnew = ?"                                  :
780
    ($table eq 'opac_news'    )    ? "SELECT * FROM $table WHERE          idnew = ?"                                  :
781
    ($table eq 'article_requests') ? "SELECT * FROM $table WHERE             id = ?"                                  :
781
    ($table eq 'borrower_modifications') ? "SELECT * FROM $table WHERE verification_token = ?" :
782
    ($table eq 'borrower_modifications') ? "SELECT * FROM $table WHERE verification_token = ?" :
782
    ($table eq 'subscription') ? "SELECT * FROM $table WHERE subscriptionid = ?" :
783
    ($table eq 'subscription') ? "SELECT * FROM $table WHERE subscriptionid = ?" :
783
    ($table eq 'serial') ? "SELECT * FROM $table WHERE serialid = ?" :
784
    ($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 (+46 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);
26
use Koha::Item::Transfer;
28
use Koha::Item::Transfer;
27
use Koha::Patrons;
29
use Koha::Patrons;
28
use Koha::Libraries;
30
use Koha::Libraries;
Lines 123-128 sub last_returned_by { Link Here
123
    }
125
    }
124
}
126
}
125
127
128
=head3 can_article_request
129
130
my $bool = $item->can_article_request( $borrower )
131
132
Returns true if item can be specifically requested
133
134
$borrower must be a Koha::Patron object
135
136
=cut
137
138
sub can_article_request {
139
    my ( $self, $borrower ) = @_;
140
141
    my $rule = $self->article_request_type($borrower);
142
143
    return 1 if $rule && $rule ne 'no' && $rule ne 'bib_only';
144
    return q{};
145
}
146
147
=head3 article_request_type
148
149
my $type = $item->article_request_type( $borrower )
150
151
returns 'yes', 'no', 'bib_only', or 'item_only'
152
153
$borrower must be a Koha::Patron object
154
155
=cut
156
157
sub article_request_type {
158
    my ( $self, $borrower ) = @_;
159
160
    my $branch_control = C4::Context->preference('HomeOrHoldingBranch');
161
    my $branchcode =
162
        $branch_control eq 'homebranch'    ? $self->homebranch
163
      : $branch_control eq 'holdingbranch' ? $self->holdingbranch
164
      :                                      undef;
165
    my $borrowertype = $borrower->categorycode;
166
    my $itemtype = $self->effective_itemtype();
167
    my $rules = GetIssuingRule( $borrowertype, $itemtype, $branchcode );
168
169
    return $rules->{article_requests} || q{};
170
}
171
126
=head3 type
172
=head3 type
127
173
128
=cut
174
=cut
(-)a/Koha/Patron.pm (+67 lines)
Lines 359-364 sub move_to_deleted { Link Here
359
    return Koha::Database->new->schema->resultset('Deletedborrower')->create($patron_infos);
359
    return Koha::Database->new->schema->resultset('Deletedborrower')->create($patron_infos);
360
}
360
}
361
361
362
=head3 article_requests
363
364
my @requests = $borrower->article_requests();
365
my $requests = $borrower->article_requests();
366
367
Returns either a list of ArticleRequests objects,
368
or an ArtitleRequests object, depending on the
369
calling context.
370
371
=cut
372
373
sub article_requests {
374
    my ( $self ) = @_;
375
376
    $self->{_article_requests} ||= Koha::ArticleRequests->search({ borrowernumber => $self->borrowernumber() });
377
378
    return $self->{_article_requests};
379
}
380
381
=head3 article_requests_current
382
383
my @requests = $patron->article_requests_current
384
385
Returns the article requests associated with this patron that are incomplete
386
387
=cut
388
389
sub article_requests_current {
390
    my ( $self ) = @_;
391
392
    $self->{_article_requests_current} ||= Koha::ArticleRequests->search(
393
        {
394
            borrowernumber => $self->id(),
395
            -or          => [
396
                { status => Koha::ArticleRequest::Status::Pending },
397
                { status => Koha::ArticleRequest::Status::Processing }
398
            ]
399
        }
400
    );
401
402
    return $self->{_article_requests_current};
403
}
404
405
=head3 article_requests_finished
406
407
my @requests = $biblio->article_requests_finished
408
409
Returns the article requests associated with this patron that are completed
410
411
=cut
412
413
sub article_requests_finished {
414
    my ( $self, $borrower ) = @_;
415
416
    $self->{_article_requests_finished} ||= Koha::ArticleRequests->search(
417
        {
418
            borrowernumber => $self->id(),
419
            -or          => [
420
                { status => Koha::ArticleRequest::Status::Completed },
421
                { status => Koha::ArticleRequest::Status::Canceled }
422
            ]
423
        }
424
    );
425
426
    return $self->{_article_requests_finished};
427
}
428
362
=head3 type
429
=head3 type
363
430
364
=cut
431
=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 67-72 sub search_housebound_deliverers { Link Here
67
    return Koha::Patrons->_new_from_dbic($del);
69
    return Koha::Patrons->_new_from_dbic($del);
68
}
70
}
69
71
72
=head3 guarantor
73
74
Returns a Koha::Patron object for this borrower's guarantor
75
76
=cut
77
78
sub guarantor {
79
    my ( $self ) = @_;
80
81
    return Koha::Patrons->find( $self->guarantorid() );
82
}
83
84
=head3 article_requests
85
86
my @requests = $borrower->article_requests();
87
my $requests = $borrower->article_requests();
88
89
Returns either a list of ArticleRequests objects,
90
or an ArtitleRequests object, depending on the
91
calling context.
92
93
=cut
94
95
sub article_requests {
96
    my ( $self ) = @_;
97
98
    $self->{_article_requests} ||= Koha::ArticleRequests->search({ borrowernumber => $self->borrowernumber() });
99
100
    return $self->{_article_requests};
101
}
102
103
=head3 article_requests_current
104
105
my @requests = $patron->article_requests_current
106
107
Returns the article requests associated with this patron that are incomplete
108
109
=cut
110
111
sub article_requests_current {
112
    my ( $self ) = @_;
113
114
    $self->{_article_requests_current} ||= Koha::ArticleRequests->search(
115
        {
116
            borrowernumber => $self->id(),
117
            -or          => [
118
                { status => Koha::ArticleRequest::Status::Pending },
119
                { status => Koha::ArticleRequest::Status::Processing }
120
            ]
121
        }
122
    );
123
124
    return $self->{_article_requests_current};
125
}
126
127
=head3 article_requests_finished
128
129
my @requests = $biblio->article_requests_finished
130
131
Returns the article requests associated with this patron that are completed
132
133
=cut
134
135
sub article_requests_finished {
136
    my ( $self, $borrower ) = @_;
137
138
    $self->{_article_requests_finished} ||= Koha::ArticleRequests->search(
139
        {
140
            borrowernumber => $self->id(),
141
            -or          => [
142
                { status => Koha::ArticleRequest::Status::Completed },
143
                { status => Koha::ArticleRequest::Status::Canceled }
144
            ]
145
        }
146
    );
147
148
    return $self->{_article_requests_finished};
149
}
150
70
=head3 type
151
=head3 type
71
152
72
=cut
153
=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