1 package Koha::Biblio::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 under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 3 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 Koha::Biblio::Iterator - iterates over biblios provided by a DBIx::Class::ResultSet
28 This provides an iterator that gives the MARC::Record of each biblio that's
29 returned by a L<DBIx::Class::ResultSet> that provides a C<biblionumber>, and
30 C<marc> or C<marcxml> column from the biblioitems table.
34 use Koha::Biblio::Iterator;
35 my $rs = $schema->resultset('biblioitems');
36 my $iterator = Koha::Biblio::Iterator->new($rs);
37 while (my $record = $iterator->next()) {
38 // do something with $record
45 use C4::Biblio; # :( - for EmbedItemsInMarcBiblio
54 my $it = new($sth, option => $value, ...);
56 Takes a ResultSet to iterate over, and gives you an iterator on it. Optional
57 options may be specified.
65 Set to true to include item data in the resulting MARC record.
72 my ( $class, $rs, %options ) = @_;
82 In a scalar context, provides the next MARC::Record from the ResultSet, or
83 C<undef> if there are no more.
85 In a list context it will provide ($biblionumber, $record).
93 my $row = $self->{rs}->next();
96 $marc = MARC::Record->new_from_usmarc( $row->marc );
98 elsif ( $row->marcxml ) {
99 $marc = MARC::Record->new_from_xml( $row->marcxml );
102 confess "No marc or 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 # TODO this should really be in Koha::Biblio or something similar.
112 C4::Biblio::EmbedItemsInMarcBiblio( $marc, $bibnum );
116 $bibnum //= $row->get_column('biblionumber');
117 confess "No biblionumber column returned in the request."
118 if ( !defined($bibnum) );
119 return ( $bibnum, $marc );