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

(-)a/C4/Biblio.pm (-90 lines)
Lines 35-41 BEGIN { Link Here
35
        GetMarcNotes
35
        GetMarcNotes
36
        GetMarcISBN
36
        GetMarcISBN
37
        GetMarcISSN
37
        GetMarcISSN
38
        GetMarcSubjects
39
        GetMarcAuthors
38
        GetMarcAuthors
40
        GetMarcSeries
39
        GetMarcSeries
41
        GetMarcUrls
40
        GetMarcUrls
Lines 1605-1699 sub GetMarcNotes { Link Here
1605
    return \@marcnotes;
1604
    return \@marcnotes;
1606
}
1605
}
1607
1606
1608
=head2 GetMarcSubjects
1609
1610
  $marcsubjcts = GetMarcSubjects($record,$marcflavour);
1611
1612
Get all subjects from the MARC record and returns them in an array.
1613
The subjects are stored in different fields depending on MARC flavour
1614
1615
=cut
1616
1617
sub GetMarcSubjects {
1618
    my ( $record, $marcflavour ) = @_;
1619
    if (!$record) {
1620
        carp 'GetMarcSubjects called on undefined record';
1621
        return;
1622
    }
1623
    my ( $mintag, $maxtag, $fields_filter );
1624
    if ( $marcflavour eq "UNIMARC" ) {
1625
        $mintag = "600";
1626
        $maxtag = "611";
1627
        $fields_filter = '6..';
1628
    } else { # marc21/normarc
1629
        $mintag = "600";
1630
        $maxtag = "699";
1631
        $fields_filter = '6..';
1632
    }
1633
1634
    my @marcsubjects;
1635
1636
    my $subject_limit = C4::Context->preference("TraceCompleteSubfields") ? 'su,complete-subfield' : 'su';
1637
    my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
1638
1639
    foreach my $field ( $record->field($fields_filter) ) {
1640
        next unless ($field->tag() >= $mintag && $field->tag() <= $maxtag);
1641
        my @subfields_loop;
1642
        my @subfields = $field->subfields();
1643
        my @link_loop;
1644
1645
        # if there is an authority link, build the links with an= subfield9
1646
        my $subfield9 = $field->subfield('9');
1647
        my $authoritylink;
1648
        if ($subfield9) {
1649
            my $linkvalue = $subfield9;
1650
            $linkvalue =~ s/(\(|\))//g;
1651
            @link_loop = ( { limit => 'an', 'link' => $linkvalue } );
1652
            $authoritylink = $linkvalue
1653
        }
1654
1655
        # other subfields
1656
        for my $subject_subfield (@subfields) {
1657
            next if ( $subject_subfield->[0] eq '9' );
1658
1659
            # don't load unimarc subfields 3,4,5
1660
            next if ( ( $marcflavour eq "UNIMARC" ) and ( $subject_subfield->[0] =~ /2|3|4|5/ ) );
1661
            # don't load MARC21 subfields 2 (FIXME: any more subfields??)
1662
            next if ( ( $marcflavour eq "MARC21" ) and ( $subject_subfield->[0] =~ /2/ ) );
1663
1664
            my $code      = $subject_subfield->[0];
1665
            my $value     = $subject_subfield->[1];
1666
            my $linkvalue = $value;
1667
            $linkvalue =~ s/(\(|\))//g;
1668
            # if no authority link, build a search query
1669
            unless ($subfield9) {
1670
                push @link_loop, {
1671
                    limit    => $subject_limit,
1672
                    'link'   => $linkvalue,
1673
                    operator => (scalar @link_loop) ? ' and ' : undef
1674
                };
1675
            }
1676
            my @this_link_loop = @link_loop;
1677
            # do not display $0
1678
            unless ( $code eq '0' ) {
1679
                push @subfields_loop, {
1680
                    code      => $code,
1681
                    value     => $value,
1682
                    link_loop => \@this_link_loop,
1683
                    separator => (scalar @subfields_loop) ? $AuthoritySeparator : ''
1684
                };
1685
            }
1686
        }
1687
1688
        push @marcsubjects, {
1689
            MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop,
1690
            authoritylink => $authoritylink,
1691
        } if $authoritylink || @subfields_loop;
1692
1693
    }
1694
    return \@marcsubjects;
1695
}    #end getMARCsubjects
1696
1697
=head2 GetMarcAuthors
1607
=head2 GetMarcAuthors
1698
1608
1699
  authors = GetMarcAuthors($record,$marcflavour);
