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

(-)a/C4/Biblio.pm (-100 lines)
Lines 36-42 BEGIN { Link Here
36
        GetMarcISBN
36
        GetMarcISBN
37
        GetMarcISSN
37
        GetMarcISSN
38
        GetMarcSubjects
38
        GetMarcSubjects
39
        GetMarcAuthors
40
        GetMarcSeries
39
        GetMarcSeries
41
        GetMarcUrls
40
        GetMarcUrls
42
        GetUsedMarcStructure
41
        GetUsedMarcStructure
Lines 1708-1812 sub GetMarcSubjects { Link Here
1708
    return \@marcsubjects;
1707
    return \@marcsubjects;
1709
}    #end getMARCsubjects
1708
}    #end getMARCsubjects
1710
1709
1711
=head2 GetMarcAuthors
1712
1713
  authors = GetMarcAuthors($record,$marcflavour);
1714
1715
Get all authors from the MARC record and returns them in an array.
1716
The authors are stored in different fields depending on MARC flavour
1717
1718
=cut
1719
1720
sub GetMarcAuthors {
1721
    my ( $record, $marcflavour ) = @_;
1722
    if (!$record) {
1723
        carp 'GetMarcAuthors called on undefined record';
1724
        return;
1725
    }
1726
    my ( $mintag, $maxtag, $fields_filter );
1727
1728
    # tagslib useful only for UNIMARC author responsibilities
1729
    my $tagslib;
1730
    if ( $marcflavour eq "UNIMARC" ) {
1731
        # FIXME : we don't have the framework available, we take the default framework. May be buggy on some setups, will be usually correct.
1732
        $tagslib = GetMarcStructure( 1, '', { unsafe => 1 });
1733
        $mintag = "700";
1734
        $maxtag = "712";
1735
        $fields_filter = '7..';
1736
    } else { # marc21/normarc
1737
        $mintag = "700";
1738
        $maxtag = "720";
1739
        $fields_filter = '7..';
1740
    }
1741
1742
    my @marcauthors;
1743
    my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
1744
1745
    foreach my $field ( $record->field($fields_filter) ) {
1746
        next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
1747
        my @subfields_loop;
1748
        my @link_loop;
1749
        my @subfields  = $field->subfields();
1750
        my $count_auth = 0;
1751
1752
        # if there is an authority link, build the link with Koha-Auth-Number: subfield9
1753
        my $subfield9 = $field->subfield('9');
1754
        if ($subfield9) {
1755
            my $linkvalue = $subfield9;
1756
            $linkvalue =~ s/(\(|\))//g;
1757
            @link_loop = ( { 'limit' => 'an', 'link' => $linkvalue } );
1758
        }
1759
1760
        # other subfields
1761
        my $unimarc3;
1762
        for my $authors_subfield (@subfields) {
1763
            next if ( $authors_subfield->[0] eq '9' );
1764
1765
            # unimarc3 contains the $3 of the author for UNIMARC.
1766
            # For french academic libraries, it's the "ppn", and it's required for idref webservice
1767
            $unimarc3 = $authors_subfield->[1] if $marcflavour eq 'UNIMARC' and $authors_subfield->[0] =~ /3/;
1768
1769
            # don't load unimarc subfields 3, 5
1770
            next if ( $marcflavour eq 'UNIMARC' and ( $authors_subfield->[0] =~ /3|5/ ) );
1771
1772
            my $code = $authors_subfield->[0];
1773
            my $value        = $authors_subfield->[1];
1774
            my $linkvalue    = $value;
1775
            $linkvalue =~ s/(\(|\))//g;
1776
            # UNIMARC author responsibility
1777
            if ( $marcflavour eq 'UNIMARC' and $code eq '4' ) {
1778
                $value = GetAuthorisedValueDesc( $field->tag(), $code, $value, '', $tagslib );
1779
                $linkvalue = "($value)";
1780
            }
1781
            # if no authority link, build a search query
1782
            unless ($subfield9) {
1783
                push @link_loop, {
1784
                    limit    => 'au',
1785
                    'link'   => $linkvalue,
1786
                    operator => (scalar @link_loop) ? ' and ' : undef
1787
                };
1788
            }
1789
            my @this_link_loop = @link_loop;
1790
            # do not display $0
1791
            unless ( $code eq '0') {
1792
                push @subfields_loop, {
1793
                    tag       => $field->tag(),
1794
                    code      => $code,
1795
                    value     => $value,
1796
                    link_loop => \@this_link_loop,
1797
                    separator => (scalar @subfields_loop) ? $AuthoritySeparator : ''
1798
                };
1799
            }
1800
        }
1801
        push @marcauthors, {
1802
            MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop,
1803
            authoritylink => $subfield9,
1804
            unimarc3 => $unimarc3
1805
        };
1806
    }
1807
    return \@marcauthors;
1808
}
1809
1810
=head2 GetMarcUrls
1710
=head2 GetMarcUrls
1811
1711
1812
  $marcurls = GetMarcUrls($record,$marcflavour);
