View | Details | Raw Unified | Return to bug 29897
Collapse All | Expand All

(-)a/Koha/Biblio.pm (-26 / +85 lines)
Lines 967-1005 sub get_marc_notes { Link Here
967
    return \@marcnotes;
967
    return \@marcnotes;
968
}
968
}
969
969
970
=head3 get_marc_contributors
970
sub _get_marc_authors {
971
972
    my $contributors = $biblio->get_marc_contributors;
973
974
Get all contributors (but first author) from the MARC record and returns them in an array.
975
They are stored in different fields depending on MARC flavour
976
977
=cut
978
979
sub get_marc_contributors {
980
    my ( $self, $params ) = @_;
971
    my ( $self, $params ) = @_;
981
972
982
    my ( $mintag, $maxtag, $fields_filter );
973
    my $fields_filter = $params->{fields_filter};
983
    my $marcflavour = C4::Context->preference('marcflavour');
974
    my $mintag        = $params->{mintag};
975
    my $maxtag        = $params->{maxtag};
976
977
    my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
978
    my $marcflavour        = C4::Context->preference('marcflavour');
984
979
985
    # tagslib useful only for UNIMARC author responsibilities
980
    # tagslib useful only for UNIMARC author responsibilities
986
    my $tagslib;
981
    my $tagslib = $marcflavour eq "UNIMARC"
987
    if ( $marcflavour eq "UNIMARC" ) {
982
      ? C4::Biblio::GetMarcStructure( 1, $self->frameworkcode, { unsafe => 1 } )
988
        $tagslib = C4::Biblio::GetMarcStructure( 1, $self->frameworkcode, { unsafe => 1 });
983
      : undef;
989
        $mintag = "700";
990
        $maxtag = "712";
991
        $fields_filter = '7..';
992
    } else { # marc21/normarc
993
        $mintag = "700";
994
        $maxtag = "720";
995
        $fields_filter = '7..';
996
    }
997
984
998
    my @marcauthors;
985
    my @marcauthors;
999
    my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
1000
1001
    foreach my $field ( $self->metadata->record->field($fields_filter) ) {
986
    foreach my $field ( $self->metadata->record->field($fields_filter) ) {
1002
        next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
987
988
        next
989
          if $mintag && $field->tag() < $mintag
990
          || $maxtag && $field->tag() > $maxtag;
991
1003
        my @subfields_loop;
992
        my @subfields_loop;
1004
        my @link_loop;
993
        my @link_loop;
1005
        my @subfields  = $field->subfields();
994
        my @subfields  = $field->subfields();
Lines 1063-1068 sub get_marc_contributors { Link Here
1063
    return \@marcauthors;
1052
    return \@marcauthors;
1064
}
1053
}
1065
1054
1055
=head3 get_marc_contributors
1056
1057
    my $contributors = $biblio->get_marc_contributors;
1058
1059
Get all contributors (but first author) from the MARC record and returns them in an array.
1060
They are stored in different fields depending on MARC flavour (700..712 for MARC21)
1061
1062
=cut
1063
1064
sub get_marc_contributors {
1065
    my ( $self, $params ) = @_;
1066
1067
    my ( $mintag, $maxtag, $fields_filter );
1068
    my $marcflavour = C4::Context->preference('marcflavour');
1069
1070
    if ( $marcflavour eq "UNIMARC" ) {
1071
        $mintag = "700";
1072
        $maxtag = "712";
1073
        $fields_filter = '7..';
1074
    } else { # marc21/normarc
1075
        $mintag = "700";
1076
        $maxtag = "720";
1077
        $fields_filter = '7..';
1078
    }
1079
1080
    return $self->_get_marc_authors(
1081
        {
1082
            fields_filter => $fields_filter,
1083
            mintag       => $mintag,
1084
            maxtag       => $maxtag
1085
        }
1086
    );
1087
}
1088
1089
=head3 get_marc_authors
1090
1091
    my $authors = $biblio->get_marc_authors;
1092
1093
Get all authors from the MARC record and returns them in an array.
1094
They are stored in different fields depending on MARC flavour
1095
(main author from 100 then secondary authors from 700..712).
1096
1097
=cut
1098
1099
sub get_marc_authors {
1100
    my ( $self, $params ) = @_;
1101
1102
    my ( $mintag, $maxtag, $fields_filter );
1103
    my $marcflavour = C4::Context->preference('marcflavour');
1104
1105
    if ( $marcflavour eq "UNIMARC" ) {
1106
        $fields_filter = '200';
1107
    } else { # marc21/normarc
1108
        $fields_filter = '100';
1109
    }
1110
1111
    my @first_authors = @{$self->_get_marc_authors(
1112
        {
1113
            fields_filter => $fields_filter,
1114
            mintag       => $mintag,
1115
            maxtag       => $maxtag
1116
        }
1117
    )};
1118
1119
    my @other_authors = @{$self->get_marc_contributors};
1120
1121
    return [@first_authors, @other_authors];
1122
}
1123
1124
1066
=head3 to_api
1125
=head3 to_api
1067
1126
1068
    my $json = $biblio->to_api;
1127
    my $json = $biblio->to_api;
(-)a/t/db_dependent/Koha/Biblio.t (-9 / +5 lines)
Lines 858-885 subtest 'current_checkouts() and old_checkouts() tests' => sub { Link Here
858
858
859
subtest 'get_marc_contributors() tests' => sub {
859
subtest 'get_marc_contributors() tests' => sub {
860
860
861
    plan tests => 1;
861
    plan tests => 2;
862
862
863
    $schema->storage->txn_begin;
863
    $schema->storage->txn_begin;
864
864
865
    my $biblio = $builder->build_sample_biblio;
865
    my $biblio = $builder->build_sample_biblio({ author => 'Main author' });
866
    my $record = $biblio->metadata->record;
866
    my $record = $biblio->metadata->record;
867
867
868
    # add author information
868
    # add author information
869
    my $field = MARC::Field->new('700','1','','a' => 'Jefferson, Thomas');
869
    my $field = MARC::Field->new('700','1','','a' => 'Jefferson, Thomas');
870
    $record->append_fields($field);
870
    $record->append_fields($field);
871
    $field = MARC::Field->new('700','1','','d' => '1743-1826');
871
    $field = MARC::Field->new('701','1','','d' => 'Secondary author 2');
872
    $record->append_fields($field);
873
    $field = MARC::Field->new('700','1','','e' => 'former owner.');
874
    $record->append_fields($field);
875
    $field = MARC::Field->new('700','1','','5' => 'MH');
876
    $record->append_fields($field);
872
    $record->append_fields($field);
877
873
878
    # get record
874
    # get record
879
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
875
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
880
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
876
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
881
877
882
    is( 4, @{$biblio->get_marc_contributors}, 'get_marc_contributors retrieves correct number of author subfields' );
878
    is( @{$biblio->get_marc_authors}, 3, 'get_marc_authors retrieves correct number of author subfields' );
879
    is( @{$biblio->get_marc_contributors}, 2, 'get_marc_contributors retrieves correct number of author subfields' );
883
    $schema->storage->txn_rollback;
880
    $schema->storage->txn_rollback;
884
};
881
};
885
882
886
- 

Return to bug 29897