-=head2 transformMARCXML4XSLT
-
-Replaces codes with authorized values in a MARC::Record object
-Is only used in this module currently.
-
-=cut
-
-sub transformMARCXML4XSLT {
- my ($biblionumber, $record) = @_;
- my $frameworkcode = GetFrameworkCode($biblionumber) || '';
- my $tagslib = &GetMarcStructure(1, $frameworkcode, { unsafe => 1 });
- my @fields;
- # FIXME: wish there was a better way to handle exceptions
- eval {
- @fields = $record->fields();
- };
- if ($@) { warn "PROBLEM WITH RECORD"; next; }
- 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/NORMARC field 942$n (suppression in opac)
- if ( !( $tag eq '942' && $subfield eq 'n' ) || $marcflavour eq 'UNIMARC' ) {
- $value = GetAuthorisedValueDesc( $tag, $letter, $value, '', $tagslib )
- 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;
-}
-
-=head2 getAuthorisedValues4MARCSubfields
-
-Returns a ref of hash of ref of hash for tag -> letter controlled by authorised values
-Is only used in this module currently.
-
-=cut
-
-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 };
-}
-