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