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 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::BiblioUtils::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<marcxml> column from the biblioitems table.
34 use Koha::BiblioUtils::Iterator;
35 my $rs = $schema->resultset('biblioitems');
36 my $iterator = Koha::BiblioUtils::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();
95 if ( $row->marcxml ) {
96 $marc = MARC::Record->new_from_xml( $row->marcxml );
99 confess "No marcxml column returned in the request.";
103 if ( $self->{items} ) {
104 $bibnum = $row->get_column('biblionumber');
105 confess "No biblionumber column returned in the request."
106 if ( !defined($bibnum) );
108 # TODO this should really be in Koha::BiblioUtils or something similar.
109 C4::Biblio::EmbedItemsInMarcBiblio( $marc, $bibnum );
113 $bibnum //= $row->get_column('biblionumber');
114 confess "No biblionumber column returned in the request."
115 if ( !defined($bibnum) );
116 return ( $bibnum, $marc );