Bug 15412: Enable dropdowns date selector when suspending holds
[koha.git] / Koha / Util / MARC.pm
blob5d026ee3cfb821e53c9992e3e18c071131b2fff9
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 (
66 !defined($tagslib)
67 || ( defined $tagslib->{$fieldtag}
68 && defined $tagslib->{$fieldtag}->{ @$subfield[0] }
69 && defined $tagslib->{$fieldtag}->{ @$subfield[0] }->{'tab'}
70 && $tagslib->{$fieldtag}->{ @$subfield[0] }->{'tab'} >= 0 )
73 push @subfield_array,
75 subtag => @$subfield[0],
76 subkey => _createKey(),
77 value => @$subfield[1],
83 if (
85 !defined($tagslib) || ( defined $tagslib->{$fieldtag}
86 && defined $tagslib->{$fieldtag}->{'tab'}
87 && $tagslib->{$fieldtag}->{'tab'} >= 0 )
89 && @subfield_array
92 push @array,
94 field => [
96 tag => $fieldtag,
97 key => _createKey(),
98 indicator1 => $field->indicator(1),
99 indicator2 => $field->indicator(2),
100 subfield => [@subfield_array],
108 return [@array];
111 =head2 _createKey
113 Create a random value to set it into the input name
115 =cut
117 sub _createKey {
118 return int(rand(1000000));
121 =head2 getAuthorityAuthorizedHeading
123 Retrieve the authorized heading from a MARC authority record
125 =cut
127 sub getAuthorityAuthorizedHeading {
128 my ( $record, $schema ) = @_;
129 return unless ( ref $record eq 'MARC::Record' );
130 if ( $schema eq 'unimarc' ) {
132 # construct UNIMARC summary, that is quite different from MARC21 one
133 # accepted form
134 foreach my $field ( $record->field('2..') ) {
135 return $field->as_string('abcdefghijlmnopqrstuvwxyz');
138 else {
139 foreach my $field ( $record->field('1..') ) {
140 my $tag = $field->tag();
141 next if "152" eq $tag;
143 # FIXME - 152 is not a good tag to use
144 # in MARC21 -- purely local tags really ought to be
145 # 9XX
146 if ( $tag eq '100' ) {
147 return $field->as_string('abcdefghjklmnopqrstvxyz68');
149 elsif ( $tag eq '110' ) {
150 return $field->as_string('abcdefghklmnoprstvxyz68');
152 elsif ( $tag eq '111' ) {
153 return $field->as_string('acdefghklnpqstvxyz68');
155 elsif ( $tag eq '130' ) {
156 return $field->as_string('adfghklmnoprstvxyz68');
158 elsif ( $tag eq '148' ) {
159 return $field->as_string('abvxyz68');
161 elsif ( $tag eq '150' ) {
162 return $field->as_string('abvxyz68');
164 elsif ( $tag eq '151' ) {
165 return $field->as_string('avxyz68');
167 elsif ( $tag eq '155' ) {
168 return $field->as_string('abvxyz68');
170 elsif ( $tag eq '180' ) {
171 return $field->as_string('vxyz68');
173 elsif ( $tag eq '181' ) {
174 return $field->as_string('vxyz68');
176 elsif ( $tag eq '182' ) {
177 return $field->as_string('vxyz68');
179 elsif ( $tag eq '185' ) {
180 return $field->as_string('vxyz68');
182 else {
183 return $field->as_string();
187 return;