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

(-)a/Koha/Biblio.pm (-26 / +85 lines)
Lines 1001-1039 sub get_marc_notes { Link Here
1001
    return \@marcnotes;
1001
    return \@marcnotes;
1002
}
1002
}
1003
1003
1004
=head3 get_marc_contributors
1004
sub _get_marc_authors {
1005
1006
    my $contributors = $biblio->get_marc_contributors;
1007
1008
Get all contributors (but first author) from the MARC record and returns them in an array.
1009
They are stored in different fields depending on MARC flavour
1010
1011
=cut
1012
1013
sub get_marc_contributors {
1014
    my ( $self, $params ) = @_;
1005
    my ( $self, $params ) = @_;
1015
1006
1016
    my ( $mintag, $maxtag, $fields_filter );
1007
    my $fields_filter = $params->{fields_filter};
1017
    my $marcflavour = C4::Context->preference('marcflavour');
1008
    my $mintag        = $params->{mintag};
1009
    my $maxtag        = $params->{maxtag};
1010
1011
    my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
1012
    my $marcflavour        = C4::Context->preference('marcflavour');
1018
1013
1019
    # tagslib useful only for UNIMARC author responsibilities
1014
    # tagslib useful only for UNIMARC author responsibilities
1020
    my $tagslib;
1015
    my $tagslib = $marcflavour eq "UNIMARC"
1021
    if ( $marcflavour eq "UNIMARC" ) {
1016
      ? C4::Biblio::GetMarcStructure( 1, $self->frameworkcode, { unsafe => 1 } )
1022
        $tagslib = C4::Biblio::GetMarcStructure( 1, $self->frameworkcode, { unsafe => 1 });
1017
      : undef;
1023
        $mintag = "700";
1024
        $maxtag = "712";
1025
        $fields_filter = '7..';
1026
    } else { # marc21/normarc
1027
        $mintag = "700";
1028
        $maxtag = "720";
1029
        $fields_filter = '7..';
1030
    }
1031
1018
1032
    my @marcauthors;
1019
    my @marcauthors;
1033
    my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
1034
1035
    foreach my $field ( $self->metadata->record->field($fields_filter) ) {
1020
    foreach my $field ( $self->metadata->record->field($fields_filter) ) {
1036
        next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
1021
1022
        next
1023
          if $mintag && $field->tag() < $mintag
1024
          || $maxtag && $field->tag() > $maxtag;
1025
1037
        my @subfields_loop;
1026
        my @subfields_loop;
1038
        my @link_loop;
1027
        my @link_loop;
1039
        my @subfields  = $field->subfields();
1028
        my @subfields  = $field->subfields();
Lines 1097-1102 sub get_marc_contributors { Link Here
1097
    return \@marcauthors;
1086
    return \@marcauthors;
1098
}
1087
}
1099
1088
1089
=head3 get_marc_contributors
1090
1091
    my $contributors = $biblio->get_marc_contributors;
1092
1093
Get all contributors (but first author) from the MARC record and returns them in an array.
1094
They are stored in different fields depending on MARC flavour (700..712 for MARC21)
1095
1096
=cut
1097
1098
sub get_marc_contributors {
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
        $mintag = "700";
1106
        $maxtag = "712";
1107
        $fields_filter = '7..';
1108
    } else { # marc21/normarc
1109
        $mintag = "700";
1110
        $maxtag = "720";
1111
        $fields_filter = '7..';
1112
    }
1113
1114
    return $self->_get_marc_authors(
1115
        {
1116
            fields_filter => $fields_filter,
1117
            mintag       => $mintag,
1118
            maxtag       => $maxtag
1119
        }
1120
    );
1121
}
1122
1123
=head3 get_marc_authors
1124
1125
    my $authors = $biblio->get_marc_authors;
1126
1127
Get all authors from the MARC record and returns them in an array.
1128
They are stored in different fields depending on MARC flavour
1129
(main author from 100 then secondary authors from 700..712).
1130
1131
=cut
1132
1133
sub get_marc_authors {
1134
    my ( $self, $params ) = @_;
1135
1136
    my ( $mintag, $maxtag, $fields_filter );
1137
    my $marcflavour = C4::Context->preference('marcflavour');
1138
1139
    if ( $marcflavour eq "UNIMARC" ) {
1140
        $fields_filter = '200';
1141
    } else { # marc21/normarc
1142
        $fields_filter = '100';
1143
    }
1144
1145
    my @first_authors = @{$self->_get_marc_authors(
1146
        {
1147
            fields_filter => $fields_filter,
1148
            mintag       => $mintag,
1149
            maxtag       => $maxtag
1150
        }
1151
    )};
1152
1153
    my @other_authors = @{$self->get_marc_contributors};
1154
1155
    return [@first_authors, @other_authors];
1156
}
1157
1158
1100
=head3 to_api
1159
=head3 to_api
1101
1160
1102
    my $json = $biblio->to_api;
1161
    my $json = $biblio->to_api;
(-)a/t/db_dependent/Koha/Biblio.t (-9 / +5 lines)
Lines 883-910 subtest 'current_checkouts() and old_checkouts() tests' => sub { Link Here
883
883
884
subtest 'get_marc_contributors() tests' => sub {
884
subtest 'get_marc_contributors() tests' => sub {
885
885
886
    plan tests => 1;
886
    plan tests => 2;
887
887
888
    $schema->storage->txn_begin;
888
    $schema->storage->txn_begin;
889
889
890
    my $biblio = $builder->build_sample_biblio;
890
    my $biblio = $builder->build_sample_biblio({ author => 'Main author' });
891
    my $record = $biblio->metadata->record;
891
    my $record = $biblio->metadata->record;
892
892
893
    # add author information
893
    # add author information
894
    my $field = MARC::Field->new('700','1','','a' => 'Jefferson, Thomas');
894
    my $field = MARC::Field->new('700','1','','a' => 'Jefferson, Thomas');
895
    $record->append_fields($field);
895
    $record->append_fields($field);
896
    $field = MARC::Field->new('700','1','','d' => '1743-1826');
896
    $field = MARC::Field->new('701','1','','d' => 'Secondary author 2');
897
    $record->append_fields($field);
898
    $field = MARC::Field->new('700','1','','e' => 'former owner.');
899
    $record->append_fields($field);
900
    $field = MARC::Field->new('700','1','','5' => 'MH');
901
    $record->append_fields($field);
897
    $record->append_fields($field);
902
898
903
    # get record
899
    # get record
904
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
900
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
905
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
901
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
906
902
907
    is( 4, @{$biblio->get_marc_contributors}, 'get_marc_contributors retrieves correct number of author subfields' );
903
    is( @{$biblio->get_marc_authors}, 3, 'get_marc_authors retrieves correct number of author subfields' );
904
    is( @{$biblio->get_marc_contributors}, 2, 'get_marc_contributors retrieves correct number of author subfields' );
908
    $schema->storage->txn_rollback;
905
    $schema->storage->txn_rollback;
909
};
906
};
910
907
911
- 

Return to bug 29897