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 1625-1729 sub GetMarcSubjects { Link Here
1625
    return \@marcsubjects;
1624
    return \@marcsubjects;
1626
}    #end getMARCsubjects
1625
}    #end getMARCsubjects
1627
1626
1628
=head2 GetMarcAuthors
1629
1630
  authors = GetMarcAuthors($record,$marcflavour);
1631
1632
Get all authors from the MARC record and returns them in an array.
1633
The authors are stored in different fields depending on MARC flavour
1634
1635
=cut
1636
1637
sub GetMarcAuthors {
1638
    my ( $record, $marcflavour ) = @_;
1639
    if (!$record) {
1640
        carp 'GetMarcAuthors called on undefined record';
1641
        return;
1642
    }
1643
    my ( $mintag, $maxtag, $fields_filter );
1644
1645
    # tagslib useful only for UNIMARC author responsibilities
1646
    my $tagslib;
1647
    if ( $marcflavour eq "UNIMARC" ) {
1648
        # FIXME : we don't have the framework available, we take the default framework. May be buggy on some setups, will be usually correct.
1649
        $tagslib = GetMarcStructure( 1, '', { unsafe => 1 });
1650
        $mintag = "700";
1651
        $maxtag = "712";
1652
        $fields_filter = '7..';
1653
    } else { # marc21
1654
        $mintag = "700";
1655
        $maxtag = "720";
1656
        $fields_filter = '7..';
1657
    }
1658
1659
    my @marcauthors;
1660
    my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
1661
1662
    foreach my $field ( $record->field($fields_filter) ) {
1663
        next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
1664
        my @subfields_loop;
1665
        my @link_loop;
1666
        my @subfields  = $field->subfields();
1667
        my $count_auth = 0;
1668
1669
        # if there is an authority link, build the link with Koha-Auth-Number: subfield9
1670
        my $subfield9 = $field->subfield('9');
1671
        if ($subfield9) {
1672
            my $linkvalue = $subfield9;
1673
            $linkvalue =~ s/(\(|\))//g;
1674
            @link_loop = ( { 'limit' => 'an', 'link' => $linkvalue } );
1675
        }
1676
1677
        # other subfields
1678
        my $unimarc3;
1679
        for my $authors_subfield (@subfields) {
1680
            next if ( $authors_subfield->[0] eq '9' );
1681
1682
            # unimarc3 contains the $3 of the author for UNIMARC.
1683
            # For french academic libraries, it's the "ppn", and it's required for idref webservice
1684
            $unimarc3 = $authors_subfield->[1] if $marcflavour eq 'UNIMARC' and $authors_subfield->[0] =~ /3/;
1685
1686
            # don't load unimarc subfields 3, 5
1687
            next if ( $marcflavour eq 'UNIMARC' and ( $authors_subfield->[0] =~ /3|5/ ) );
1688
1689
            my $code = $authors_subfield->[0];
1690
            my $value        = $authors_subfield->[1];
1691
            my $linkvalue    = $value;
1692
            $linkvalue =~ s/(\(|\))//g;
1693
            # UNIMARC author responsibility
1694
            if ( $marcflavour eq 'UNIMARC' and $code eq '4' ) {
1695
                $value = GetAuthorisedValueDesc( $field->tag(), $code, $value, '', $tagslib );
1696
                $linkvalue = "($value)";
1697
            }
1698
            # if no authority link, build a search query
1699
            unless ($subfield9) {
1700
                push @link_loop, {
1701
                    limit    => 'au',
1702
                    'link'   => $linkvalue,
1703
                    operator => (scalar @link_loop) ? ' and ' : undef
1704
                };
1705
            }
1706
            my @this_link_loop = @link_loop;
1707
            # do not display $0
1708
            unless ( $code eq '0') {
1709
                push @subfields_loop, {
1710
                    tag       => $field->tag(),
1711
                    code      => $code,
1712
                    value     => $value,
1713
                    link_loop => \@this_link_loop,
1714
                    separator => (scalar @subfields_loop) ? $AuthoritySeparator : ''
1715
                };
1716
            }
1717
        }
1718
        push @marcauthors, {
1719
            MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop,
1720
            authoritylink => $subfield9,
1721
            unimarc3 => $unimarc3
1722
        };
1723
    }
1724
    return \@marcauthors;
1725
}
1726
1727
=head2 GetMarcUrls
1627
=head2 GetMarcUrls
1728
1628
1729
  $marcurls = GetMarcUrls($record,$marcflavour);
