|
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 |