Bugzilla – Attachment 135364 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.42 KB, created by
Martin Renvoize (ashimema)
on 2022-05-26 10:06:30 UTC
(
hide
)
Description:
Bug 30848: Add an AuthorizedValues RecordProcessor filter
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-05-26 10:06:30 UTC
Size:
5.42 KB
patch
obsolete
>From e82759e147623343795defa5b438f150369809cd 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 => ('ExpandAuthorizedValues'), > options => { > interface => 'opac', > frameworkcode => $biblio->frameworkcode > } > } > ); > > $processor->process( $record ); >--- > Koha/Filter/MARC/ExpandAuthorizedValues.pm | 133 +++++++++++++++++++++ > 1 file changed, 133 insertions(+) > create mode 100644 Koha/Filter/MARC/ExpandAuthorizedValues.pm > >diff --git a/Koha/Filter/MARC/ExpandAuthorizedValues.pm b/Koha/Filter/MARC/ExpandAuthorizedValues.pm >new file mode 100644 >index 0000000000..3306839728 >--- /dev/null >+++ b/Koha/Filter/MARC/ExpandAuthorizedValues.pm >@@ -0,0 +1,133 @@ >+package Koha::Filter::MARC::ExpandAuthorizedValues; >+ >+# 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::ExpandAuthorizedValues - 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 => ['ExpandAuthorizedValues'], >+ 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 = 'ExpandAuthorizedValues'; >+ >+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