use Modern::Perl;
-use Carp;
use Koha::Database;
use base qw(Koha::Objects);
+use Koha::SearchEngine::Indexer;
+
=head1 NAME
Koha::Items - Koha Item object set class
=cut
-=head3 filter_by_for_loan
+=head3 filter_by_for_hold
- my $filtered_items = $items->filter_by_for_loan;
+ my $filtered_items = $items->filter_by_for_hold;
-Return the items of the set that are loanable
+Return the items of the set that are holdable
=cut
-sub filter_by_for_loan {
+sub filter_by_for_hold {
my ($self) = @_;
- return $self->search( { notforloan => [ 0, undef ] } );
+ return $self->search( { notforloan => { '<=' => 0 } } ); # items with negative or zero notforloan value are holdable
}
=head3 filter_by_visible_in_opac
return $self->search( $params );
}
+=head3 move_to_biblio
+
+ $items->move_to_biblio($to_biblio);
+
+Move items to a given biblio.
+
+=cut
+
+sub move_to_biblio {
+ my ( $self, $to_biblio ) = @_;
+
+ my $biblionumbers = { $to_biblio->biblionumber => 1 };
+ while ( my $item = $self->next() ) {
+ $biblionumbers->{ $item->biblionumber } = 1;
+ $item->move_to_biblio( $to_biblio, { skip_record_index => 1 } );
+ }
+ my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
+ for my $biblionumber ( keys %{$biblionumbers} ) {
+ $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" );
+ }
+}
+
+
=head2 Internal methods
=head3 _type