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 1616-1720 sub GetMarcSubjects { Link Here
1616
    return \@marcsubjects;
1615
    return \@marcsubjects;
1617
}    #end getMARCsubjects
1616
}    #end getMARCsubjects
1618
1617
1619
=head2 GetMarcAuthors
1620
1621
  authors = GetMarcAuthors($record,$marcflavour);
1622
1623
Get all authors from the MARC record and returns them in an array.
1624
The authors are stored in different fields depending on MARC flavour
1625
1626
=cut
1627
1628
sub GetMarcAuthors {
1629
    my ( $record, $marcflavour ) = @_;
1630
    if (!$record) {
1631
        carp 'GetMarcAuthors called on undefined record';
1632
        return;
1633
    }
1634
    my ( $mintag, $maxtag, $fields_filter );
1635
1636
    # tagslib useful only for UNIMARC author responsibilities
1637
    my $tagslib;
1638
    if ( $marcflavour eq "UNIMARC" ) {
1639
        # FIXME : we don't have the framework available, we take the default framework. May be buggy on some setups, will be usually correct.
1640
        $tagslib = GetMarcStructure( 1, '', { unsafe => 1 });
1641
        $mintag = "700";
1642
        $maxtag = "712";
1643
        $fields_filter = '7..';
1644
    } else { # marc21/normarc
1645
        $mintag = "700";
1646
        $maxtag = "720";
1647
        $fields_filter = '7..';
1648
    }
1649
1650
    my @marcauthors;
1651
    my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
1652
1653
    foreach my $field ( $record->field($fields_filter) ) {
1654
        next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
1655
        my @subfields_loop;
1656
        my @link_loop;
1657
        my @subfields  = $field->subfields();
1658
        my $count_auth = 0;
1659
1660
        # if there is an authority link, build the link with Koha-Auth-Number: subfield9
1661
        my $subfield9 = $field->subfield('9');
1662
        if ($subfield9) {
1663
            my $linkvalue = $subfield9;
1664
            $linkvalue =~ s/(\(|\))//g;
1665
            @link_loop = ( { 'limit' => 'an', 'link' => $linkvalue } );
1666
        }
1667
1668
        # other subfields
1669
        my $unimarc3;
1670
        for my $authors_subfield (@subfields) {
1671
            next if ( $authors_subfield->[0] eq '9' );
1672
1673
            # unimarc3 contains the $3 of the author for UNIMARC.
1674
            # For french academic libraries, it's the "ppn", and it's required for idref webservice
1675
            $unimarc3 = $authors_subfield->[1] if $marcflavour eq 'UNIMARC' and $authors_subfield->[0] =~ /3/;
1676
1677
            # don't load unimarc subfields 3, 5
1678
            next if ( $marcflavour eq 'UNIMARC' and ( $authors_subfield->[0] =~ /3|5/ ) );
1679
1680
            my $code = $authors_subfield->[0];
1681
            my $value        = $authors_subfield->[1];
1682
            my $linkvalue    = $value;
1683
            $linkvalue =~ s/(\(|\))//g;
1684
            # UNIMARC author responsibility
1685
            if ( $marcflavour eq 'UNIMARC' and $code eq '4' ) {
1686
                $value = GetAuthorisedValueDesc( $field->tag(), $code, $value, '', $tagslib );
1687
                $linkvalue = "($value)";
1688
            }
1689
            # if no authority link, build a search query
1690
            unless ($subfield9) {
1691
                push @link_loop, {
1692
                    limit    => 'au',
1693
                    'link'   => $linkvalue,
1694
                    operator => (scalar @link_loop) ? ' and ' : undef
1695
                };
1696
            }
1697
            my @this_link_loop = @link_loop;
1698
            # do not display $0
1699
            unless ( $code eq '0') {
1700
                push @subfields_loop, {
1701
                    tag       => $field->tag(),
1702
                    code      => $code,
1703
                    value     => $value,
1704
                    link_loop => \@this_link_loop,
1705
                    separator => (scalar @subfields_loop) ? $AuthoritySeparator : ''
1706
                };
1707
            }
1708
        }
1709
        push @marcauthors, {
1710
            MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop,
1711
            authoritylink => $subfield9,
1712
            unimarc3 => $unimarc3
1713
        };
1714
    }
1715
    return \@marcauthors;
1716
}
1717
1718
=head2 GetMarcUrls
1618
=head2 GetMarcUrls
1719
1619
1720
  $marcurls = GetMarcUrls($record,$marcflavour);
