Bugzilla – Attachment 135353 Details for
Bug 30848
Introduce Koha::Filter::ExpandCodedFields
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30848: Add an AuthorizedValues RecordProcessor filter
Bug-30848-Add-an-AuthorizedValues-RecordProcessor-.patch (text/plain), 5.36 KB, created by
Martin Renvoize (ashimema)
on 2022-05-25 16:19:14 UTC
(
hide
)
Description:
Bug 30848: Add an AuthorizedValues RecordProcessor filter
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-05-25 16:19:14 UTC
Size:
5.36 KB
patch
obsolete
>From 7c3a2ef143233162a736eb97d6d7b4b5ffad0760 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 25 May 2022 15:19:57 +0100 >Subject: [PATCH] Bug 30848: Add an AuthorizedValues RecordProcessor filter > >This patch introduces a RecordProcessor filter for MARC::Record objects >that replaces AV codes with AC descriptions in the MARC::Record passed to the processor. > >Target usage: > > my $biblio = Koha::Biblios->find( > $biblio_id, > { prefetch => [ metadata ] } > ); > > my $record = $biblio->metadata->record; > > my $processor = Koha::RecordProcessor->new( > { > filters => ('AuthorizedValues'), > options => { > interface => 'opac', > frameworkcode => $biblio->frameworkcode > } > } > ); > > $processor->process( $record ); >--- > Koha/Filter/MARC/AuthorizedValues.pm | 133 +++++++++++++++++++++++++++ > 1 file changed, 133 insertions(+) > create mode 100644 Koha/Filter/MARC/AuthorizedValues.pm > >diff --git a/Koha/Filter/MARC/AuthorizedValues.pm b/Koha/Filter/MARC/AuthorizedValues.pm >new file mode 100644 >index 0000000000..34a404db01 >--- /dev/null >+++ b/Koha/Filter/MARC/AuthorizedValues.pm >@@ -0,0 +1,133 @@ >+package Koha::Filter::MARC::AuthorizedValues; >+ >+# Copyright 2022 PTFS Europe >+# >+# 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::AuthorizedValues - Replaces AV codes with descriptions in MARC::Record objects. >+ >+=head1 SYNOPSIS >+ >+ my $biblio = Koha::Biblios->find( >+ $biblio_id, >+ { prefetch => [ metadata ] } >+ ); >+ >+ my $record = $biblio->metadata->record; >+ >+ my $record_processor = Koha::RecordProcessor->new( >+ { >+ filters => ['AuthorizedValues'], >+ options => { >+ interface => 'opac', >+ } >+ } >+ ); >+ >+ $record_processor->process($record); >+ >+=head1 DESCRIPTION >+ >+Filter to replace Koha AV codes in MARC::Records with their Koha AV descriptions. >+ >+=cut >+ >+use Modern::Perl; >+ >+use C4::Biblio qw( GetAuthorisedValueDesc GetMarcStructure ); >+ >+use base qw(Koha::RecordProcessor::Base); >+our $NAME = 'AuthorizedValues'; >+ >+my %authval_per_framework; # Cache for tagfield-tagsubfield to decode per framework. >+ >+=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 $params = $self->params; >+ my $interface = $params->{options}->{interface} // 'opac'; >+ my $opac = $interface eq 'opac' ? 1 : 0; >+ my $frameworkcode = $params->{options}->{frameworkcode} // q{}; >+ my $marcstructure = $params->{options}->{marcstructure} >+ // GetMarcStructure( 1, $frameworkcode, { unsafe => 1 } ); >+ >+ my $marcflavour = C4::Context->preference('marcflavour'); >+ my $av = _getAuthorisedValues4MARCSubfields($frameworkcode); >+ foreach my $tag ( keys %$av ) { >+ foreach my $field ( $record->field($tag) ) { >+ if ( $av->{$tag} ) { >+ my @new_subfields = (); >+ for my $subfield ( $field->subfields() ) { >+ my ( $letter, $value ) = @$subfield; >+ >+ # Replace the field value with the authorised value >+ # *except* for MARC21 field 942$n (suppression in opac) >+ if ( !( $tag eq '942' && $subfield->[0] eq 'n' ) >+ || $marcflavour eq 'UNIMARC' ) >+ { >+ $value = >+ GetAuthorisedValueDesc( $tag, $letter, $value, '', >+ $marcstructure, undef, $opac ) >+ if $av->{$tag}->{$letter}; >+ } >+ push( @new_subfields, $letter, $value ); >+ } >+ $field->replace_with( >+ MARC::Field->new( >+ $tag, $field->indicator(1), >+ $field->indicator(2), @new_subfields >+ ) >+ ); >+ } >+ } >+ } >+ >+ return $record; >+} >+ >+sub _getAuthorisedValues4MARCSubfields { >+ my ($frameworkcode) = @_; >+ unless ( $authval_per_framework{$frameworkcode} ) { >+ my $dbh = C4::Context->dbh; >+ my $sth = $dbh->prepare( >+ "SELECT DISTINCT tagfield, tagsubfield >+ FROM marc_subfield_structure >+ WHERE authorised_value IS NOT NULL >+ AND authorised_value!='' >+ AND frameworkcode=?" >+ ); >+ $sth->execute($frameworkcode); >+ my $av = {}; >+ while ( my ( $tag, $letter ) = $sth->fetchrow() ) { >+ $av->{$tag}->{$letter} = 1; >+ } >+ $authval_per_framework{$frameworkcode} = $av; >+ } >+ return $authval_per_framework{$frameworkcode}; >+} >+ >+1; >-- >2.20.1
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 30848
:
135338
|
135353
|
135363
|
135364
|
135386
|
135387
|
135388
|
135418
|
135421
|
135422
|
135423
|
135424
|
135425
|
135707
|
135708
|
135709
|
135710
|
135711
|
135712
|
135713
|
135714
|
135715
|
135716
|
135717
|
135770
|
136025
|
136026
|
136027
|
136259
|
136260
|
136261
|
136262
|
136774
|
136775
|
136776
|
136777