|
Lines 25-30
use Koha::Database;
Link Here
|
| 25 |
|
25 |
|
| 26 |
use base qw(Koha::Object); |
26 |
use base qw(Koha::Object); |
| 27 |
|
27 |
|
|
|
28 |
use C4::Circulation qw(GetIssuingRule); |
| 29 |
use Koha::Items; |
| 30 |
use Koha::ArticleRequests; |
| 31 |
use Koha::ArticleRequest::Status; |
| 32 |
|
| 28 |
=head1 NAME |
33 |
=head1 NAME |
| 29 |
|
34 |
|
| 30 |
Koha::Biblio - Koha Biblio Object class |
35 |
Koha::Biblio - Koha Biblio Object class |
|
Lines 35-40
Koha::Biblio - Koha Biblio Object class
Link Here
|
| 35 |
|
40 |
|
| 36 |
=cut |
41 |
=cut |
| 37 |
|
42 |
|
|
|
43 |
=head3 can_article_request |
| 44 |
|
| 45 |
my $bool = $biblio->can_article_request( $borrower ); |
| 46 |
|
| 47 |
Returns true if article requests can be made for this record |
| 48 |
|
| 49 |
$borrower must be a Koha::Borrower object |
| 50 |
|
| 51 |
=cut |
| 52 |
|
| 53 |
sub can_article_request { |
| 54 |
my ( $self, $borrower ) = @_; |
| 55 |
|
| 56 |
my $rule = $self->article_request_type($borrower); |
| 57 |
return q{} if $rule eq 'item_only' && !$self->items()->count(); |
| 58 |
return 1 if $rule && $rule ne 'no'; |
| 59 |
|
| 60 |
return q{}; |
| 61 |
} |
| 62 |
|
| 63 |
=head3 article_request_type |
| 64 |
|
| 65 |
my $type = $biblio->article_request_type( $borrower ); |
| 66 |
|
| 67 |
Returns the article request type based on items, or on the record |
| 68 |
itself if there are no items. |
| 69 |
|
| 70 |
$borrower must be a Koha::Borrower object |
| 71 |
|
| 72 |
=cut |
| 73 |
|
| 74 |
sub article_request_type { |
| 75 |
my ( $self, $borrower ) = @_; |
| 76 |
|
| 77 |
my $rule = $self->article_request_type_for_items( $borrower ); |
| 78 |
return $rule if $rule; |
| 79 |
|
| 80 |
# If the record has no items that are requestable, go by the record itemtype |
| 81 |
$rule = $self->article_request_type_for_bib($borrower); |
| 82 |
return $rule if $rule; |
| 83 |
|
| 84 |
return q{}; |
| 85 |
} |
| 86 |
|
| 87 |
=head3 article_request_type_for_bib |
| 88 |
|
| 89 |
my $type = $biblio->article_request_type_for_bib |
| 90 |
|
| 91 |
Returns the article request type 'yes', 'no', 'item_only', 'bib_only', for the given record |
| 92 |
|
| 93 |
=cut |
| 94 |
|
| 95 |
sub article_request_type_for_bib { |
| 96 |
my ( $self, $borrower ) = @_; |
| 97 |
|
| 98 |
my $borrowertype = $borrower->categorycode; |
| 99 |
my $itemtype = $self->itemtype(); |
| 100 |
my $rules = GetIssuingRule( $borrowertype, $itemtype ); |
| 101 |
|
| 102 |
return $rules->{article_requests} || q{}; |
| 103 |
} |
| 104 |
|
| 105 |
=head3 article_request_type_for_items |
| 106 |
|
| 107 |
my $type = $biblio->article_request_type_for_items |
| 108 |
|
| 109 |
Returns the article request type 'yes', 'no', 'item_only', 'bib_only', for the given record's items |
| 110 |
|
| 111 |
If there is a conflict where some items are 'bib_only' and some are 'item_only', 'bib_only' will be returned. |
| 112 |
|
| 113 |
=cut |
| 114 |
|
| 115 |
sub article_request_type_for_items { |
| 116 |
my ( $self, $borrower ) = @_; |
| 117 |
|
| 118 |
my $counts; |
| 119 |
foreach my $item ( $self->items()->as_list() ) { |
| 120 |
my $rule = $item->article_request_type($borrower); |
| 121 |
return $rule if $rule eq 'bib_only'; # we don't need to go any further |
| 122 |
$counts->{$rule}++; |
| 123 |
} |
| 124 |
|
| 125 |
return 'item_only' if $counts->{item_only}; |
| 126 |
return 'yes' if $counts->{yes}; |
| 127 |
return 'no' if $counts->{no}; |
| 128 |
return q{}; |
| 129 |
} |
| 130 |
|
| 131 |
=head3 article_requests |
| 132 |
|
| 133 |
my @requests = $biblio->article_requests |
| 134 |
|
| 135 |
Returns the article requests associated with this Biblio |
| 136 |
|
| 137 |
=cut |
| 138 |
|
| 139 |
sub article_requests { |
| 140 |
my ( $self, $borrower ) = @_; |
| 141 |
|
| 142 |
$self->{_article_requests} ||= Koha::ArticleRequests->search( { biblionumber => $self->biblionumber() } ); |
| 143 |
|
| 144 |
return wantarray ? $self->{_article_requests}->as_list : $self->{_article_requests}; |
| 145 |
} |
| 146 |
|
| 147 |
=head3 article_requests_current |
| 148 |
|
| 149 |
my @requests = $biblio->article_requests_current |
| 150 |
|
| 151 |
Returns the article requests associated with this Biblio that are incomplete |
| 152 |
|
| 153 |
=cut |
| 154 |
|
| 155 |
sub article_requests_current { |
| 156 |
my ( $self, $borrower ) = @_; |
| 157 |
|
| 158 |
$self->{_article_requests_current} ||= Koha::ArticleRequests->search( |
| 159 |
{ |
| 160 |
biblionumber => $self->biblionumber(), |
| 161 |
-or => [ |
| 162 |
{ status => Koha::ArticleRequest::Status::Open }, |
| 163 |
{ status => Koha::ArticleRequest::Status::Processing } |
| 164 |
] |
| 165 |
} |
| 166 |
); |
| 167 |
|
| 168 |
return wantarray ? $self->{_article_requests_current}->as_list : $self->{_article_requests_current}; |
| 169 |
} |
| 170 |
|
| 171 |
=head3 article_requests_finished |
| 172 |
|
| 173 |
my @requests = $biblio->article_requests_finished |
| 174 |
|
| 175 |
Returns the article requests associated with this Biblio that are completed |
| 176 |
|
| 177 |
=cut |
| 178 |
|
| 179 |
sub article_requests_finished { |
| 180 |
my ( $self, $borrower ) = @_; |
| 181 |
|
| 182 |
$self->{_article_requests_finished} ||= Koha::ArticleRequests->search( |
| 183 |
{ |
| 184 |
biblionumber => $self->biblionumber(), |
| 185 |
-or => [ |
| 186 |
{ status => Koha::ArticleRequest::Status::Completed }, |
| 187 |
{ status => Koha::ArticleRequest::Status::Canceled } |
| 188 |
] |
| 189 |
} |
| 190 |
); |
| 191 |
|
| 192 |
return wantarray ? $self->{_article_requests_finished}->as_list : $self->{_article_requests_finished}; |
| 193 |
} |
| 194 |
|
| 195 |
=head3 items |
| 196 |
|
| 197 |
my @items = $biblio->items(); |
| 198 |
my $items = $biblio->items(); |
| 199 |
|
| 200 |
Returns a list of Koha::Item objects or a Koha::Items object of |
| 201 |
items associated with this bib |
| 202 |
|
| 203 |
=cut |
| 204 |
|
| 205 |
sub items { |
| 206 |
my ( $self ) = @_; |
| 207 |
|
| 208 |
$self->{_items} ||= Koha::Items->search({ biblionumber => $self->biblionumber() }); |
| 209 |
|
| 210 |
return $self->{_items}; |
| 211 |
} |
| 212 |
|
| 38 |
=head3 type |
213 |
=head3 type |
| 39 |
|
214 |
|
| 40 |
=cut |
215 |
=cut |