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

(-)a/C4/Biblio.pm (-90 lines)
Lines 33-39 BEGIN { Link Here
33
        GetMarcControlnumber
33
        GetMarcControlnumber
34
        GetMarcISBN
34
        GetMarcISBN
35
        GetMarcISSN
35
        GetMarcISSN
36
        GetMarcSubjects
37
        GetMarcSeries
36
        GetMarcSeries
38
        GetMarcUrls
37
        GetMarcUrls
39
        GetUsedMarcStructure
38
        GetUsedMarcStructure
Lines 1499-1593 sub GetMarcISSN { Link Here
1499
    return \@marcissns;
1498
    return \@marcissns;
1500
}    # end GetMarcISSN
1499
}    # end GetMarcISSN
1501
1500
1502
=head2 GetMarcSubjects
1503
1504
  $marcsubjcts = GetMarcSubjects($record,$marcflavour);
1505
1506
Get all subjects from the MARC record and returns them in an array.
1507
The subjects are stored in different fields depending on MARC flavour
1508
1509
=cut
1510
1511
sub GetMarcSubjects {
1512
    my ( $record, $marcflavour ) = @_;
1513
    if (!$record) {
1514
        carp 'GetMarcSubjects called on undefined record';
1515
        return;
1516
    }
1517
    my ( $mintag, $maxtag, $fields_filter );
1518
    if ( $marcflavour eq "UNIMARC" ) {
1519
        $mintag = "600";
1520
        $maxtag = "611";
1521
        $fields_filter = '6..';
1522
    } else { # marc21
1523
        $mintag = "600";
1524
        $maxtag = "699";
1525
        $fields_filter = '6..';
1526
    }
1527
1528
    my @marcsubjects;
1529
1530
    my $subject_limit = C4::Context->preference("TraceCompleteSubfields") ? 'su,complete-subfield' : 'su';
1531
    my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
1532
1533
    foreach my $field ( $record->field($fields_filter) ) {
1534
        next unless ($field->tag() >= $mintag && $field->tag() <= $maxtag);
1535
        my @subfields_loop;
1536
        my @subfields = $field->subfields();
1537
        my @link_loop;
1538
1539
        # if there is an authority link, build the links with an= subfield9
1540
        my $subfield9 = $field->subfield('9');
1541
        my $authoritylink;
1542
        if ($subfield9) {
1543
            my $linkvalue = $subfield9;
1544
            $linkvalue =~ s/(\(|\))//g;
1545
            @link_loop = ( { limit => 'an', 'link' => $linkvalue } );
1546
            $authoritylink = $linkvalue
1547
        }
1548
1549
        # other subfields
1550
        for my $subject_subfield (@subfields) {
1551
            next if ( $subject_subfield->[0] eq '9' );
1552
1553
            # don't load unimarc subfields 3,4,5
1554
            next if ( ( $marcflavour eq "UNIMARC" ) and ( $subject_subfield->[0] =~ /2|3|4|5/ ) );
1555
            # don't load MARC21 subfields 2 (FIXME: any more subfields??)
1556
            next if ( ( $marcflavour eq "MARC21" ) and ( $subject_subfield->[0] =~ /2/ ) );
1557
1558
            my $code      = $subject_subfield->[0];
1559
            my $value     = $subject_subfield->[1];
1560
            my $linkvalue = $value;
1561
            $linkvalue =~ s/(\(|\))//g;
1562
            # if no authority link, build a search query
1563
            unless ($subfield9) {
1564
                push @link_loop, {
1565
                    limit    => $subject_limit,
1566
                    'link'   => $linkvalue,
1567
                    operator => (scalar @link_loop) ? ' AND ' : undef
1568
                };
1569
            }
1570
            my @this_link_loop = @link_loop;
1571
            # do not display $0
1572
            unless ( $code eq '0' ) {
1573
                push @subfields_loop, {
1574
                    code      => $code,
1575
                    value     => $value,
1576
                    link_loop => \@this_link_loop,
1577
                    separator => (scalar @subfields_loop) ? $AuthoritySeparator : ''
1578
                };
1579
            }
1580
        }
1581
1582
        push @marcsubjects, {
1583
            MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop,
1584
            authoritylink => $authoritylink,
1585
        } if $authoritylink || @subfields_loop;
1586
1587
    }
1588
    return \@marcsubjects;
1589
}    #end getMARCsubjects
1590
1591
=head2 GetMarcUrls
1501
=head2 GetMarcUrls
1592
1502
1593
  $marcurls = GetMarcUrls($record,$marcflavour);
1503
  $marcurls = GetMarcUrls($record,$marcflavour);
