From 56312840151f8080e54d607ef221bf99baa9b227 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 26 Apr 2012 09:42:27 -0400 Subject: [PATCH] Bug 7933 - Fields in marc display not the same The fields displayed in the 'labeled' and 'plain' views for opac-MARCdetail.pl differ. The labeled view hides subfields marked as hidden, while the 'plain' view does not. This is because the plain view simply grabs the marcxml and transforms it via xslt. The labeled view is processed in a completely different way, which respects the hidden field flag for the set framework. This commit resolves this issue by adding a subroutine to remove hidden fields from a given record, and another subroutine to convert marc records to marx xml. Where before, the raw marc xml was transformed, now the script gets a record with the hidden subfields removed, transforms that to marc xml, and then transforms it again via xslt ( as before ). --- C4/Biblio.pm | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ opac/opac-showmarc.pl | 4 ++- 2 files changed, 63 insertions(+), 1 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 56cd94e..6fd7951 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -90,12 +90,15 @@ BEGIN { &GetMarcFromKohaField &GetFrameworkCode &TransformKohaToMarc + &TransformMarcToXml &PrepHostMarcField &CountItemsIssued &CountBiblioInOrders &GetSubscriptionsId &GetHolds + + &GetMarcBiblioWithoutHiddenFields ); # To modify something @@ -2011,6 +2014,20 @@ sub TransformKohaToMarc { return $record; } +=head TransformMarcToXml + + $marcxml = TransformMarcToKoha( $record ); + + Accepts a Marc::Record and returns record converted to marc xml. + +=cut + +sub TransformMarcToXml { + my ( $record ) = @_; + + return MARC::File::XML::header() . MARC::File::XML::record( $record ) . MARC::File::XML::footer(); +} + =head2 PrepHostMarcField $hostfield = PrepHostMarcField ( $hostbiblionumber,$hostitemnumber,$marcflavour ) @@ -3654,6 +3671,49 @@ sub GetHolds { return ($holds); } +=head2 GetMarcBiblioWithoutHiddenFields + + $record = GetMarcBiblioWithoutHiddenFields( $biblionumber ); + + Returns a marc record where all fields marked as hidden + have been removed. + +=cut + +sub GetMarcBiblioWithoutHiddenFields { + my ( $biblionumber ) = @_; + + return unless $biblionumber; + + my $itemtype = GetFrameworkCode( $biblionumber ); + my $tagslib = GetMarcStructure( 0, $itemtype ); + my $record = GetMarcBiblio($biblionumber); + + foreach my $field_name ( keys %$tagslib ) { + my $field = $tagslib->{$field_name}; + + foreach my $subfield_name ( keys %$field ) { + next if ( $subfield_name eq 'lib' + || $subfield_name eq 'repeatable' + || $subfield_name eq 'mandatory' + || $subfield_name eq 'tab' ); + + my $subfield = $tagslib->{ $field_name }->{ $subfield_name }; + + if ( $tagslib->{ $field_name }->{ $subfield_name }->{'hidden'} ) { + my @fields = $record->field( $field_name ); + foreach my $field ( @fields ) { + $field->delete_subfield( code => $subfield_name ); + + $record->delete_field( $field ) unless ( $field->subfields() ); + } + } + } + } + + return $record; +} + =head2 prepare_host_field $marcfield = prepare_host_field( $hostbiblioitem, $marcflavour ); diff --git a/opac/opac-showmarc.pl b/opac/opac-showmarc.pl index 3638f88..12c896b 100755 --- a/opac/opac-showmarc.pl +++ b/opac/opac-showmarc.pl @@ -66,7 +66,9 @@ if ($importid) { } if ($view eq 'card' || $view eq 'html') { - $xmlrecord = GetXmlBiblio($biblionumber) unless $xmlrecord; + $record = GetMarcBiblioWithoutHiddenFields($biblionumber) unless $record; + $xmlrecord = TransformMarcToXml( $record ); + my $xslfile; my $themelang = '/' . C4::Context->preference("opacthemes") . '/' . C4::Templates::_current_language(); -- 1.7.2.5