1712
  $marcurls = GetMarcUrls($record,$marcflavour);
(-)a/Koha/Biblio.pm (+96 lines)
Lines 797-802 sub cover_images { Link Here
797
    return Koha::CoverImages->_new_from_dbic($cover_images_rs);
797
    return Koha::CoverImages->_new_from_dbic($cover_images_rs);
798
}
798
}
799
799
800
=head3 get_authors_from_MARC
801
802
    my $authors = $biblio->get_authors_from_MARC;
803
804
Get all authors from the MARC record and returns them in an array.
805
The authors are stored in different fields depending on MARC flavour
806
807
=cut
808
809
sub get_authors_from_MARC {
810
    my ( $self, $params ) = @_;
811
812
    my ( $mintag, $maxtag, $fields_filter );
813
    my $marcflavour = C4::Context->preference('marcflavour');
814
815
    # tagslib useful only for UNIMARC author responsibilities
816
    my $tagslib;
817
    if ( $marcflavour eq "UNIMARC" ) {
818
        # FIXME : we don't have the framework available, we take the default framework. May be buggy on some setups, will be usually correct.
819
        $tagslib = C4::Biblio::GetMarcStructure( 1, '', { unsafe => 1 });
820
        $mintag = "700";
821
        $maxtag = "712";
822
        $fields_filter = '7..';
823
    } else { # marc21/normarc
824
        $mintag = "700";
825
        $maxtag = "720";
826
        $fields_filter = '7..';
827
    }
828
829
    my @marcauthors;
830
    my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
831
832
    foreach my $field ( $self->metadata->record->field($fields_filter) ) {
833
        next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
834
        my @subfields_loop;
835
        my @link_loop;
836
        my @subfields  = $field->subfields();
837
        my $count_auth = 0;
838
839
        # if there is an authority link, build the link with Koha-Auth-Number: subfield9
840
        my $subfield9 = $field->subfield('9');
841
        if ($subfield9) {
842
            my $linkvalue = $subfield9;
843
            $linkvalue =~ s/(\(|\))//g;
844
            @link_loop = ( { 'limit' => 'an', 'link' => $linkvalue } );
845
        }
846
847
        # other subfields
848
        my $unimarc3;
849
        for my $authors_subfield (@subfields) {
850
            next if ( $authors_subfield->[0] eq '9' );
851
852
            # unimarc3 contains the $3 of the author for UNIMARC.
853
            # For french academic libraries, it's the "ppn", and it's required for idref webservice
854
            $unimarc3 = $authors_subfield->[1] if $marcflavour eq 'UNIMARC' and $authors_subfield->[0] =~ /3/;
855
856
            # don't load unimarc subfields 3, 5
857
            next if ( $marcflavour eq 'UNIMARC' and ( $authors_subfield->[0] =~ /3|5/ ) );
858
859
            my $code = $authors_subfield->[0];
860
            my $value        = $authors_subfield->[1];
861
            my $linkvalue    = $value;
862
            $linkvalue =~ s/(\(|\))//g;
863
            # UNIMARC author responsibility
864
            if ( $marcflavour eq 'UNIMARC' and $code eq '4' ) {
865
                $value = C4::Biblio::GetAuthorisedValueDesc( $field->tag(), $code, $value, '', $tagslib );
866
                $linkvalue = "($value)";
867
            }
868
            # if no authority link, build a search query
869
            unless ($subfield9) {
870
                push @link_loop, {
871
                    limit    => 'au',
872
                    'link'   => $linkvalue,
873
                    operator => (scalar @link_loop) ? ' and ' : undef
874
                };
875
            }
876
            my @this_link_loop = @link_loop;
877
            # do not display $0
878
            unless ( $code eq '0') {
879
                push @subfields_loop, {
880
                    tag       => $field->tag(),
881
                    code      => $code,
882
                    value     => $value,
883
                    link_loop => \@this_link_loop,
884
                    separator => (scalar @subfields_loop) ? $AuthoritySeparator : ''
885
                };
886
            }
887
        }
888
        push @marcauthors, {
889
            MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop,
890
            authoritylink => $subfield9,
891
            unimarc3 => $unimarc3
892
        };
893
    }
894
    return \@marcauthors;
895
}
800
896
801
=head3 to_api
897
=head3 to_api
802
898
(-)a/basket/basket.pl (-1 / +2 lines)
Lines 61-69 foreach my $biblionumber ( @bibs ) { Link Here
61
61
62
    my $dat              = &GetBiblioData($biblionumber);
62
    my $dat              = &GetBiblioData($biblionumber);
63
    next unless $dat;
63
    next unless $dat;
64
    my $biblio           = Koha::Biblios->find( $biblionumber );
64
    my $record           = &GetMarcBiblio({ biblionumber => $biblionumber });
65
    my $record           = &GetMarcBiblio({ biblionumber => $biblionumber });
65
    my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
66
    my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
66
    my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
67
    my $marcauthorsarray = $biblio->get_authors_from_MARC;
67
    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
68
    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
68
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
69
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
69
    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
70
    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 / +2 lines)
