|
Line 0
Link Here
|
|
|
1 |
package Koha::Filter::MARC::EmbedAnalyticalItems; |
| 2 |
|
| 3 |
# Copyright 2022 Biblibre |
| 4 |
# |
| 5 |
# This file is part of Koha. |
| 6 |
# |
| 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. |
| 11 |
# |
| 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. |
| 16 |
# |
| 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>. |
| 19 |
|
| 20 |
=head1 NAME |
| 21 |
|
| 22 |
Koha::Filter::MARC::EmbedAnalyticalItems - Appends analytical items information on MARC::Record objects. |
| 23 |
|
| 24 |
=head1 DESCRIPTION |
| 25 |
|
| 26 |
Filter to embed analytical items information into MARC::Record objects. |
| 27 |
|
| 28 |
Does nothing if system preference EasyAnalyticalRecords is disabled. |
| 29 |
|
| 30 |
=cut |
| 31 |
|
| 32 |
use Modern::Perl; |
| 33 |
|
| 34 |
use Koha::Item; |
| 35 |
|
| 36 |
use base qw(Koha::RecordProcessor::Base); |
| 37 |
our $NAME = 'EmbedAnalyticalItems'; |
| 38 |
|
| 39 |
=head2 filter |
| 40 |
|
| 41 |
Embed analytical items into the MARC::Record object. |
| 42 |
|
| 43 |
=cut |
| 44 |
|
| 45 |
sub filter { |
| 46 |
my $self = shift; |
| 47 |
my $record = shift; |
| 48 |
|
| 49 |
return unless defined $record and ref($record) eq 'MARC::Record'; |
| 50 |
|
| 51 |
return $record unless C4::Context->preference('EasyAnalyticalRecords'); |
| 52 |
|
| 53 |
my @item_fields; |
| 54 |
my $marcflavour = C4::Context->preference('marcflavour'); |
| 55 |
my $analyticfield = '773'; |
| 56 |
if ( $marcflavour eq 'MARC21' ) { |
| 57 |
$analyticfield = '773'; |
| 58 |
} |
| 59 |
elsif ( $marcflavour eq 'UNIMARC' ) { |
| 60 |
$analyticfield = '461'; |
| 61 |
} |
| 62 |
foreach my $field ( $record->field($analyticfield) ) { |
| 63 |
my $item = Koha::Item->find($field->subfield('9')); |
| 64 |
next unless defined $item; |
| 65 |
my $item_field = $item->as_marc_field; |
| 66 |
# TODO barcode |
| 67 |
push @item_fields, $item_field; |
| 68 |
} |
| 69 |
$record->append_fields(@item_fields); |
| 70 |
|
| 71 |
return $record; |
| 72 |
} |
| 73 |
|
| 74 |
1; |