1620
  $marcurls = GetMarcUrls($record,$marcflavour);
(-)a/Koha/Biblio.pm (+97 lines)
Lines 850-855 sub get_marc_notes { Link Here
850
    return \@marcnotes;
850
    return \@marcnotes;
851
}
851
}
852
852
853
=head3 get_authors_from_MARC
854
855
    my $authors = $biblio->get_authors_from_MARC;
856
857
Get all authors from the MARC record and returns them in an array.
858
The authors are stored in different fields depending on MARC flavour
859
860
=cut
861
862
sub get_authors_from_MARC {
863
    my ( $self, $params ) = @_;
864
865
    my ( $mintag, $maxtag, $fields_filter );
866
    my $marcflavour = C4::Context->preference('marcflavour');
867
868
    # tagslib useful only for UNIMARC author responsibilities
869
    my $tagslib;
870
    if ( $marcflavour eq "UNIMARC" ) {
871
        # FIXME : we don't have the framework available, we take the default framework. May be buggy on some setups, will be usually correct.
872
        $tagslib = C4::Biblio::GetMarcStructure( 1, '', { unsafe => 1 });
873
        $mintag = "700";
874
        $maxtag = "712";
875
        $fields_filter = '7..';
876
    } else { # marc21/normarc
877
        $mintag = "700";
878
        $maxtag = "720";
879
        $fields_filter = '7..';
880
    }
881
882
    my @marcauthors;
883
    my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
884
885
    foreach my $field ( $self->metadata->record->field($fields_filter) ) {
886
        next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
887
        my @subfields_loop;
888
        my @link_loop;
889
        my @subfields  = $field->subfields();
890
        my $count_auth = 0;
891
892
        # if there is an authority link, build the link with Koha-Auth-Number: subfield9
893
        my $subfield9 = $field->subfield('9');
894
        if ($subfield9) {
895
            my $linkvalue = $subfield9;
896
            $linkvalue =~ s/(\(|\))//g;
897
            @link_loop = ( { 'limit' => 'an', 'link' => $linkvalue } );
898
        }
899
900
        # other subfields
901
        my $unimarc3;
902
        for my $authors_subfield (@subfields) {
903
            next if ( $authors_subfield->[0] eq '9' );
904
905
            # unimarc3 contains the $3 of the author for UNIMARC.
906
            # For french academic libraries, it's the "ppn", and it's required for idref webservice
907
            $unimarc3 = $authors_subfield->[1] if $marcflavour eq 'UNIMARC' and $authors_subfield->[0] =~ /3/;
908
909
            # don't load unimarc subfields 3, 5
910
            next if ( $marcflavour eq 'UNIMARC' and ( $authors_subfield->[0] =~ /3|5/ ) );
911
912
            my $code = $authors_subfield->[0];
913
            my $value        = $authors_subfield->[1];
914
            my $linkvalue    = $value;
915
            $linkvalue =~ s/(\(|\))//g;
916
            # UNIMARC author responsibility
917
            if ( $marcflavour eq 'UNIMARC' and $code eq '4' ) {
918
                $value = C4::Biblio::GetAuthorisedValueDesc( $field->tag(), $code, $value, '', $tagslib );
919
                $linkvalue = "($value)";
920
            }
921
            # if no authority link, build a search query
922
            unless ($subfield9) {
923
                push @link_loop, {
924
                    limit    => 'au',
925
                    'link'   => $linkvalue,
926
                    operator => (scalar @link_loop) ? ' and ' : undef
927
                };
928
            }
929
            my @this_link_loop = @link_loop;
930
            # do not display $0
931
            unless ( $code eq '0') {
932
                push @subfields_loop, {
933
                    tag       => $field->tag(),
934
                    code      => $code,
935
                    value     => $value,
936
                    link_loop => \@this_link_loop,
937
                    separator => (scalar @subfields_loop) ? $AuthoritySeparator : ''
938
                };
939
            }
940
        }
941
        push @marcauthors, {
942
            MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop,
943
            authoritylink => $subfield9,
944
            unimarc3 => $unimarc3
945
        };
946
    }
947
    return \@marcauthors;
948
}
949
853
=head3 to_api
950
=head3 to_api
854
951
855
    my $json = $biblio->to_api;
