@@ -, +, @@ Koha::Objects::Record::Collections->print_collection work with Authorities and Biblios --- Koha/Authority.pm | 19 ++++++++++++++++--- Koha/Biblio.pm | 14 ++++++++++++++ Koha/Objects/Record/Collections.pm | 9 ++++++--- t/db_dependent/Biblio.t | 16 +++++++++++++++- t/db_dependent/Koha/Authorities.t | 16 +++++++++++++++- 5 files changed, 66 insertions(+), 8 deletions(-) --- a/Koha/Authority.pm +++ a/Koha/Authority.pm @@ -148,11 +148,24 @@ Return the MARC::Record for this authority sub record { my ( $self ) = @_; - my $flavour = - C4::Context->preference('marcflavour') eq 'UNIMARC' + my $flavour = $self->record_schema; + return MARC::Record->new_from_xml( $self->marcxml, 'UTF-8', $flavour ); +} + +=head3 record_schema + +my $schema = $biblio->record_schema(); + +Returns the record schema (MARC21 or UNIMARCAUTH). + +=cut + +sub record_schema { + my ( $self ) = @_; + + return C4::Context->preference('marcflavour') eq 'UNIMARC' ? 'UNIMARCAUTH' : 'MARC21'; - return MARC::Record->new_from_xml( $self->marcxml, 'UTF-8', $flavour ); } =head2 Class Methods --- a/Koha/Biblio.pm +++ a/Koha/Biblio.pm @@ -105,6 +105,20 @@ sub record { return $self->metadata->record; } +=head3 record_schema + +my $schema = $biblio->record_schema(); + +Returns the record schema (MARC21, USMARC or UNIMARC). + +=cut + +sub record_schema { + my ( $self ) = @_; + + return $self->metadata->schema // C4::Context->preference("marcflavour"); +} + =head3 orders my $orders = $biblio->orders(); --- a/Koha/Objects/Record/Collections.pm +++ a/Koha/Objects/Record/Collections.pm @@ -84,10 +84,13 @@ sub print_collection { $end = MARC::File::XML::footer(); } while ( my $element = $self->next ) { - my $metadata = $element->metadata; - MARC::File::XML->default_record_format( $metadata->schema // C4::Context->preference("marcflavour") ) + my $schema = C4::Context->preference("marcflavour"); + if ($element->can('record_schema')) { + $schema = $element->record_schema; + } + MARC::File::XML->default_record_format( $schema ) if $format eq 'marcxml'; - push @parts, $serializers{$format}->( $metadata->record ); + push @parts, $serializers{$format}->( $element->record ); } return ( defined $start ? $start : '' ) --- a/t/db_dependent/Biblio.t +++ a/t/db_dependent/Biblio.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 16; +use Test::More tests => 17; use Test::MockModule; use Test::Warn; use List::MoreUtils qw( uniq ); @@ -877,6 +877,20 @@ subtest 'record test' => sub { $biblio->metadata->record->as_formatted ); }; +subtest 'record_schema test' => sub { + plan tests => 1; + + my $marc_record = MARC::Record->new; + $marc_record->append_fields( create_isbn_field( '0590353403', 'MARC21' ) ); + + my ($biblionumber) = C4::Biblio::AddBiblio( $marc_record, '' ); + + my $biblio = Koha::Biblios->find($biblionumber); + + is( $biblio->record_schema, + $biblio->metadata->schema ); +}; + # Cleanup --- a/t/db_dependent/Koha/Authorities.t +++ a/t/db_dependent/Koha/Authorities.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 9; +use Test::More tests => 10; use MARC::Field; use MARC::File::XML; use MARC::Record; @@ -321,4 +321,18 @@ subtest 'record tests' => sub { }; +subtest 'record_schema tests' => sub { + plan tests => 2; + + my $authority = $builder->build_object({class => 'Koha::Authorities'}); + + t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); + + is($authority->record_schema, 'MARC21'); + + t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' ); + + is($authority->record_schema, 'UNIMARCAUTH'); +}; + $schema->storage->txn_rollback; --