1 package Koha::BiblioUtils::Iterator;
3 # This contains an iterator over biblio records
5 # Copyright 2014 Catalyst IT
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 Koha::BiblioUtils::Iterator - iterates over biblios provided by a DBIx::Class::ResultSet
28 This provides an iterator over a L<DBIx::Class::ResultSet> that contains a
30 Returns a MARC::Record in scalar context.
31 Returns biblionumber and marc in list context.
35 use Koha::BiblioUtils::Iterator;
36 my $rs = $schema->resultset('biblioitems');
37 my $iterator = Koha::BiblioUtils::Iterator->new($rs);
38 while (my $record = $iterator->next()) {
39 // do something with $record
47 use Koha::Biblio::Metadata;
49 use Carp qw( confess );
56 my $it = new($sth, option => $value, ...);
58 Takes a ResultSet to iterate over, and gives you an iterator on it. Optional
59 options may be specified.
67 Set to true to include item data in the resulting MARC record.
74 my ( $class, $rs, %options ) = @_;
84 In a scalar context, provides the next MARC::Record from the ResultSet, or
85 C<undef> if there are no more.
87 In a list context it will provide ($biblionumber, $record).
95 my $row = $self->{rs}->next();
97 my $marcxml = C4::Biblio::GetXmlBiblio( $row->get_column('biblionumber') );
99 $marc = MARC::Record->new_from_xml( $marcxml, 'UTF-8' );
102 confess "No marcxml column returned in the request.";
106 if ( $self->{items} ) {
107 $bibnum = $row->get_column('biblionumber');
108 confess "No biblionumber column returned in the request."
109 if ( !defined($bibnum) );
111 $marc = Koha::Biblio::Metadata->record(
115 biblionumber => $bibnum,
121 $bibnum //= $row->get_column('biblionumber');
122 confess "No biblionumber column returned in the request."
123 if ( !defined($bibnum) );
124 return ( $bibnum, $marc );