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

(-)a/C4/Biblio.pm (-100 lines)
Lines 35-41 BEGIN { Link Here
35
        GetMarcISBN
35
        GetMarcISBN
36
        GetMarcISSN
36
        GetMarcISSN
37
        GetMarcSubjects
37
        GetMarcSubjects
38
        GetMarcAuthors
39
        GetMarcSeries
38
        GetMarcSeries
40
        GetMarcUrls
39
        GetMarcUrls
41
        GetUsedMarcStructure
40
        GetUsedMarcStructure
Lines 1658-1762 sub GetMarcSubjects { Link Here
1658
    return \@marcsubjects;
1657
    return \@marcsubjects;
1659
}    #end getMARCsubjects
1658
}    #end getMARCsubjects
1660
1659
1661
=head2 GetMarcAuthors
1662
1663
  authors = GetMarcAuthors($record,$marcflavour);
1664
1665
Get all authors from the MARC record and returns them in an array.
1666
The authors are stored in different fields depending on MARC flavour
1667
1668
=cut
1669
1670
sub GetMarcAuthors {
1671
    my ( $record, $marcflavour ) = @_;
1672
    if (!$record) {
1673
        carp 'GetMarcAuthors called on undefined record';
1674
        return;
1675
    }
1676
    my ( $mintag, $maxtag, $fields_filter );
1677
1678
    # tagslib useful only for UNIMARC author responsibilities
1679
    my $tagslib;
1680
    if ( $marcflavour eq "UNIMARC" ) {
1681
        # FIXME : we don't have the framework available, we take the default framework. May be buggy on some setups, will be usually correct.
1682
        $tagslib = GetMarcStructure( 1, '', { unsafe => 1 });
1683
        $mintag = "700";
1684
        $maxtag = "712";
1685
        $fields_filter = '7..';
1686
    } else { # marc21
1687
        $mintag = "700";
1688
        $maxtag = "720";
1689
        $fields_filter = '7..';
1690
    }
1691
1692
    my @marcauthors;
1693
    my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
1694
1695
    foreach my $field ( $record->field($fields_filter) ) {
1696
        next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
1697
        my @subfields_loop;
1698
        my @link_loop;
1699
        my @subfields  = $field->subfields();
1700
        my $count_auth = 0;
1701
1702
        # if there is an authority link, build the link with Koha-Auth-Number: subfield9
1703
        my $subfield9 = $field->subfield('9');
1704
        if ($subfield9) {
1705
            my $linkvalue = $subfield9;
1706
            $linkvalue =~ s/(\(|\))//g;
1707
            @link_loop = ( { 'limit' => 'an', 'link' => $linkvalue } );
1708
        }
1709
1710
        # other subfields
1711
        my $unimarc3;
1712
        for my $authors_subfield (@subfields) {
1713
            next if ( $authors_subfield->[0] eq '9' );
1714
1715
            # unimarc3 contains the $3 of the author for UNIMARC.
1716
            # For french academic libraries, it's the "ppn", and it's required for idref webservice
1717
            $unimarc3 = $authors_subfield->[1] if $marcflavour eq 'UNIMARC' and $authors_subfield->[0] =~ /3/;
1718
1719
            # don't load unimarc subfields 3, 5
1720
            next if ( $marcflavour eq 'UNIMARC' and ( $authors_subfield->[0] =~ /3|5/ ) );
1721
1722
            my $code = $authors_subfield->[0];
1723
            my $value        = $authors_subfield->[1];
1724
            my $linkvalue    = $value;
1725
            $linkvalue =~ s/(\(|\))//g;
1726
            # UNIMARC author responsibility
1727
            if ( $marcflavour eq 'UNIMARC' and $code eq '4' ) {
1728
                $value = GetAuthorisedValueDesc( $field->tag(), $code, $value, '', $tagslib );
1729
                $linkvalue = "($value)";
1730
            }
1731
            # if no authority link, build a search query
1732
            unless ($subfield9) {
1733
                push @link_loop, {
1734
                    limit    => 'au',
1735
                    'link'   => $linkvalue,
1736
                    operator => (scalar @link_loop) ? ' and ' : undef
1737
                };
1738
            }
1739
            my @this_link_loop = @link_loop;
1740
            # do not display $0
1741
            unless ( $code eq '0') {
1742
                push @subfields_loop, {
1743
                    tag       => $field->tag(),
1744
                    code      => $code,
1745
                    value     => $value,
1746
                    link_loop => \@this_link_loop,
1747
                    separator => (scalar @subfields_loop) ? $AuthoritySeparator : ''
1748
                };
1749
            }
1750
        }
1751
        push @marcauthors, {
1752
            MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop,
1753
            authoritylink => $subfield9,
1754
            unimarc3 => $unimarc3
1755
        };
1756
    }
1757
    return \@marcauthors;
1758
}
1759
1760
=head2 GetMarcUrls
1660
=head2 GetMarcUrls
1761
1661
1762
  $marcurls = GetMarcUrls($record,$marcflavour);