Lines 70-75 foreach my $biblionumber ( @bibs ) { Link Here
70
70
71
    my $dat              = &GetBiblioData($biblionumber);
71
    my $dat              = &GetBiblioData($biblionumber);
72
    next unless $dat;
72
    next unless $dat;
73
    my $biblio           = Koha::Biblios->find( $biblionumber );
73
74
74
    # No filtering on the item records needed for the record itself
75
    # No filtering on the item records needed for the record itself
75
    # since the only reason item information is grabbed is because of branchcodes.
76
    # since the only reason item information is grabbed is because of branchcodes.
Lines 82-88 foreach my $biblionumber ( @bibs ) { Link Here
82
    $record_processor->process($record);
83
    $record_processor->process($record);
83
    next unless $record;
84
    next unless $record;
84
    my $marcnotesarray   = GetMarcNotes( $record, $marcflavour, 1 );
85
    my $marcnotesarray   = GetMarcNotes( $record, $marcflavour, 1 );
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
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
88
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
88
    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
89
    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 => 41;
24
plan tests => 39;
25
25
26
use_ok('C4::Biblio');
26
use_ok('C4::Biblio');
27
27
Lines 99-110 warning_is { $ret = GetMarcSubjects() } Link Here
99
99
100
ok( !defined $ret, 'GetMarcSubjects returns undef if not passed rec');
100
ok( !defined $ret, 'GetMarcSubjects returns undef if not passed rec');
101
101
102
warning_is { $ret = GetMarcAuthors() }
103
           { carped => 'GetMarcAuthors called on undefined record'},
104
           "GetMarcAuthors returns carped warning on undef record";
105
106
ok( !defined $ret, 'GetMarcAuthors returns undef if not passed rec');
107
108
warning_is { $ret = GetMarcUrls() }
102
warning_is { $ret = GetMarcUrls() }
109
           { carped => 'GetMarcUrls called on undefined record'},
103
           { carped => 'GetMarcUrls called on undefined record'},
110
           "GetMarcUrls returns carped warning on undef record";
104
           "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 => 12;
20
use Test::More tests => 13;
21
21
22
use C4::Biblio;
22
use C4::Biblio;
23
use Koha::Database;
23
use Koha::Database;
Lines 551-553 subtest 'subscriptions() tests' => sub { Link Here
551
551
552
    $schema->storage->txn_rollback;
552
    $schema->storage->txn_rollback;
553
};
553
};
554
555
subtest 'get_authors_from_MARC() tests' => sub {
556
557
    plan tests => 1;
558
559
    $schema->storage->txn_begin;
560
561
    my $biblio = $builder->build_sample_biblio;
562
    my $record = $biblio->metadata->record;
563
564
    # add author information
565
    my $field = MARC::Field->new('700','1','','a' => 'Jefferson, Thomas');
566
    $record->append_fields($field);
567
    $field = MARC::Field->new('700','1','','d' => '1743-1826');
568
    $record->append_fields($field);
569
    $field = MARC::Field->new('700','1','','e' => 'former owner.');
570
    $record->append_fields($field);
571
    $field = MARC::Field->new('700','1','','5' => 'MH');
572
    $record->append_fields($field);
573
574
    # get record
575
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
576
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
577
578
    is( 4, @{$biblio->get_authors_from_MARC}, 'get_authors_from_MARC retrieves correct number of author subfields' );
579
580
    $schema->storage->txn_rollback;
581
};
(-)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