Bug 10566: (follow-up) fix HTML validation issues
[koha.git] / Koha / Util / MARC.pm
blobfc3c9f247c8a7e984560e483c3c031d91e4aa934
1 package Koha::Util::MARC;
3 # Copyright 2013 C & P Bibliography Services
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use Modern::Perl;
21 use MARC::Record;
23 =head1 NAME
25 Koha::Util::MARC - utility class with routines for working with MARC records
27 =head1 METHODS
29 =head2 createMergeHash
31 Create a hash to use when merging MARC records
33 =cut
35 sub createMergeHash {
36 my ( $record, $tagslib ) = @_;
38 return unless $record;
40 my @array;
41 my @fields = $record->fields();
43 foreach my $field (@fields) {
44 my $fieldtag = $field->tag();
45 if ( $fieldtag < 10 ) {
46 if ( !defined($tagslib)
47 || $tagslib->{$fieldtag}->{'@'}->{'tab'} >= 0 )
49 push @array,
51 field => [
53 tag => $fieldtag,
54 key => _createKey(),
55 value => $field->data(),
61 else {
62 my @subfields = $field->subfields();
63 my @subfield_array;
64 foreach my $subfield (@subfields) {
65 if ( !defined($tagslib)
66 || $tagslib->{$fieldtag}->{ @$subfield[0] }->{'tab'} >= 0 )
68 push @subfield_array,
70 subtag => @$subfield[0],
71 subkey => _createKey(),
72 value => @$subfield[1],
78 if ( !defined($tagslib) || @subfield_array )
80 push @array,
82 field => [
84 tag => $fieldtag,
85 key => _createKey(),
86 indicator1 => $field->indicator(1),
87 indicator2 => $field->indicator(2),
88 subfield => [@subfield_array],
96 return [@array];
99 =head2 _createKey
101 Create a random value to set it into the input name
103 =cut
105 sub _createKey {
106 return int(rand(1000000));