952
    my $json = $biblio->to_api;
(-)a/basket/basket.pl (-1 / +1 lines)
Lines 65-71 foreach my $biblionumber ( @bibs ) { Link Here
65
    my $biblio           = Koha::Biblios->find( $biblionumber );
65
    my $biblio           = Koha::Biblios->find( $biblionumber );
66
    my $record           = &GetMarcBiblio({ biblionumber => $biblionumber });
66
    my $record           = &GetMarcBiblio({ biblionumber => $biblionumber });
67
    my $marcnotesarray   = $biblio->get_marc_notes({ marcflavour => $marcflavour });
67
    my $marcnotesarray   = $biblio->get_marc_notes({ marcflavour => $marcflavour });
68
    my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
68
    my $marcauthorsarray = $biblio->get_authors_from_MARC;
69
    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
69
    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
70
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
70
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
71
    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
71
    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
(-)a/basket/sendbasket.pl (-1 / +2 lines)
Lines 69-78 if ( $email_add ) { Link Here
69
69
70
        my $dat              = GetBiblioData($biblionumber);
70
        my $dat              = GetBiblioData($biblionumber);
71
        next unless $dat;
71
        next unless $dat;
72
        my $biblio           = Koha::Biblios->find( $biblionumber );
72
        my $record           = GetMarcBiblio({
73
        my $record           = GetMarcBiblio({
73
            biblionumber => $biblionumber,
74
            biblionumber => $biblionumber,
74
            embed_items => 1 });
75
            embed_items => 1 });
75
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
76
        my $marcauthorsarray = $biblio->get_authors_from_MARC;
76
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
77
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
77
78
78
        my @items = GetItemsInfo( $biblionumber );
79
        my @items = GetItemsInfo( $biblionumber );
(-)a/opac/opac-basket.pl (-1 / +1 lines)
Lines 84-90 foreach my $biblionumber ( @bibs ) { Link Here
84
    $record_processor->process($record);
84
    $record_processor->process($record);
85
    next unless $record;
85
    next unless $record;
86
    my $marcnotesarray   = $biblio->get_marc_notes({ marcflavour => $marcflavour, opac => 1 });
86
    my $marcnotesarray   = $biblio->get_marc_notes({ marcflavour => $marcflavour, opac => 1 });
87
    my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
87
    my $marcauthorsarray = $biblio->get_authors_from_MARC;
88
    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
88
    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
89
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
89
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
90
    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
90
    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
(-)a/opac/opac-detail.pl (-1 / +1 lines)
Lines 802-808 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) { Link Here
802
## get notes and subjects from MARC record
802
## get notes and subjects from MARC record
803
if (!C4::Context->preference("OPACXSLTDetailsDisplay") ) {
803
if (!C4::Context->preference("OPACXSLTDetailsDisplay") ) {
804
    my $marcisbnsarray   = GetMarcISBN    ($record,$marcflavour);
804
    my $marcisbnsarray   = GetMarcISBN    ($record,$marcflavour);
805
    my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
805
    my $marcauthorsarray = $biblio->get_authors_from_MARC;
806
    my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
806
    my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
807
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
807
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
808
    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
808
    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
(-)a/opac/opac-sendbasket.pl (-1 / +2 lines)
Lines 77-88 if ( $email_add ) { Link Here
77
77
78
        my $dat              = GetBiblioData($biblionumber);
78
        my $dat              = GetBiblioData($biblionumber);
79
        next unless $dat;
79
        next unless $dat;
80
        my $biblio           = Koha::Biblios->find( $biblionumber );
80
        my $record           = GetMarcBiblio({
81
        my $record           = GetMarcBiblio({
81
            biblionumber => $biblionumber,
82
            biblionumber => $biblionumber,
82
            embed_items  => 1,
83
            embed_items  => 1,
83
            opac         => 1,
84
            opac         => 1,
84
            borcat       => $borcat });
85
            borcat       => $borcat });
85
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
86
        my $marcauthorsarray = $biblio->get_authors_from_MARC;
86
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
87
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
87
88
88
        my @items = GetItemsInfo( $biblionumber );
89
        my @items = GetItemsInfo( $biblionumber );
(-)a/opac/opac-sendshelf.pl (-1 / +2 lines)
Lines 86-95 if ( $email ) { Link Here
86
            opac         => 1,
86
            opac         => 1,
87
            borcat       => $borcat });
87
            borcat       => $borcat });
88
        next unless $record;
88
        next unless $record;
89
        my $biblio           = Koha::Biblios->find( $biblionumber );
89
        my $fw               = GetFrameworkCode($biblionumber);
90
        my $fw               = GetFrameworkCode($biblionumber);
90
        my $dat              = GetBiblioData($biblionumber);
91
        my $dat              = GetBiblioData($biblionumber);
91
92
92
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
93
        my $marcauthorsarray = $biblio->get_authors_from_MARC;
93
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
94
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
94
95
95
        my @items = GetItemsInfo( $biblionumber );
96
        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
use_ok('C4::Biblio');
26
use_ok('C4::Biblio');
27
27
Lines 93-104 warning_is { $ret = GetMarcSubjects() } Link Here
93
93
94
ok( !defined $ret, 'GetMarcSubjects returns undef if not passed rec');
94
ok( !defined $ret, 'GetMarcSubjects returns undef if not passed rec');
95
95
96
warning_is { $ret = GetMarcAuthors() }
97
           { carped => 'GetMarcAuthors called on undefined record'},
98
           "GetMarcAuthors returns carped warning on undef record";
99
100
ok( !defined $ret, 'GetMarcAuthors returns undef if not passed rec');
101
102
warning_is { $ret = GetMarcUrls() }
96
warning_is { $ret = GetMarcUrls() }
103
           { carped => 'GetMarcUrls called on undefined record'},
97
           { carped => 'GetMarcUrls called on undefined record'},
104
           "GetMarcUrls returns carped warning on undef record";
98
           "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 => 14;
20
use Test::More tests => 15;
21
21
22
use C4::Biblio;
22
use C4::Biblio;
23
use Koha::Database;
23
use Koha::Database;
Lines 610-612 subtest 'get_marc_notes() UNIMARC tests' => sub { Link Here
610
610
611
    $schema->storage->txn_rollback;
611
    $schema->storage->txn_rollback;
612
};
612
};
613
614
subtest 'get_authors_from_MARC() tests' => sub {
615
616
    plan tests => 1;
617
618
    $schema->storage->txn_begin;
619
620
    my $biblio = $builder->build_sample_biblio;
621
    my $record = $biblio->metadata->record;
622
623
    # add author information
624
    my $field = MARC::Field->new('700','1','','a' => 'Jefferson, Thomas');
625
    $record->append_fields($field);
626
    $field = MARC::Field->new('700','1','','d' => '1743-1826');
627
    $record->append_fields($field);
628
    $field = MARC::Field->new('700','1','','e' => 'former owner.');
629
    $record->append_fields($field);
630
    $field = MARC::Field->new('700','1','','5' => 'MH');
631
    $record->append_fields($field);
632
633
    # get record
634
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
635
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
636
637
    is( 4, @{$biblio->get_authors_from_MARC}, 'get_authors_from_MARC retrieves correct number of author subfields' );
638
639
    $schema->storage->txn_rollback;
640
};
(-)a/virtualshelves/sendshelf.pl (-2 / +2 lines)
Lines 67-77 if ($to_address) { Link Here
67
67
68
    while ( my $content = $contents->next ) {
68
    while ( my $content = $contents->next ) {
69
        my $biblionumber     = $content->biblionumber;
69
        my $biblionumber     = $content->biblionumber;
70
        my $biblio           = Koha::Biblios->find( $biblionumber );
70
        my $dat              = GetBiblioData($biblionumber);
71
        my $dat              = GetBiblioData($biblionumber);
71
        my $record           = GetMarcBiblio({
72
        my $record           = GetMarcBiblio({
72
            biblionumber => $biblionumber,
73
            biblionumber => $biblionumber,
73
            embed_items  => 1 });
74
            embed_items  => 1 });
74
        my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
75
        my $marcauthorsarray = $biblio->get_authors_from_MARC;
75
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
76
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
76
77
77
        my @items = GetItemsInfo($biblionumber);
78
        my @items = GetItemsInfo($biblionumber);
78
- 

Return to bug 27266