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 1694-1798 sub GetMarcSubjects { Link Here
1694
    return \@marcsubjects;
1693
    return \@marcsubjects;
1695
}    #end getMARCsubjects
1694
}    #end getMARCsubjects
1696
1695
1697
=head2 GetMarcAuthors
1698
1699
  authors = GetMarcAuthors($record,$marcflavour);
1700
1701
Get all authors from the MARC record and returns them in an array.
1702
The authors are stored in different fields depending on MARC flavour
1703
1704
=cut
1705
1706
sub GetMarcAuthors {
1707
    my ( $record, $marcflavour ) = @_;
1708
    if (!$record) {
1709
        carp 'GetMarcAuthors called on undefined record';
1710
        return;
1711
    }
1712
    my ( $mintag, $maxtag, $fields_filter );
1713
1714
    # tagslib useful only for UNIMARC author responsibilities
1715
    my $tagslib;
1716
    if ( $marcflavour eq "UNIMARC" ) {
1717
        # FIXME : we don't have the framework available, we take the default framework. May be buggy on some setups, will be usually correct.
1718
        $tagslib = GetMarcStructure( 1, '', { unsafe => 1 });
1719
        $mintag = "700";
1720
        $maxtag = "712";
1721
        $fields_filter = '7..';
1722
    } else { # marc21/normarc
1723
        $mintag = "700";
1724
        $maxtag = "720";
1725
        $fields_filter = '7..';
1726
    }
1727
1728
    my @marcauthors;
1729
    my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
1730
1731
    foreach my $field ( $record->field($fields_filter) ) {
1732
        next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
1733
        my @subfields_loop;
1734
        my @link_loop;
1735
        my @subfields  = $field->subfields();
1736
        my $count_auth = 0;
1737
1738
        # if there is an authority link, build the link with Koha-Auth-Number: subfield9
1739
        my $subfield9 = $field->subfield('9');
1740
        if ($subfield9) {
1741
            my $linkvalue = $subfield9;
1742
            $linkvalue =~ s/(\(|\))//g;
1743
            @link_loop = ( { 'limit' => 'an', 'link' => $linkvalue } );
1744
        }
1745
1746
        # other subfields
1747
        my $unimarc3;
1748
        for my $authors_subfield (@subfields) {
1749
            next if ( $authors_subfield->[0] eq '9' );
1750
1751
            # unimarc3 contains the $3 of the author for UNIMARC.
1752
            # For french academic libraries, it's the "ppn", and it's required for idref webservice
1753
            $unimarc3 = $authors_subfield->[1] if $marcflavour eq 'UNIMARC' and $authors_subfield->[0] =~ /3/;
1754
1755
            # don't load unimarc subfields 3, 5
1756
            next if ( $marcflavour eq 'UNIMARC' and ( $authors_subfield->[0] =~ /3|5/ ) );
1757
1758
            my $code = $authors_subfield->[0];
1759
            my $value        = $authors_subfield->[1];
1760
            my $linkvalue    = $value;
1761
            $linkvalue =~ s/(\(|\))//g;
1762
            # UNIMARC author responsibility
1763
            if ( $marcflavour eq 'UNIMARC' and $code eq '4' ) {
1764
                $value = GetAuthorisedValueDesc( $field->tag(), $code, $value, '', $tagslib );
1765
                $linkvalue = "($value)";
1766
            }
1767
            # if no authority link, build a search query
1768
            unless ($subfield9) {
1769
                push @link_loop, {
1770
                    limit    => 'au',
1771
                    'link'   => $linkvalue,
1772
                    operator => (scalar @link_loop) ? ' and ' : undef
1773
                };
1774
            }
1775
            my @this_link_loop = @link_loop;
1776
            # do not display $0
1777
            unless ( $code eq '0') {
1778
                push @subfields_loop, {
1779
                    tag       => $field->tag(),
1780
                    code      => $code,
1781
                    value     => $value,
1782
                    link_loop => \@this_link_loop,
1783
                    separator => (scalar @subfields_loop) ? $AuthoritySeparator : ''
1784
                };
1785
            }
1786
        }
1787
        push @marcauthors, {
1788
            MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop,
1789
            authoritylink => $subfield9,
1790
            unimarc3 => $unimarc3
1791
        };
1792
    }
1793
    return \@marcauthors;
1794
}
1795
1796
=head2 GetMarcUrls
1696
=head2 GetMarcUrls
1797
1697
1798
  $marcurls = GetMarcUrls($record,$marcflavour);
1698
  $marcurls = GetMarcUrls($record,$marcflavour);