(-)a/Koha/Biblio.pm (+87 lines)
Lines 1162-1167 sub get_marc_authors { Link Here
1162
    return [@first_authors, @other_authors];
1162
    return [@first_authors, @other_authors];
1163
}
1163
}
1164
1164
1165
=head3 get_marc_subjects
1166
1167
  $marcsubjcts = $biblio->get_marc_subjects({ marcflavour => $marcflavour });
1168
1169
Get all subjects from the MARC record and returns them in an array.
1170
The subjects are stored in different fields depending on MARC flavour
1171
1172
=cut
1173
1174
sub get_marc_subjects {
1175
    my ( $self, $params ) = @_;
1176
    my ( $mintag, $maxtag, $fields_filter );
1177
1178
    my $marcflavour = $params->{marcflavour};
1179
    if ( $marcflavour eq "UNIMARC" ) {
1180
        $mintag = "600";
1181
        $maxtag = "611";
1182
        $fields_filter = '6..';
1183
    } else { # marc21/normarc
1184
        $mintag = "600";
1185
        $maxtag = "699";
1186
        $fields_filter = '6..';
1187
    }
1188
1189
    my @marcsubjects;
1190
1191
    my $subject_limit = C4::Context->preference("TraceCompleteSubfields") ? 'su,complete-subfield' : 'su';
1192
    my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator');
1193
1194
    foreach my $field ( $self->metadata->record->field($fields_filter) ) {
1195
        next unless ($field->tag() >= $mintag && $field->tag() <= $maxtag);
1196
        my @subfields_loop;
1197
        my @subfields = $field->subfields();
1198
        my @link_loop;
1199
1200
        # if there is an authority link, build the links with an= subfield9
1201
        my $subfield9 = $field->subfield('9');
1202
        my $authoritylink;
1203
        if ($subfield9) {
1204
            my $linkvalue = $subfield9;
1205
            $linkvalue =~ s/(\(|\))//g;
1206
            @link_loop = ( { limit => 'an', 'link' => $linkvalue } );
1207
            $authoritylink = $linkvalue
1208
        }
1209
1210
        # other subfields
1211
        for my $subject_subfield (@subfields) {
1212
            next if ( $subject_subfield->[0] eq '9' );
1213
1214
            # don't load unimarc subfields 3,4,5
1215
            next if ( ( $marcflavour eq "UNIMARC" ) and ( $subject_subfield->[0] =~ /2|3|4|5/ ) );
1216
            # don't load MARC21 subfields 2 (FIXME: any more subfields??)
1217
            next if ( ( $marcflavour eq "MARC21" ) and ( $subject_subfield->[0] =~ /2/ ) );
1218
1219
            my $code      = $subject_subfield->[0];
1220
            my $value     = $subject_subfield->[1];
1221
            my $linkvalue = $value;
1222
            $linkvalue =~ s/(\(|\))//g;
1223
            # if no authority link, build a search query
1224
            unless ($subfield9) {
1225
                push @link_loop, {
1226
                    limit    => $subject_limit,
1227
                    'link'   => $linkvalue,
1228
                    operator => (scalar @link_loop) ? ' and ' : undef
1229
                };
1230
            }
1231
            my @this_link_loop = @link_loop;
1232
            # do not display $0
1233
            unless ( $code eq '0') {
1234
                push @subfields_loop, {
1235
                    tag       => $field->tag(),
1236
                    code      => $code,
1237
                    value     => $value,
1238
                    link_loop => \@this_link_loop,
1239
                    separator => (scalar @subfields_loop) ? $AuthoritySeparator : ''
1240
                };
1241
            }
1242
        }
1243
1244
        push @marcsubjects, {
1245
            MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop,
1246
            authoritylink => $authoritylink,
1247
        } if $authoritylink || @subfields_loop;
1248
1249
    }
1250
    return \@marcsubjects;
1251
}
1165
1252
1166
=head3 to_api
1253
=head3 to_api
1167
1254
(-)a/basket/basket.pl (-1 / +1 lines)
Lines 68-74 foreach my $biblionumber ( @bibs ) { Link Here
68
    my $record           = $biblio->metadata->record;
68
    my $record           = $biblio->metadata->record;
69
    my $marcnotesarray   = $biblio->get_marc_notes;
69
    my $marcnotesarray   = $biblio->get_marc_notes;
70
    my $marcauthorsarray = $biblio->get_marc_contributors;
70
    my $marcauthorsarray = $biblio->get_marc_contributors;
71
    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
71
    my $marcsubjctsarray = $biblio->get_marc_subjects({ marcflavour => $marcflavour });
72
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
72
    my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
73
    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
73
    my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
74
74
(-)a/basket/sendbasket.pl (-1 / +1 lines)
Lines 73-79 if ( $email_add ) { Link Here
73
        my $dat              = $biblio->unblessed;
73
        my $dat              = $biblio->unblessed;
74
        my $record           = $biblio->metadata->record({ embed_items => 1 });
74
        my $record           = $biblio->metadata->record({ embed_items => 1 });
75
        my $marcauthorsarray = $biblio->get_marc_contributors;
75
        my $marcauthorsarray = $biblio->get_marc_contributors;
76
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
76
        my $marcsubjctsarray = $biblio->get_marc_subjects({ marcflavour => $marcflavour });
77
77
78
        my $hasauthors = 0;
78
        my $hasauthors = 0;
79
        if($dat->{'author'} || @$marcauthorsarray) {
79
        if($dat->{'author'} || @$marcauthorsarray) {
(-)a/opac/opac-basket.pl (-1 / +1 lines)
Lines 85-91 foreach my $biblionumber ( @bibs ) { Link Here
85
    next unless $record;
85
    next unless $record;
86
    my $marcnotesarray   = $biblio->get_marc_notes({ opac => 1 });
86
    my $marcnotesarray   = $biblio->get_marc_notes({ opac => 1 });
87
    my $marcauthorsarray = $biblio->get_marc_contributors;
87
    my $marcauthorsarray = $biblio->get_marc_contributors;
88
    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
88
    my $marcsubjctsarray = $biblio->get_marc_subjects({ marcflavour => $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);
91
91
(-)a/opac/opac-detail.pl (+2 lines)
Lines 777-782 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) { Link Here
777
}
777
}
778
778
779
my $marcnotesarray = $biblio->get_marc_notes({ opac => 1, record => $record });
779
my $marcnotesarray = $biblio->get_marc_notes({ opac => 1, record => $record });
780
my $marcsubjctsarray = $biblio->get_marc_subjects({ marcflavour => $marcflavour });
780
781
781
if( C4::Context->preference('ArticleRequests') ) {
782
if( C4::Context->preference('ArticleRequests') ) {
782
    my $patron = $borrowernumber ? Koha::Patrons->find($borrowernumber) : undef;
783
    my $patron = $borrowernumber ? Koha::Patrons->find($borrowernumber) : undef;
Lines 792-797 if( C4::Context->preference('ArticleRequests') ) { Link Here
792
my $norequests = ! $biblio->items->filter_by_for_hold->count;
793
my $norequests = ! $biblio->items->filter_by_for_hold->count;
793
    $template->param(
794
    $template->param(
794
                     MARCNOTES               => $marcnotesarray,
795
                     MARCNOTES               => $marcnotesarray,
796
                     MARCSUBJCTS             => $marcsubjctsarray,
795
                     norequests              => $norequests,
797
                     norequests              => $norequests,
796
                     itemdata_ccode          => $itemfields{ccode},
798
                     itemdata_ccode          => $itemfields{ccode},
797
                     itemdata_materials      => $itemfields{materials},
799
                     itemdata_materials      => $itemfields{materials},
(-)a/opac/opac-sendbasket.pl (-1 / +1 lines)
Lines 83-89 if ( $email_add ) { Link Here
83
            }
83
            }
84
        );
84
        );
85
        my $marcauthorsarray = $biblio->get_marc_contributors;
85
        my $marcauthorsarray = $biblio->get_marc_contributors;
86
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
86
        my $marcsubjctsarray = $biblio->get_marc_subjects({ marcflavour => $marcflavour });
87
87
88
        my $items = $biblio->items->search_ordered->filter_by_visible_in_opac({ patron => $patron });
88
        my $items = $biblio->items->search_ordered->filter_by_visible_in_opac({ patron => $patron });
89
89
(-)a/opac/opac-sendshelf.pl (-1 / +2 lines)
Lines 89-98 if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { Link Here
89
            }
89
            }
90
        );
90
        );
91
        next unless $record;
91
        next unless $record;
92
        my $biblio           = Koha::Biblios->find( $biblionumber );
92
        my $fw               = GetFrameworkCode($biblionumber);
93
        my $fw               = GetFrameworkCode($biblionumber);
93
94
94
        my $marcauthorsarray = $biblio->get_marc_contributors;
95
        my $marcauthorsarray = $biblio->get_marc_contributors;
95
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
96
        my $marcsubjctsarray = $biblio->get_marc_subjects({ marcflavour => $marcflavour });
96
97
97
        my $items = $biblio->items->search_ordered->filter_by_visible_in_opac({ patron => $patron });
98
        my $items = $biblio->items->search_ordered->filter_by_visible_in_opac({ patron => $patron });
98
99
(-)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 => 34;
24
plan tests => 32;
25
25
26
26
27
use_ok('C4::Biblio', qw( AddBiblio ModBiblio BiblioAutoLink LinkBibHeadingsToAuthorities GetMarcPrice GetMarcQuantity GetMarcControlnumber GetMarcISBN GetMarcISSN GetMarcSubjects GetMarcUrls GetMarcSeries TransformMarcToKoha ModBiblioMarc RemoveAllNsb UpdateTotalIssues ));
27
use_ok('C4::Biblio', qw( AddBiblio ModBiblio BiblioAutoLink LinkBibHeadingsToAuthorities GetMarcPrice GetMarcQuantity GetMarcControlnumber GetMarcISBN GetMarcISSN GetMarcSubjects GetMarcUrls GetMarcSeries TransformMarcToKoha ModBiblioMarc RemoveAllNsb UpdateTotalIssues ));
Lines 88-99 warning_is { $ret = GetMarcISSN() } Link Here
88
88
89
ok( !defined $ret, 'GetMarcISSN returns undef if not passed rec');
89
ok( !defined $ret, 'GetMarcISSN returns undef if not passed rec');
90
90
91
warning_is { $ret = GetMarcSubjects() }
92
           { carped => 'GetMarcSubjects called on undefined record'},
93
           "GetMarcSubjects returns carped warning on undef record";
94
95
ok( !defined $ret, 'GetMarcSubjects returns undef if not passed rec');
96
97
warning_is { $ret = GetMarcUrls() }
91
warning_is { $ret = GetMarcUrls() }
98
           { carped => 'GetMarcUrls called on undefined record'},
92
           { carped => 'GetMarcUrls called on undefined record'},
99
           "GetMarcUrls returns carped warning on undef record";
93
           "GetMarcUrls returns carped warning on undef record";
(-)a/t/db_dependent/Koha/Biblio.t (-1 / +23 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 22; # +1
20
use Test::More tests => 23; # +1
21
use Test::Warn;
21
use Test::Warn;
22
22
23
use C4::Biblio qw( AddBiblio ModBiblio ModBiblioMarc );
23
use C4::Biblio qw( AddBiblio ModBiblio ModBiblioMarc );
Lines 1053-1058 subtest 'item_groups() tests' => sub { Link Here
1053
    $schema->storage->txn_rollback;
1053
    $schema->storage->txn_rollback;
1054
};
1054
};
1055
1055
1056
subtest 'get_marc_subjects() tests' => sub {
1057
1058
    plan tests => 1;
1059
1060
    $schema->storage->txn_begin;
1061
1062
    my $biblio = $builder->build_sample_biblio;
1063
    my $record = $biblio->metadata->record;
1064
1065
    # add author information
1066
    my $field = MARC::Field->new('600','1','0','a' => 'Nixon, Richard M.');
1067
    $record->append_fields($field);
1068
    $field = MARC::Field->new('600','1','0','q' => '(Richard Milhouse),');
1069
    $record->append_fields($field);
1070
    $field = MARC::Field->new('600','1','0','d' => '1913-');
1071
    $record->append_fields($field);
1072
    $field = MARC::Field->new('600','1','0','x' => 'Psychology.');
1073
    is( 4, @{$biblio->get_marc_subjects({ marcflavour => 'MARC21' })}, 'get_marc_subjects retrieves correct number of subject subfields' );
1074
1075
    $schema->storage->txn_rollback;
1076
};
1077
1056
sub component_record1 {
1078
sub component_record1 {
1057
    my $marc = MARC::Record->new;
1079
    my $marc = MARC::Record->new;
1058
    $marc->append_fields(
1080
    $marc->append_fields(
(-)a/virtualshelves/sendshelf.pl (-2 / +1 lines)
Lines 80-86 if ($to_address) { Link Here
80
        my $dat              = $biblio->unblessed;
80
        my $dat              = $biblio->unblessed;
81
        my $record           = $biblio->metadata->record({ embed_items => 1 });
81
        my $record           = $biblio->metadata->record({ embed_items => 1 });
82
        my $marcauthorsarray = $biblio->get_marc_contributors;
82
        my $marcauthorsarray = $biblio->get_marc_contributors;
83
        my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
83
        my $marcsubjctsarray = $biblio->get_marc_subjects({ marcflavour => $marcflavour });
84
84
85
        my $items = $biblio->items->search_ordered;
85
        my $items = $biblio->items->search_ordered;
86
86
87
- 

Return to bug 27269