=head1 API
-=head2 Class Methods
+=head2 Class methods
=cut
sub get_items_that_can_fill {
my ( $self ) = @_;
- my @biblionumbers = $self->get_column('biblionumber');
-
- my @branchtransfers = map { $_->itemnumber }
- Koha::Item::Transfers->search(
- { datearrived => undef },
- {
- columns => ['itemnumber'],
- collapse => 1,
- }
- );
- my @waiting_holds = map { $_->itemnumber }
- Koha::Holds->search(
- { 'found' => 'W' },
- {
- columns => ['itemnumber'],
- collapse => 1,
- }
- );
-
- my @hold_not_allowed_itypes = Koha::CirculationRules->search(
+ return Koha::Items->new->empty()
+ unless $self->count() > 0;
+
+ my @itemnumbers = $self->search({ 'me.itemnumber' => { '!=' => undef } })->get_column('itemnumber');
+ my @biblionumbers = $self->search({ 'me.itemnumber' => undef })->get_column('biblionumber');
+ my @bibs_or_items;
+ push @bibs_or_items, 'me.itemnumber' => { in => \@itemnumbers } if @itemnumbers;
+ push @bibs_or_items, 'me.biblionumber' => { in => \@biblionumbers } if @biblionumbers;
+
+ my @branchtransfers = Koha::Item::Transfers->filter_by_current->search({}, {
+ columns => ['itemnumber'],
+ collapse => 1,
+ }
+ )->get_column('itemnumber');
+ my @waiting_holds = Koha::Holds->search(
+ { 'found' => 'W' },
{
- rule_name => 'holdallowed',
- branchcode => undef,
- categorycode => undef,
- rule_value => 'not_allowed',
+ columns => ['itemnumber'],
+ collapse => 1,
}
- )->get_column('itemtype');
+ )->get_column('itemnumber');
return Koha::Items->search(
{
- biblionumber => { in => \@biblionumbers },
- itemlost => 0,
- withdrawn => 0,
- notforloan => 0,
- onloan => undef,
+ -or => \@bibs_or_items,
itemnumber => { -not_in => [ @branchtransfers, @waiting_holds ] },
- itype => { -not_in => \@hold_not_allowed_itypes },
+ onloan => undef,
+ notforloan => 0,
}
- );
+ )->filter_by_for_hold();
+}
+
+=head3 filter_by_has_cancellation_requests
+
+ my $with_cancellation_reqs = $holds->filter_by_has_cancellation_requests;
+
+Returns a filtered resultset only containing holds that have cancellation requests.
+
+=cut
+
+sub filter_by_has_cancellation_requests {
+ my ($self) = @_;
+
+ return $self->search( { 'hold_cancellation_request_id' => { '!=' => undef } },
+ { join => 'cancellation_requests' } );
}
-=head3 type
+=head3 filter_out_has_cancellation_requests
+
+ my $holds_without_cancellation_requests = $holds->filter_out_has_cancellation_requests;
+
+Returns a filtered resultset without holds with cancellation requests.
+
+=cut
+
+sub filter_out_has_cancellation_requests {
+ my ($self) = @_;
+
+ return $self->search( { 'hold_cancellation_request_id' => { '=' => undef } },
+ { join => 'cancellation_requests' } );
+}
+
+=head2 Internal methods
+
+=head3 _type
=cut