1609
  authors = GetMarcAuthors($record,$marcflavour);
(-)a/Koha/Biblio.pm (+86 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_subjects
797
798
  $marcsubjcts = $biblio->get_marc_subjects({ marcflavour => $marcflavour });
799
800
Get all subjects from the MARC record and returns them in an array.
801
The subjects are stored in different fields depending on MARC flavour
802
803
=cut
804
805
sub get_marc_subjects {
806
    my ( $self, $params ) = @_;
807
    my ( $mintag, $maxtag, $fields_filter );
808
809
    my $marcflavour = $params->{marcflavour};
810
    if ( $marcflavour eq "UNIMARC" ) {
811
        $mintag = "600";
812
        $maxtag = "611";
813
        $fields_filter = '6..';
814
    } else { # marc21/normarc
815
        $mintag = "600";
816
        $maxtag = "699";
817
        $fields_filter = '6..';
818
    }
819
820
    my @marcsubjects;
821
822
    my $subject_limit = C4::Context->preference("TraceCompleteSubfields") ? 'su,complete-subfield' : 'su';
823
    my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
824
825
    foreach my $field ( $self->metadata->record->field($fields_filter) ) {
826
        next unless ($field->tag() >= $mintag && $field->tag() <= $maxtag);
827
        my @subfields_loop;
828
        my @subfields = $field->subfields();
829
        my @link_loop;
830
831
        # if there is an authority link, build the links with an= subfield9
832
        my $subfield9 = $field->subfield('9');
833
        my $authoritylink;
834
        if ($subfield9) {
835
            my $linkvalue = $subfield9;
836
            $linkvalue =~ s/(\(|\))//g;
837
            @link_loop = ( { limit => 'an', 'link' => $linkvalue } );
838
            $authoritylink = $linkvalue
839
        }
840
841
        # other subfields
842
        for my $subject_subfield (@subfields) {
843
            next if ( $subject_subfield->[0] eq '9' );
844
845
            # don't load unimarc subfields 3,4,5
846
            next if ( ( $marcflavour eq "UNIMARC" ) and ( $subject_subfield->[0] =~ /2|3|4|5/ ) );
847
            # don't load MARC21 subfields 2 (FIXME: any more subfields??)
848
            next if ( ( $marcflavour eq "MARC21" ) and ( $subject_subfield->[0] =~ /2/ ) );
849
850
            my $code      = $subject_subfield->[0];
851
            my $value     = $subject_subfield->[1];
852
            my $linkvalue = $value;
853
            $linkvalue =~ s/(\(|\))//g;
854
            # if no authority link, build a search query
855
            unless ($subfield9) {
856
                push @link_loop, {
857
                    limit    => $subject_limit,
858
                    'link'   => $linkvalue,
859
                    operator => (scalar @link_loop) ? ' and ' : undef
860
                };
861
            }
862
            my @this_link_loop = @link_loop;
863
            # do not display $0
864
            unless ( $code eq '0' ) {
865
                push @subfields_loop, {
866
                    code      => $code,
867
                    value     => $value,
868
                    link_loop => \@this_link_loop,
869
                    separator => (scalar @subfields_loop) ? $AuthoritySeparator : ''
870
                };
871
            }
872
        }
873
874
        push @marcsubjects, {
875
            MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop,
876
            authoritylink => $authoritylink,
877
        } if $authoritylink || @subfields_loop;
878
879
    }
880
    return \@marcsubjects;
881
}
796
882
797
=head3 to_api
883
=head3 to_api
798
884
(-)a/basket/basket.pl (-1 / +2 lines)
Lines 61-70 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 = GetMarcAuthors( $record, $marcflavour );
67
    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
68
    my $marcsubjctsarray = $biblio->get_marc_subjects({ marcflavour => $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);
70
    my @items            = GetItemsInfo( $biblionumber );
71
    my @items            = GetItemsInfo( $biblionumber );
(-)a/basket/sendbasket.pl (-1 / +2 lines)
Lines 69-79 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 = GetMarcAuthors( $record, $marcflavour );
76
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
77
        my $marcsubjctsarray = $biblio->get_marc_subjects({ marcflavour => $marcflavour });
77
78
78
        my @items = GetItemsInfo( $biblionumber );
79
        my @items = GetItemsInfo( $biblionumber );
79
80
(-)a/opac/opac-basket.pl (-1 / +2 lines)
Lines 81-89 foreach my $biblionumber ( @bibs ) { Link Here
81
    });
81
    });