1662
  $marcurls = GetMarcUrls($record,$marcflavour);
(-)a/Koha/Biblio.pm (+97 lines)
Lines 966-971 sub get_marc_notes { Link Here
966
    return \@marcnotes;
966
    return \@marcnotes;
967
}
967
}
968
968
969
=head3 get_authors_from_MARC
970
971
    my $authors = $biblio->get_authors_from_MARC;
972
973
Get all authors from the MARC record and returns them in an array.
974
The authors are stored in different fields depending on MARC flavour
975
976
=cut
977
978
sub get_authors_from_MARC {
979
    my ( $self, $params ) = @_;
980
981
    my ( $mintag, $maxtag, $fields_filter );
982
    my $marcflavour = C4::Context->preference('marcflavour');
983
984
    # tagslib useful only for UNIMARC author responsibilities
985
    my $tagslib;
986
    if ( $marcflavour eq "UNIMARC" ) {
987
        # FIXME : we don't have the framework available, we take the default framework. May be buggy on some setups, will be usually correct.
988
        $tagslib = C4::Biblio::GetMarcStructure( 1, '', { unsafe => 1 });
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
998
    my @marcauthors;
999
    my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
1000
1001
    foreach my $field ( $self->metadata->record->field($fields_filter) ) {
1002
        next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
1003
        my @subfields_loop;
1004
        my @link_loop;
1005
        my @subfields  = $field->subfields();
1006
        my $count_auth = 0;
1007
1008
        # if there is an authority link, build the link with Koha-Auth-Number: subfield9
1009
        my $subfield9 = $field->subfield('9');
1010
        if ($subfield9) {
1011
            my $linkvalue = $subfield9;
1012
            $linkvalue =~ s/(\(|\))//g;
1013
            @link_loop = ( { 'limit' => 'an', 'link' => $linkvalue } );
1014
        }
1015
1016
        # other subfields
1017
        my $unimarc3;
1018
        for my $authors_subfield (@subfields) {
1019
            next if ( $authors_subfield->[0] eq '9' );
1020
1021
            # unimarc3 contains the $3 of the author for UNIMARC.
1022
            # For french academic libraries, it's the "ppn", and it's required for idref webservice
1023
            $unimarc3 = $authors_subfield->[1] if $marcflavour eq 'UNIMARC' and $authors_subfield->[0] =~ /3/;
1024
1025
            # don't load unimarc subfields 3, 5
1026
            next if ( $marcflavour eq 'UNIMARC' and ( $authors_subfield->[0] =~ /3|5/ ) );
1027
1028
            my $code = $authors_subfield->[0];
1029
            my $value        = $authors_subfield->[1];
1030
            my $linkvalue    = $value;
1031
            $linkvalue =~ s/(\(|\))//g;
1032
            # UNIMARC author responsibility
1033
            if ( $marcflavour eq 'UNIMARC' and $code eq '4' ) {
1034
                $value = C4::Biblio::GetAuthorisedValueDesc( $field->tag(), $code, $value, '', $tagslib );
1035
                $linkvalue = "($value)";
1036
            }
1037
            # if no authority link, build a search query
1038
            unless ($subfield9) {
1039
                push @link_loop, {
1040
                    limit    => 'au',
1041
                    'link'   => $linkvalue,
1042
                    operator => (scalar @link_loop) ? ' and ' : undef
1043
                };
1044
            }
1045
            my @this_link_loop = @link_loop;
1046
            # do not display $0
1047
            unless ( $code eq '0') {
1048
                push @subfields_loop, {
1049
                    tag       => $field->tag(),
1050
                    code      => $code,
1051
                    value     => $value,
1052
                    link_loop => \@this_link_loop,
1053
                    separator => (scalar @subfields_loop) ? $AuthoritySeparator : ''
1054
                };
1055
            }
1056
        }
1057
        push @marcauthors, {
1058
            MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop,
1059
            authoritylink => $subfield9,
1060
            unimarc3 => $unimarc3
1061
        };
1062
    }
1063
    return \@marcauthors;
1064
}
1065
969
=head3 to_api
1066
=head3 to_api
970
1067
971
    my $json = $biblio->to_api;
1068
    my $json = $biblio->to_api;
(-)a/basket/basket.pl (-1 / +1 lines)
Lines 72-78 foreach my $biblionumber ( @bibs ) { Link Here
72
    my $biblio           = Koha::Biblios->find( $biblionumber );
72
    my $biblio           = Koha::Biblios->find( $biblionumber );
73
    my $record           = &GetMarcBiblio({ biblionumber => $biblionumber });
73
    my $record           = &GetMarcBiblio({ biblionumber => $biblionumber });
74
    my $marcnotesarray   = $biblio->get_marc_notes({ marcflavour => $marcflavour });
74
    my $marcnotesarray   = $biblio->get_marc_notes({ marcflavour => $marcflavour });
75
    my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
75
    my $marcauthorsarray = $biblio->get_authors_from_MARC;
76
    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
76
    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
77
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
77
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
78
    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
78
    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
(-)a/basket/sendbasket.pl (-1 / +2 lines)
Lines 74-83 if ( $email_add ) { Link Here
74
74
75
        my $dat              = GetBiblioData($biblionumber);
75
        my $dat              = GetBiblioData($biblionumber);
76
        next unless $dat;
76
        next unless $dat;
77
        my $biblio           = Koha::Biblios->find( $biblionumber );
77
        my $record           = GetMarcBiblio({
78
        my $record           = GetMarcBiblio({
78
            biblionumber => $biblionumber,
79
            biblionumber => $biblionumber,
79
            embed_items => 1 });
80
            embed_items => 1 });
80
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
81
        my $marcauthorsarray = $biblio->get_authors_from_MARC;
81
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
82
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
82
83
83
        my @items = GetItemsInfo( $biblionumber );
84
        my @items = GetItemsInfo( $biblionumber );
(-)a/opac/opac-basket.pl (-1 / +1 lines)
Lines 94-100 foreach my $biblionumber ( @bibs ) { Link Here
94
    $record_processor->process($record);
94
    $record_processor->process($record);
95
    next unless $record;
95
    next unless $record;
96
    my $marcnotesarray   = $biblio->get_marc_notes({ marcflavour => $marcflavour, opac => 1 });
96
    my $marcnotesarray   = $biblio->get_marc_notes({ marcflavour => $marcflavour, opac => 1 });
97
    my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
97
    my $marcauthorsarray = $biblio->get_authors_from_MARC;
98
    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
98
    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
99
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
99
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
100
    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
100
    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
(-)a/opac/opac-detail.pl (+2 lines)
Lines 784-789 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) { Link Here
784
}
784
}
785
785
786
my $marcnotesarray = $biblio->get_marc_notes({ marcflavour => $marcflavour, opac => 1 });
786
my $marcnotesarray = $biblio->get_marc_notes({ marcflavour => $marcflavour, opac => 1 });
787
my $marcauthorsarray = $biblio->get_authors_from_MARC;
787
788
788
if( C4::Context->preference('ArticleRequests') ) {
789
if( C4::Context->preference('ArticleRequests') ) {
789
    my $patron = $borrowernumber ? Koha::Patrons->find($borrowernumber) : undef;
790
    my $patron = $borrowernumber ? Koha::Patrons->find($borrowernumber) : undef;
Lines 799-804 if( C4::Context->preference('ArticleRequests') ) { Link Here
799
my $norequests = ! $biblio->items->filter_by_for_hold->count;
800
my $norequests = ! $biblio->items->filter_by_for_hold->count;
800
    $template->param(
801
    $template->param(
801
                     MARCNOTES               => $marcnotesarray,
802
                     MARCNOTES               => $marcnotesarray,
803
                     MARCAUTHORS             => $marcauthorsarray,
802
                     norequests              => $norequests,
804
                     norequests              => $norequests,
803
                     itemdata_ccode          => $itemfields{ccode},
805
                     itemdata_ccode          => $itemfields{ccode},
804
                     itemdata_materials      => $itemfields{materials},
806
                     itemdata_materials      => $itemfields{materials},
(-)a/opac/opac-sendbasket.pl (-1 / +2 lines)
Lines 81-92 if ( $email_add ) { Link Here
81
81
82
        my $dat              = GetBiblioData($biblionumber);
82
        my $dat              = GetBiblioData($biblionumber);
83
        next unless $dat;
83
        next unless $dat;
84
        my $biblio           = Koha::Biblios->find( $biblionumber );
84
        my $record           = GetMarcBiblio({
85
        my $record           = GetMarcBiblio({
85
            biblionumber => $biblionumber,
86
            biblionumber => $biblionumber,
86
            embed_items  => 1,
87
            embed_items  => 1,
87
            opac         => 1,
88
            opac         => 1,
88
            borcat       => $borcat });
89
            borcat       => $borcat });
89
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
90
        my $marcauthorsarray = $biblio->get_authors_from_MARC;
90
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
91
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
91
92
92
        my @items = GetItemsInfo( $biblionumber );
93
        my @items = GetItemsInfo( $biblionumber );
(-)a/opac/opac-sendshelf.pl (-1 / +2 lines)
Lines 92-101 if ( $email ) { Link Here
92
            opac         => 1,
92
            opac         => 1,
93
            borcat       => $borcat });
93
            borcat       => $borcat });
94
        next unless $record;
94
        next unless $record;
95
        my $biblio           = Koha::Biblios->find( $biblionumber );
95
        my $fw               = GetFrameworkCode($biblionumber);
96
        my $fw               = GetFrameworkCode($biblionumber);
96
        my $dat              = GetBiblioData($biblionumber);
97
        my $dat              = GetBiblioData($biblionumber);
97
98
98
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
99
        my $marcauthorsarray = $biblio->get_authors_from_MARC;
99
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
100
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
100
101
101
        my @items = GetItemsInfo( $biblionumber );
102
        my @items = GetItemsInfo( $biblionumber );
(-)a/t/Biblio.t (-7 / +1 lines)
Lines 21-27 use Test::More; Link Here
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
24
plan tests => 39;
24
plan tests => 37;
25
25
26
26
27
use_ok('C4::Biblio', qw( AddBiblio ModBiblio BiblioAutoLink LinkBibHeadingsToAuthorities GetMarcPrice GetMarcQuantity GetMarcControlnumber GetMarcISBN GetMarcISSN GetMarcSubjects GetMarcAuthors GetMarcUrls GetMarcSeries TransformMarcToKoha ModBiblioMarc RemoveAllNsb GetMarcBiblio UpdateTotalIssues ));
27
use_ok('C4::Biblio', qw( AddBiblio ModBiblio BiblioAutoLink LinkBibHeadingsToAuthorities GetMarcPrice GetMarcQuantity GetMarcControlnumber GetMarcISBN GetMarcISSN GetMarcSubjects GetMarcAuthors GetMarcUrls GetMarcSeries TransformMarcToKoha ModBiblioMarc RemoveAllNsb GetMarcBiblio UpdateTotalIssues ));
Lines 94-105 warning_is { $ret = GetMarcSubjects() } Link Here
94
94
95
ok( !defined $ret, 'GetMarcSubjects returns undef if not passed rec');
95
ok( !defined $ret, 'GetMarcSubjects returns undef if not passed rec');
96
96
97
warning_is { $ret = GetMarcAuthors() }
98
           { carped => 'GetMarcAuthors called on undefined record'},
99
           "GetMarcAuthors returns carped warning on undef record";
100
101
ok( !defined $ret, 'GetMarcAuthors returns undef if not passed rec');
102
103
warning_is { $ret = GetMarcUrls() }
97
warning_is { $ret = GetMarcUrls() }
104
           { carped => 'GetMarcUrls called on undefined record'},
98
           { carped => 'GetMarcUrls called on undefined record'},
105
           "GetMarcUrls returns carped warning on undef record";
99
           "GetMarcUrls returns carped warning on undef record";
(-)a/t/db_dependent/Koha/Biblio.t (-1 / +29 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 19;
20
use Test::More tests => 20;
21
use Test::Warn;
21
use Test::Warn;
22
22
23
use C4::Biblio qw( AddBiblio ModBiblio ModBiblioMarc );
23
use C4::Biblio qw( AddBiblio ModBiblio ModBiblioMarc );
Lines 859-864 subtest 'current_checkouts() and old_checkouts() tests' => sub { Link Here
859
    $schema->storage->txn_rollback;
859
    $schema->storage->txn_rollback;
860
};
860
};
861
861
862
subtest 'get_authors_from_MARC() tests' => sub {
863
864
    plan tests => 1;
865
866
    $schema->storage->txn_begin;
867
868
    my $biblio = $builder->build_sample_biblio;
869
    my $record = $biblio->metadata->record;
870
871
    # add author information
872
    my $field = MARC::Field->new('700','1','','a' => 'Jefferson, Thomas');
873
    $record->append_fields($field);
874
    $field = MARC::Field->new('700','1','','d' => '1743-1826');
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);
880
881
    # get record
882
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
883
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
884
885
    is( 4, @{$biblio->get_authors_from_MARC}, 'get_authors_from_MARC retrieves correct number of author subfields' );
886
887
    $schema->storage->txn_rollback;
888
};
889
862
sub component_record1 {
890
sub component_record1 {
863
    my $marc = MARC::Record->new;
891
    my $marc = MARC::Record->new;
864
    $marc->append_fields(
892
    $marc->append_fields(
(-)a/virtualshelves/sendshelf.pl (-2 / +2 lines)
Lines 73-83 if ($to_address) { Link Here
73
73
74
    while ( my $content = $contents->next ) {
74
    while ( my $content = $contents->next ) {
75
        my $biblionumber     = $content->biblionumber;
75
        my $biblionumber     = $content->biblionumber;
76
        my $biblio           = Koha::Biblios->find( $biblionumber );
76
        my $dat              = GetBiblioData($biblionumber);
77
        my $dat              = GetBiblioData($biblionumber);
77
        my $record           = GetMarcBiblio({
78
        my $record           = GetMarcBiblio({
78
            biblionumber => $biblionumber,
79
            biblionumber => $biblionumber,
79
            embed_items  => 1 });
80
            embed_items  => 1 });
80
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
81
        my $marcauthorsarray = $biblio->get_authors_from_MARC;
81
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
82
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
82
83
83
        my @items = GetItemsInfo($biblionumber);
84
        my @items = GetItemsInfo($biblionumber);
84
- 

Return to bug 27266