Bugzilla – Attachment 94095 Details for
Bug 23793
Add an EmbedItems RecordProcessor filter for MARC::Record objects
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23793: Add an EmbedItems RecordProcessor filter for MARC::Record objects
Bug-23793-Add-an-EmbedItems-RecordProcessor-filter.patch (text/plain), 3.55 KB, created by
Tomás Cohen Arazi
on 2019-10-14 12:12:18 UTC
(
hide
)
Description:
Bug 23793: Add an EmbedItems RecordProcessor filter for MARC::Record objects
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi
Created:
2019-10-14 12:12:18 UTC
Size:
3.55 KB
patch
obsolete
>From 1315d712d0048a4911d8296b97fd97ed54acf788 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 10 Oct 2019 13:17:18 -0300 >Subject: [PATCH] Bug 23793: Add an EmbedItems RecordProcessor filter for > MARC::Record objects > >This patch introduces a RecordProcessor filter for MARC::Record objects >that embeds MARC::Field's for each item that is passed to the processor. > >Target usage: > >my $biblio = Koha::Biblios->find( > $biblio_id, > { prefetch => [ items, metadata ] } >); > >my $opachiddenitems_rules; >eval { > my $yaml = C4::Context->preference('OpacHiddenItems') . "\n\n"; > $opachiddenitems_rules = YAML::Load($yaml); >}; > >my @items = grep { !$_->hidden_in_opac({ rules => $opachiddenitems_rules }) @{$biblio->items->as_list}; >my $record = $biblio->metadata->record; > >my $processor = Koha::RecordProcessor->new( > { > filters => ('EmbedItems'), > options => { > items => \@items > } > } >); > >$processor->process( $record ); >--- > Koha/Filter/MARC/EmbedItems.pm | 91 ++++++++++++++++++++++++++++++++++ > 1 file changed, 91 insertions(+) > create mode 100644 Koha/Filter/MARC/EmbedItems.pm > >diff --git a/Koha/Filter/MARC/EmbedItems.pm b/Koha/Filter/MARC/EmbedItems.pm >new file mode 100644 >index 0000000000..626c919846 >--- /dev/null >+++ b/Koha/Filter/MARC/EmbedItems.pm >@@ -0,0 +1,91 @@ >+package Koha::Filter::MARC::EmbedItems; >+ >+# Copyright 2019 Theke Solutions >+ >+# 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::EmbedItems - Appends item information on MARC::Record objects. >+ >+=head1 SYNOPSIS >+ >+my $biblio = Koha::Biblios->find( >+ $biblio_id, >+ { prefetch => [ items, metadata ] } >+); >+ >+my $opachiddenitems_rules; >+eval { >+ my $yaml = C4::Context->preference('OpacHiddenItems') . "\n\n"; >+ $opachiddenitems_rules = YAML::Load($yaml); >+}; >+ >+my @items = grep { !$_->hidden_in_opac({ rules => $opachiddenitems_rules }) @{$biblio->items}; >+my $record = $biblio->metadata->record; >+ >+my $processor = Koha::RecordProcessor->new( >+ { >+ filters => ('EmbedItems'), >+ options => { >+ items => \@items >+ } >+ } >+); >+ >+$processor->process( $record ); >+ >+=head1 DESCRIPTION >+ >+Filter to embed items information into MARC::Record objects. >+ >+=cut >+ >+use Modern::Perl; >+ >+use C4::Biblio; >+ >+use base qw(Koha::RecordProcessor::Base); >+our $NAME = 'EmbedItems'; >+ >+=head2 filter >+ >+Embed items into the MARC::Record object. >+ >+=cut >+ >+sub filter { >+ my $self = shift; >+ my $record = shift; >+ >+ return unless defined $record and ref($record) eq 'MARC::Record'; >+ >+ my $items = $self->{params}->{options}->{items}; >+ my $mss = $self->{params}->{options}->{mss} >+ // C4::Biblio::GetMarcSubfieldStructure( '', { unsafe => 1 } ); >+ >+ my @item_fields; >+ >+ foreach my $item ( @{$items} ) { >+ push @item_fields, $item->as_marc_field( { mss => $mss } ); >+ } >+ >+ $record->append_fields(@item_fields); >+ >+ return $record; >+} >+ >+1; >-- >2.23.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23793
:
93971
|
93980
|
94030
|
94095
|
94096
|
94599
|
94600
|
94602
|
94603