1 package Koha
::Filter
::MARC
::EmbedSeeFromHeadings
;
3 # Copyright 2012 C & P Bibliography Services
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 Koha::Filter::MARC::EmbedSeeFromHeadings - embeds see from headings into MARC for indexing
29 Filter to embed see from headings into MARC records.
36 use Koha
::MetadataRecord
::Authority
;
37 use C4
::Biblio qw
/GetMarcFromKohaField/;
39 use base
qw(Koha::RecordProcessor::Base);
40 our $NAME = 'EmbedSeeFromHeadings';
45 my $newrecord = $filter->filter($record);
46 my $newrecords = $filter->filter(\@records);
48 Embed see from headings into the specified record(s) and return the result.
49 In order to differentiate added headings from actual headings, a 'z' is
50 put in the first indicator.
58 return unless defined $record;
60 if (ref $record eq 'ARRAY') {
62 foreach my $thisrec (@
$record) {
63 push @recarray, _processrecord
($thisrec);
65 $newrecord = \
@recarray;
66 } elsif (ref $record eq 'MARC::Record') {
67 $newrecord = _processrecord
($record);
76 my ($item_tag) = GetMarcFromKohaField
("items.itemnumber", '');
79 foreach my $field ( $record->fields() ) {
80 next if $field->is_control_field();
81 next if $field->tag() eq $item_tag;
82 my $authid = $field->subfield('9');
86 my $authority = Koha
::MetadataRecord
::Authority
->get_from_authid($authid);
87 next unless $authority;
88 my $auth_marc = $authority->record;
89 my @seefrom = $auth_marc->field('4..');
91 foreach my $authfield (@seefrom) {
92 my $tag = substr($field->tag(), 0, 1) . substr($authfield->tag(), 1, 2);
93 next if MARC
::Field
->is_controlfield_tag($tag);
94 my $newfield = MARC
::Field
->new($tag,
96 $authfield->indicator(2) || ' ',
98 foreach my $sub ($authfield->subfields()) {
99 my ($code,$val) = @
$sub;
100 $newfield->add_subfields( $code => $val );
102 $newfield->delete_subfield( code
=> '9' );
103 push @newfields, $newfield if (scalar($newfield->subfields()) > 0);
105 $record->append_fields(@newfields);