1629
  $marcurls = GetMarcUrls($record,$marcflavour);
(-)a/Koha/Biblio.pm (+97 lines)
Lines 842-847 sub get_marc_notes { Link Here
842
    return \@marcnotes;
842
    return \@marcnotes;
843
}
843
}
844
844
845
=head3 get_authors_from_MARC
846
847
    my $authors = $biblio->get_authors_from_MARC;
848
849
Get all authors from the MARC record and returns them in an array.
850
The authors are stored in different fields depending on MARC flavour
851
852
=cut
853
854
sub get_authors_from_MARC {
855
    my ( $self, $params ) = @_;
856
857
    my ( $mintag, $maxtag, $fields_filter );
858
    my $marcflavour = C4::Context->preference('marcflavour');
859
860
    # tagslib useful only for UNIMARC author responsibilities
861
    my $tagslib;
862
    if ( $marcflavour eq "UNIMARC" ) {
863
        # FIXME : we don't have the framework available, we take the default framework. May be buggy on some setups, will be usually correct.
864
        $tagslib = C4::Biblio::GetMarcStructure( 1, '', { unsafe => 1 });
865
        $mintag = "700";
866
        $maxtag = "712";
867
        $fields_filter = '7..';
868
    } else { # marc21/normarc
869
        $mintag = "700";
870
        $maxtag = "720";
871
        $fields_filter = '7..';
872
    }
873
874
    my @marcauthors;
875
    my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
876
877
    foreach my $field ( $self->metadata->record->field($fields_filter) ) {
878
        next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
879
        my @subfields_loop;
880
        my @link_loop;
881
        my @subfields  = $field->subfields();
882
        my $count_auth = 0;
883
884
        # if there is an authority link, build the link with Koha-Auth-Number: subfield9
885
        my $subfield9 = $field->subfield('9');
886
        if ($subfield9) {
887
            my $linkvalue = $subfield9;
888
            $linkvalue =~ s/(\(|\))//g;
889
            @link_loop = ( { 'limit' => 'an', 'link' => $linkvalue } );
890
        }
891
892
        # other subfields
893
        my $unimarc3;
894
        for my $authors_subfield (@subfields) {
895
            next if ( $authors_subfield->[0] eq '9' );
896
897
            # unimarc3 contains the $3 of the author for UNIMARC.
898
            # For french academic libraries, it's the "ppn", and it's required for idref webservice
899
            $unimarc3 = $authors_subfield->[1] if $marcflavour eq 'UNIMARC' and $authors_subfield->[0] =~ /3/;
900
901
            # don't load unimarc subfields 3, 5
902
            next if ( $marcflavour eq 'UNIMARC' and ( $authors_subfield->[0] =~ /3|5/ ) );
903
904
            my $code = $authors_subfield->[0];
905
            my $value        = $authors_subfield->[1];
906
            my $linkvalue    = $value;
907
            $linkvalue =~ s/(\(|\))//g;
908
            # UNIMARC author responsibility
909
            if ( $marcflavour eq 'UNIMARC' and $code eq '4' ) {
910
                $value = C4::Biblio::GetAuthorisedValueDesc( $field->tag(), $code, $value, '', $tagslib );
911
                $linkvalue = "($value)";
912
            }
913
            # if no authority link, build a search query
914
            unless ($subfield9) {
915
                push @link_loop, {
916
                    limit    => 'au',
917
                    'link'   => $linkvalue,
918
                    operator => (scalar @link_loop) ? ' and ' : undef
919
                };
920
            }
921
            my @this_link_loop = @link_loop;
922
            # do not display $0
923
            unless ( $code eq '0') {
924
                push @subfields_loop, {
925
                    tag       => $field->tag(),
926
                    code      => $code,
927
                    value     => $value,
928
                    link_loop => \@this_link_loop,
929
                    separator => (scalar @subfields_loop) ? $AuthoritySeparator : ''
930
                };
931
            }
932
        }
933
        push @marcauthors, {
934
            MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop,
935
            authoritylink => $subfield9,
936
            unimarc3 => $unimarc3
937
        };
938
    }
939
    return \@marcauthors;
940
}
941
845
=head3 to_api
942
=head3 to_api
846
943
847
    my $json = $biblio->to_api;
