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

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

Return to bug 29897