(-)a/Koha/Biblio.pm (+96 lines)
Lines 793-798 sub cover_images { Link Here
793
    return Koha::CoverImages->_new_from_dbic($cover_images_rs);
793
    return Koha::CoverImages->_new_from_dbic($cover_images_rs);
794
}
794
}
795
795
796
=head3 get_marc_authors
797
798
    my $authors = $biblio->get_marc_authors({ marcflavour => $marcflavour });
799
800
Get all authors from the MARC record and returns them in an array.
801
The authors are stored in different fields depending on MARC flavour
802
803
=cut
804
805
sub get_marc_authors {
806
    my ( $self, $params ) = @_;
807
808
    my ( $mintag, $maxtag, $fields_filter );
809
    my $marcflavour = $params->{marcflavour};
810
811
    # tagslib useful only for UNIMARC author responsibilities
812
    my $tagslib;
813
    if ( $marcflavour eq "UNIMARC" ) {
814
        # FIXME : we don't have the framework available, we take the default framework. May be buggy on some setups, will be usually correct.
815
        $tagslib = C4::Biblio::GetMarcStructure( 1, '', { unsafe => 1 });
816
        $mintag = "700";
817
        $maxtag = "712";
818
        $fields_filter = '7..';
819
    } else { # marc21/normarc
820
        $mintag = "700";
821
        $maxtag = "720";
822
        $fields_filter = '7..';
823
    }
824
825
    my @marcauthors;
826
    my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
827
828
    foreach my $field ( $self->metadata->record->field($fields_filter) ) {
829
        next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
830
        my @subfields_loop;
831
        my @link_loop;
832
        my @subfields  = $field->subfields();
833
        my $count_auth = 0;
834
835
        # if there is an authority link, build the link with Koha-Auth-Number: subfield9
836
        my $subfield9 = $field->subfield('9');
837
        if ($subfield9) {
838
            my $linkvalue = $subfield9;
839
            $linkvalue =~ s/(\(|\))//g;
840
            @link_loop = ( { 'limit' => 'an', 'link' => $linkvalue } );
841
        }
842
843
        # other subfields
844
        my $unimarc3;
845
        for my $authors_subfield (@subfields) {
846
            next if ( $authors_subfield->[0] eq '9' );
847
848
            # unimarc3 contains the $3 of the author for UNIMARC.
849
            # For french academic libraries, it's the "ppn", and it's required for idref webservice
850
            $unimarc3 = $authors_subfield->[1] if $marcflavour eq 'UNIMARC' and $authors_subfield->[0] =~ /3/;
851
852
            # don't load unimarc subfields 3, 5
853
            next if ( $marcflavour eq 'UNIMARC' and ( $authors_subfield->[0] =~ /3|5/ ) );
854
855
            my $code = $authors_subfield->[0];
856
            my $value        = $authors_subfield->[1];
857
            my $linkvalue    = $value;
858
            $linkvalue =~ s/(\(|\))//g;
859
            # UNIMARC author responsibility
860
            if ( $marcflavour eq 'UNIMARC' and $code eq '4' ) {
861
                $value = C4::Biblio::GetAuthorisedValueDesc( $field->tag(), $code, $value, '', $tagslib );
862
                $linkvalue = "($value)";
863
            }
864
            # if no authority link, build a search query
865
            unless ($subfield9) {
866
                push @link_loop, {
867
                    limit    => 'au',
868
                    'link'   => $linkvalue,
869
                    operator => (scalar @link_loop) ? ' and ' : undef
870
                };
871
            }
872
            my @this_link_loop = @link_loop;
873
            # do not display $0
874
            unless ( $code eq '0') {
875
                push @subfields_loop, {
876
                    tag       => $field->tag(),
877
                    code      => $code,
878
                    value     => $value,
879
                    link_loop => \@this_link_loop,
880
                    separator => (scalar @subfields_loop) ? $AuthoritySeparator : ''
881
                };
882
            }
883
        }
884
        push @marcauthors, {
885
            MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop,
886
            authoritylink => $subfield9,
887
            unimarc3 => $unimarc3
888
        };
889
    }
890
    return \@marcauthors;
891
}
796
892
797
=head3 to_api
893
=head3 to_api
798
894
(-)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_marc_authors({ marcflavour => $marcflavour });
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_marc_authors({ marcflavour => $marcflavour });
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_marc_authors({ marcflavour => $marcflavour });
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_marc_authors({ marcflavour => $marcflavour });
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_marc_authors({ marcflavour => $marcflavour });
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_marc_authors({ marcflavour => $marcflavour });
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_marc_authors() 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_marc_authors}, 'get_marc_authors 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_marc_authors({ marcflavour => $marcflavour });
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