1 package Koha::BiblioUtils;
3 # This contains functions to do with managing 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 - contains some handy biblio-related functions
28 This contains functions for operations on biblio records.
30 Note: really, C4::Biblio does the main functions, but the Koha namespace is
31 the new thing that should be used.
35 use C4::Biblio; # EmbedItemsInMarcBiblio
36 use Koha::Biblio::Iterator;
40 use base qw(Class::Accessor);
42 __PACKAGE__->mk_accessors(qw());
46 =head2 get_all_biblios_iterator
48 my $it = get_all_biblios_iterator();
50 This will provide an iterator object that will, one by one, provide the
51 MARC::Record of each biblio. This will include the item data.
53 The iterator is a Koha::Biblio::Iterator object.
57 sub get_all_biblios_iterator {
58 my $database = Koha::Database->new();
59 my $schema = $database->schema();
61 $schema->resultset('Biblioitem')->search( { marc => { '!=', undef } },
62 { columns => [qw/ biblionumber marc /] } );
63 return Koha::Biblio::Iterator->new($rs, items => 1);
66 =head2 get_marc_biblio
68 my $marc = get_marc_biblio($bibnum, %options);
70 This fetches the MARC::Record for the given biblio number. Nothing is returned
71 if the biblionumber couldn't be found (or it somehow has no MARC data.)
79 If set to true, item data is embedded in the record. Default is to not do this.
86 my ($class,$bibnum, %options) = @_;
88 my $database = Koha::Database->new();
89 my $schema = $database->schema();
91 $schema->resultset('Biblioitem')
92 ->search( { marc => { '!=', undef }, biblionumber => $bibnum },
93 { columns => [qw/ marc /] } );
95 my $row = $rs->next();
97 my $marc = MARC::Record->new_from_usmarc($row->marc);
99 # TODO implement this in this module
100 C4::Biblio::EmbedItemsInMarcBiblio($marc, $bibnum) if $options{item_data};