Josef Moravec
68eeefa07e
Test plan: Run tests, at least: t/db_dependent/Biblio.t t/db_dependent/Biblio/TransformHtmlToMarc.t t/db_dependent/Charset.t t/db_dependent/Circulation/GetTopIssues.t t/db_dependent/Filter_MARC_ViewPolicy.t t/db_dependent/ImportBatch.t t/db_dependent/Items.t t/db_dependent/Items/AutomaticItemModificationByAge.t t/db_dependent/Items/GetItemsForInventory.t t/db_dependent/Koha/Filter/EmbedItemsAvailability.t t/db_dependent/Serials.t t/db_dependent/XISBN.t t/db_dependent/FrameworkPlugin.t Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Signed-off-by: Michal Denar <black23@gmail.com> Signed-off-by: Bouzid Fergani <bouzid.fergani@inlibro.com> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
107 lines
3.1 KiB
Perl
107 lines
3.1 KiB
Perl
package Koha::Filter::MARC::EmbedSeeFromHeadings;
|
|
|
|
# Copyright 2012 C & P Bibliography Services
|
|
#
|
|
# This file is part of Koha.
|
|
#
|
|
# Koha is free software; you can redistribute it and/or modify it
|
|
# under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Koha is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
|
|
|
=head1 NAME
|
|
|
|
Koha::Filter::MARC::EmbedSeeFromHeadings - embeds see from headings into MARC for indexing
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
Filter to embed see from headings into MARC records.
|
|
|
|
=cut
|
|
|
|
use strict;
|
|
use warnings;
|
|
use Carp;
|
|
use Koha::MetadataRecord::Authority;
|
|
use C4::Biblio qw/GetMarcFromKohaField/;
|
|
|
|
use base qw(Koha::RecordProcessor::Base);
|
|
our $NAME = 'EmbedSeeFromHeadings';
|
|
|
|
=head2 filter
|
|
|
|
my $newrecord = $filter->filter($record);
|
|
my $newrecords = $filter->filter(\@records);
|
|
|
|
Embed see from headings into the specified record(s) and return the result.
|
|
In order to differentiate added headings from actual headings, a 'z' is
|
|
put in the first indicator.
|
|
|
|
=cut
|
|
sub filter {
|
|
my $self = shift;
|
|
my $record = shift;
|
|
my $newrecord;
|
|
|
|
return unless defined $record;
|
|
|
|
if (ref $record eq 'ARRAY') {
|
|
my @recarray;
|
|
foreach my $thisrec (@$record) {
|
|
push @recarray, _processrecord($thisrec);
|
|
}
|
|
$newrecord = \@recarray;
|
|
} elsif (ref $record eq 'MARC::Record') {
|
|
$newrecord = _processrecord($record);
|
|
}
|
|
|
|
return $newrecord;
|
|
}
|
|
|
|
sub _processrecord {
|
|
my $record = shift;
|
|
|
|
my ($item_tag) = GetMarcFromKohaField( "items.itemnumber" );
|
|
$item_tag ||= '';
|
|
|
|
foreach my $field ( $record->fields() ) {
|
|
next if $field->is_control_field();
|
|
next if $field->tag() eq $item_tag;
|
|
my $authid = $field->subfield('9');
|
|
|
|
next unless $authid;
|
|
|
|
my $authority = Koha::MetadataRecord::Authority->get_from_authid($authid);
|
|
next unless $authority;
|
|
my $auth_marc = $authority->record;
|
|
my @seefrom = $auth_marc->field('4..');
|
|
my @newfields;
|
|
foreach my $authfield (@seefrom) {
|
|
my $tag = substr($field->tag(), 0, 1) . substr($authfield->tag(), 1, 2);
|
|
next if MARC::Field->is_controlfield_tag($tag);
|
|
my $newfield = MARC::Field->new($tag,
|
|
'z',
|
|
$authfield->indicator(2) || ' ',
|
|
'9' => '1');
|
|
foreach my $sub ($authfield->subfields()) {
|
|
my ($code,$val) = @$sub;
|
|
$newfield->add_subfields( $code => $val );
|
|
}
|
|
$newfield->delete_subfield( code => '9' );
|
|
push @newfields, $newfield if (scalar($newfield->subfields()) > 0);
|
|
}
|
|
$record->append_fields(@newfields);
|
|
}
|
|
return $record;
|
|
}
|