82
    $record_processor->process($record);
82
    $record_processor->process($record);
83
    next unless $record;
83
    next unless $record;
84
    my $biblio           = Koha::Biblios->find( $biblionumber );
84
    my $marcnotesarray   = GetMarcNotes( $record, $marcflavour, 1 );
85
    my $marcnotesarray   = GetMarcNotes( $record, $marcflavour, 1 );
85
    my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
86
    my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
86
    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
87
    my $marcsubjctsarray = $biblio->get_marc_subjects({ marcflavour => $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);
89
90
(-)a/opac/opac-detail.pl (-1 / +1 lines)
Lines 803-809 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) { Link Here
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 = GetMarcAuthors ($record,$marcflavour);
806
    my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
806
    my $marcsubjctsarray = $biblio->get_marc_subjects({ marcflavour => $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);
809
809
(-)a/opac/opac-sendbasket.pl (-1 / +2 lines)
Lines 77-89 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 = GetMarcAuthors( $record, $marcflavour );
86
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
87
        my $marcsubjctsarray = $biblio->get_marc_subjects({ marcflavour => $marcflavour });
87
88
88
        my @items = GetItemsInfo( $biblionumber );
89
        my @items = GetItemsInfo( $biblionumber );
89
90
(-)a/opac/opac-sendshelf.pl (-1 / +2 lines)
Lines 86-96 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 = GetMarcAuthors( $record, $marcflavour );
93
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
94
        my $marcsubjctsarray = $biblio->get_marc_subjects({ marcflavour => $marcflavour });
94
95
95
        my @items = GetItemsInfo( $biblionumber );
96
        my @items = GetItemsInfo( $biblionumber );
96
97
(-)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 93-104 warning_is { $ret = GetMarcNotes() } Link Here
93
93
94
ok( !defined $ret, 'GetMarcNotes returns undef if not passed rec');
94
ok( !defined $ret, 'GetMarcNotes returns undef if not passed rec');
95
95
96
warning_is { $ret = GetMarcSubjects() }
97
           { carped => 'GetMarcSubjects called on undefined record'},
98
           "GetMarcSubjects returns carped warning on undef record";
99
100
ok( !defined $ret, 'GetMarcSubjects returns undef if not passed rec');
101
102
warning_is { $ret = GetMarcAuthors() }
96
warning_is { $ret = GetMarcAuthors() }
103
           { carped => 'GetMarcAuthors called on undefined record'},
97
           { carped => 'GetMarcAuthors called on undefined record'},
104
           "GetMarcAuthors returns carped warning on undef record";
98
           "GetMarcAuthors 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_subjects() 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('600','1','0','a' => 'Nixon, Richard M.');
566
    $record->append_fields($field);
567
    $field = MARC::Field->new('600','1','0','q' => '(Richard Milhouse),');
568
    $record->append_fields($field);
569
    $field = MARC::Field->new('600','1','0','d' => '1913-');
570
    $record->append_fields($field);
571
    $field = MARC::Field->new('600','1','0','x' => 'Psychology.');
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_subjects({ marcflavour => 'MARC21' })}, 'get_marc_subjects retrieves correct number of subject subfields' );
579
580
    $schema->storage->txn_rollback;
581
};
(-)a/virtualshelves/sendshelf.pl (-2 / +2 lines)
Lines 67-78 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 = GetMarcAuthors( $record, $marcflavour );
75
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
76
        my $marcsubjctsarray = $biblio->get_marc_subjects({ marcflavour => $marcflavour });
76
77
77
        my @items = GetItemsInfo($biblionumber);
78
        my @items = GetItemsInfo($biblionumber);
78
79
79
- 

Return to bug 27269