944
    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 785-790 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) { Link Here
785
}
785
}
786
786
787
my $marcnotesarray = $biblio->get_marc_notes({ marcflavour => $marcflavour, opac => 1 });
787
my $marcnotesarray = $biblio->get_marc_notes({ marcflavour => $marcflavour, opac => 1 });
788
my $marcauthorsarray = $biblio->get_authors_from_MARC;
788
789
789
if( C4::Context->preference('ArticleRequests') ) {
790
if( C4::Context->preference('ArticleRequests') ) {
790
    my $patron = $borrowernumber ? Koha::Patrons->find($borrowernumber) : undef;
791
    my $patron = $borrowernumber ? Koha::Patrons->find($borrowernumber) : undef;
Lines 800-805 if( C4::Context->preference('ArticleRequests') ) { Link Here
800
my $norequests = ! $biblio->items->filter_by_for_hold->count;
801
my $norequests = ! $biblio->items->filter_by_for_hold->count;
801
    $template->param(
802
    $template->param(
802
                     MARCNOTES               => $marcnotesarray,
803
                     MARCNOTES               => $marcnotesarray,
804
                     MARCAUTHORS             => $marcauthorsarray,
803
                     norequests              => $norequests,
805
                     norequests              => $norequests,
804
                     RequestOnOpac           => C4::Context->preference("RequestOnOpac"),
806
                     RequestOnOpac           => C4::Context->preference("RequestOnOpac"),
805
                     itemdata_ccode          => $itemfields{ccode},
807
                     itemdata_ccode          => $itemfields{ccode},
(-)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 => 16;
20
use Test::More tests => 17;
21
21
22
use C4::Biblio qw( AddBiblio ModBiblio );
22
use C4::Biblio qw( AddBiblio ModBiblio );
23
use Koha::Database;
23
use Koha::Database;
Lines 736-738 subtest 'article_requests() tests' => sub { Link Here
736
736
737
    $schema->storage->txn_rollback;
737
    $schema->storage->txn_rollback;
738
};
738
};
739
740
subtest 'get_authors_from_MARC() tests' => sub {
741
742
    plan tests => 1;
743
744
    $schema->storage->txn_begin;
745
746
    my $biblio = $builder->build_sample_biblio;
747
    my $record = $biblio->metadata->record;
748
749
    # add author information
750
    my $field = MARC::Field->new('700','1','','a' => 'Jefferson, Thomas');
751
    $record->append_fields($field);
752
    $field = MARC::Field->new('700','1','','d' => '1743-1826');
753
    $record->append_fields($field);
754
    $field = MARC::Field->new('700','1','','e' => 'former owner.');
755
    $record->append_fields($field);
756
    $field = MARC::Field->new('700','1','','5' => 'MH');
757
    $record->append_fields($field);
758
759
    # get record
760
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
761
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
762
763
    is( 4, @{$biblio->get_authors_from_MARC}, 'get_authors_from_MARC retrieves correct number of author subfields' );
764
765
    $schema->storage->txn_rollback;
766
};
(-)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