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

(-)a/C4/Biblio.pm (-55 lines)
Lines 32-38 BEGIN { Link Here
32
        GetMarcBiblio
32
        GetMarcBiblio
33
        GetISBDView
33
        GetISBDView
34
        GetMarcControlnumber
34
        GetMarcControlnumber
35
        GetMarcNotes
36
        GetMarcISBN
35
        GetMarcISBN
37
        GetMarcISSN
36
        GetMarcISSN
38
        GetMarcSubjects
37
        GetMarcSubjects
Lines 1565-1624 sub GetMarcISSN { Link Here
1565
    return \@marcissns;
1564
    return \@marcissns;
1566
}    # end GetMarcISSN
1565
}    # end GetMarcISSN
1567
1566
1568
=head2 GetMarcNotes
1569
1570
    $marcnotesarray = GetMarcNotes( $record, $marcflavour );
1571
1572
    Get all notes from the MARC record and returns them in an array.
1573
    The notes are stored in different fields depending on MARC flavour.
1574
    MARC21 5XX $u subfields receive special attention as they are URIs.
1575
1576
=cut
1577
1578
sub GetMarcNotes {
1579
    my ( $record, $marcflavour, $opac ) = @_;
1580
    if (!$record) {
1581
        carp 'GetMarcNotes called on undefined record';
1582
        return;
1583
    }
1584
1585
    my $scope = $marcflavour eq "UNIMARC"? '3..': '5..';
1586
    my @marcnotes;
1587
1588
    #MARC21 specs indicate some notes should be private if first indicator 0
1589
    my %maybe_private = (
1590
        541 => 1,
1591
        542 => 1,
1592
        561 => 1,
1593
        583 => 1,
1594
        590 => 1
1595
    );
1596
1597
    my %hiddenlist = map { $_ => 1 }
1598
        split( /,/, C4::Context->preference('NotesToHide'));
1599
    foreach my $field ( $record->field($scope) ) {
1600
        my $tag = $field->tag();
1601
        next if $hiddenlist{ $tag };
1602
        next if $opac && $maybe_private{$tag} && !$field->indicator(1);
1603
        if( $marcflavour ne 'UNIMARC' && $field->subfield('u') ) {
1604
            # Field 5XX$u always contains URI
1605
            # Examples: 505u, 506u, 510u, 514u, 520u, 530u, 538u, 540u, 542u, 552u, 555u, 561u, 563u, 583u
1606
            # We first push the other subfields, then all $u's separately
1607
            # Leave further actions to the template (see e.g. opac-detail)
1608
            my $othersub =
1609
                join '', ( 'a' .. 't', 'v' .. 'z', '0' .. '9' ); # excl 'u'
1610
            push @marcnotes, { marcnote => $field->as_string($othersub) };
1611
            foreach my $sub ( $field->subfield('u') ) {
1612
                $sub =~ s/^\s+|\s+$//g; # trim
1613
                push @marcnotes, { marcnote => $sub };
1614
            }
1615
        } else {
1616
            push @marcnotes, { marcnote => $field->as_string() };
1617
        }
1618
    }
1619
    return \@marcnotes;
1620
}
1621
1622
=head2 GetMarcSubjects
1567
=head2 GetMarcSubjects
1623
1568
1624
  $marcsubjcts = GetMarcSubjects($record,$marcflavour);
1569
  $marcsubjcts = GetMarcSubjects($record,$marcflavour);
(-)a/Koha/Biblio.pm (+52 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_marc_notes
801
802
    $marcnotesarray = $biblio->get_marc_notes({ marcflavour => $marcflavour });
803
804
Get all notes from the MARC record and returns them in an array.
805
The notes are stored in different fields depending on MARC flavour.
806
MARC21 5XX $u subfields receive special attention as they are URIs.
807
808
=cut
809
810
sub get_marc_notes {
811
    my ( $self, $params ) = @_;
812
813
    my $marcflavour = $params->{marcflavour};
814
    my $opac = $params->{opac};
815
816
    my $scope = $marcflavour eq "UNIMARC"? '3..': '5..';
817
    my @marcnotes;
818
819
    #MARC21 specs indicate some notes should be private if first indicator 0
820
    my %maybe_private = (
821
        541 => 1,
822
        542 => 1,
823
        561 => 1,
824
        583 => 1,
825
        590 => 1
826
    );
827
828
    my %hiddenlist = map { $_ => 1 }
829
        split( /,/, C4::Context->preference('NotesToHide'));
830
    foreach my $field ( $self->metadata->record->field($scope) ) {
831
        my $tag = $field->tag();
832
        next if $hiddenlist{ $tag };
833
        next if $opac && $maybe_private{$tag} && !$field->indicator(1);
834
        if( $marcflavour ne 'UNIMARC' && $field->subfield('u') ) {
835
            # Field 5XX$u always contains URI
836
            # Examples: 505u, 506u, 510u, 514u, 520u, 530u, 538u, 540u, 542u, 552u, 555u, 561u, 563u, 583u
837
            # We first push the other subfields, then all $u's separately
838
            # Leave further actions to the template (see e.g. opac-detail)
839
            my $othersub =
840
                join '', ( 'a' .. 't', 'v' .. 'z', '0' .. '9' ); # excl 'u'
841
            push @marcnotes, { marcnote => $field->as_string($othersub) };
842
            foreach my $sub ( $field->subfield('u') ) {
843
                $sub =~ s/^\s+|\s+$//g; # trim
844
                push @marcnotes, { marcnote => $sub };
845
            }
846
        } else {
847
            push @marcnotes, { marcnote => $field->as_string() };
848
        }
849
    }
850
    return \@marcnotes;
851
}
800
852
801
=head3 to_api
853
=head3 to_api
802
854
(-)a/basket/basket.pl (-1 / +2 lines)
Lines 61-68 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   = $biblio->get_marc_notes({ marcflavour => $marcflavour });
66
    my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
67
    my $marcauthorsarray = GetMarcAuthors( $record, $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);
(-)a/catalogue/detail.pl (-1 / +1 lines)
Lines 195-201 $template->param( Link Here
195
    normalized_isbn => $isbn,
195
    normalized_isbn => $isbn,
196
);
196
);
197
197
198
my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
198
my $marcnotesarray   = $biblio->get_marc_notes({ marcflavour => $marcflavour });
199
199
200
my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } };
200
my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } };
201
201
(-)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 81-87 foreach my $biblionumber ( @bibs ) { Link Here
81
    });
82
    });
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   = $biblio->get_marc_notes({ marcflavour => $marcflavour, opac => 1 });
85
    my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
86
    my $marcauthorsarray = GetMarcAuthors( $record, $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);
(-)a/opac/opac-detail.pl (-1 / +1 lines)
Lines 816-822 if (!C4::Context->preference("OPACXSLTDetailsDisplay") ) { Link Here
816
    );
816
    );
817
}
817
}
818
818
819
my $marcnotesarray   = GetMarcNotes   ($record,$marcflavour,1);
819
my $marcnotesarray = $biblio->get_marc_notes({ marcflavour => $marcflavour, opac => 1 });
820
820
821
if( C4::Context->preference('ArticleRequests') ) {
821
if( C4::Context->preference('ArticleRequests') ) {
822
    my $patron = $borrowernumber ? Koha::Patrons->find($borrowernumber) : undef;
822
    my $patron = $borrowernumber ? Koha::Patrons->find($borrowernumber) : undef;
(-)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 87-98 warning_is { $ret = GetMarcISSN() } Link Here
87
87
88
ok( !defined $ret, 'GetMarcISSN returns undef if not passed rec');
88
ok( !defined $ret, 'GetMarcISSN returns undef if not passed rec');
89
89
90
warning_is { $ret = GetMarcNotes() }
91
           { carped => 'GetMarcNotes called on undefined record'},
92
           "GetMarcNotes returns carped warning on undef record";
93
94
ok( !defined $ret, 'GetMarcNotes returns undef if not passed rec');
95
96
warning_is { $ret = GetMarcSubjects() }
90
warning_is { $ret = GetMarcSubjects() }
97
           { carped => 'GetMarcSubjects called on undefined record'},
91
           { carped => 'GetMarcSubjects called on undefined record'},
98
           "GetMarcSubjects returns carped warning on undef record";
92
           "GetMarcSubjects returns carped warning on undef record";
(-)a/t/Biblio/GetMarcNotes.t (-70 lines)
Lines 1-70 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 2;
21
use t::lib::Mocks;
22
23
use MARC::Field;
24
use MARC::Record;
25
26
use C4::Biblio;
27
28
subtest 'GetMarcNotes MARC21' => sub {
29
    plan tests => 11;
30
    t::lib::Mocks::mock_preference( 'NotesToHide', '520' );
31
32
    my $record = MARC::Record->new;
33
    $record->append_fields(
34
        MARC::Field->new( '500', '', '', a => 'Note1' ),
35
        MARC::Field->new( '505', '', '', a => 'Note2', u => 'http://someserver.com' ),
36
        MARC::Field->new( '520', '', '', a => 'Note3 skipped' ),
37
        MARC::Field->new( '541', '0', '', a => 'Note4 skipped on opac' ),
38
        MARC::Field->new( '541', '', '', a => 'Note5' ),
39
    );
40
    my $notes = C4::Biblio::GetMarcNotes( $record, 'MARC21' );
41
    is( $notes->[0]->{marcnote}, 'Note1', 'First note' );
42
    is( $notes->[1]->{marcnote}, 'Note2', 'Second note' );
43
    is( $notes->[2]->{marcnote}, 'http://someserver.com', 'URL separated' );
44
    is( $notes->[3]->{marcnote}, 'Note4 skipped on opac',"Not shows if not opac" );
45
    is( $notes->[4]->{marcnote}, 'Note5', 'Fifth note' );
46
    is( @$notes, 5, 'No more notes' );
47
    $notes = C4::Biblio::GetMarcNotes( $record, 'MARC21', 1 );
48
    is( $notes->[0]->{marcnote}, 'Note1', 'First note' );
49
    is( $notes->[1]->{marcnote}, 'Note2', 'Second note' );
50
    is( $notes->[2]->{marcnote}, 'http://someserver.com', 'URL separated' );
51
    is( $notes->[3]->{marcnote}, 'Note5', 'Fifth note shows after fourth skipped' );
52
    is( @$notes, 4, 'No more notes' );
53
54
};
55
56
subtest 'GetMarcNotes UNIMARC' => sub {
57
    plan tests => 3;
58
    t::lib::Mocks::mock_preference( 'NotesToHide', '310' );
59
60
    my $record = MARC::Record->new;
61
    $record->append_fields(
62
        MARC::Field->new( '300', '', '', a => 'Note1' ),
63
        MARC::Field->new( '300', '', '', a => 'Note2' ),
64
        MARC::Field->new( '310', '', '', a => 'Note3 skipped' ),
65
    );
66
    my $notes = C4::Biblio::GetMarcNotes( $record, 'UNIMARC' );
67
    is( $notes->[0]->{marcnote}, 'Note1', 'First note' );
68
    is( $notes->[1]->{marcnote}, 'Note2', 'Second note' );
69
    is( @$notes, 2, 'No more notes' );
70
};
(-)a/t/db_dependent/Biblio.t (-12 / +3 lines)
Lines 416-430 sub run_tests { Link Here
416
    }
416
    }
417
    is ($newincbiblioitemnumber, $biblioitemnumbertotest, 'Check newincbiblioitemnumber');
417
    is ($newincbiblioitemnumber, $biblioitemnumbertotest, 'Check newincbiblioitemnumber');
418
418
419
    # test for GetMarcNotes
420
    my $a1= GetMarcNotes( $marc_record, $marcflavour );
421
    my $field2 = MARC::Field->new( $marcflavour eq 'UNIMARC'? 300: 555, 0, '', a=> 'Some text', u=> 'http://url-1.com', u=> 'nohttp://something_else' );
422
    $marc_record->append_fields( $field2 );
423
    my $a2= GetMarcNotes( $marc_record, $marcflavour );
424
    is( ( $marcflavour eq 'UNIMARC' && @$a2 == @$a1 + 1 ) ||
425
        ( $marcflavour ne 'UNIMARC' && @$a2 == @$a1 + 3 ), 1,
426
        'Check the number of returned notes of GetMarcNotes' );
427
428
    # test for GetMarcUrls
419
    # test for GetMarcUrls
429
    $marc_record->append_fields(
420
    $marc_record->append_fields(
430
        MARC::Field->new( '856', '', '', u => ' https://koha-community.org ' ),
421
        MARC::Field->new( '856', '', '', u => ' https://koha-community.org ' ),
Lines 586-599 sub create_author_field { Link Here
586
}
577
}
587
578
588
subtest 'MARC21' => sub {
579
subtest 'MARC21' => sub {
589
    plan tests => 48;
580
    plan tests => 47;
590
    run_tests('MARC21');
581
    run_tests('MARC21');
591
    $schema->storage->txn_rollback;
582
    $schema->storage->txn_rollback;
592
    $schema->storage->txn_begin;
583
    $schema->storage->txn_begin;
593
};
584
};
594
585
595
subtest 'UNIMARC' => sub {
586
subtest 'UNIMARC' => sub {
596
    plan tests => 48;
587
    plan tests => 47;
597
588
598
    # Mock the auth type data for UNIMARC
589
    # Mock the auth type data for UNIMARC
599
    $dbh->do("UPDATE auth_types SET auth_tag_to_report = '106' WHERE auth_tag_to_report = '100'") or die $dbh->errstr;
590
    $dbh->do("UPDATE auth_types SET auth_tag_to_report = '106' WHERE auth_tag_to_report = '100'") or die $dbh->errstr;
Lines 604-610 subtest 'UNIMARC' => sub { Link Here
604
};
595
};
605
596
606
subtest 'NORMARC' => sub {
597
subtest 'NORMARC' => sub {
607
    plan tests => 48;
598
    plan tests => 47;
608
    run_tests('NORMARC');
599
    run_tests('NORMARC');
609
    $schema->storage->txn_rollback;
600
    $schema->storage->txn_rollback;
610
    $schema->storage->txn_begin;
601
    $schema->storage->txn_begin;
(-)a/t/db_dependent/Koha/Biblio.t (-2 / +60 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 => 14;
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
- 
554
555
subtest 'get_marc_notes() MARC21 tests' => sub {
556
    plan tests => 11;
557
558
    $schema->storage->txn_begin;
559
560
    t::lib::Mocks::mock_preference( 'NotesToHide', '520' );
561
562
    my $biblio = $builder->build_sample_biblio;
563
    my $record = $biblio->metadata->record;
564
    $record->append_fields(
565
        MARC::Field->new( '500', '', '', a => 'Note1' ),
566
        MARC::Field->new( '505', '', '', a => 'Note2', u => 'http://someserver.com' ),
567
        MARC::Field->new( '520', '', '', a => 'Note3 skipped' ),
568
        MARC::Field->new( '541', '0', '', a => 'Note4 skipped on opac' ),
569
        MARC::Field->new( '541', '', '', a => 'Note5' ),
570
    );
571
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
572
    $biblio = Koha::Biblios->find( $biblio->biblionumber);
573
    my $notes = $biblio->get_marc_notes({ marcflavour => 'MARC21' });
574
    is( $notes->[0]->{marcnote}, 'Note1', 'First note' );
575
    is( $notes->[1]->{marcnote}, 'Note2', 'Second note' );
576
    is( $notes->[2]->{marcnote}, 'http://someserver.com', 'URL separated' );
577
    is( $notes->[3]->{marcnote}, 'Note4 skipped on opac',"Not shows if not opac" );
578
    is( $notes->[4]->{marcnote}, 'Note5', 'Fifth note' );
579
    is( @$notes, 5, 'No more notes' );
580
    $notes = $biblio->get_marc_notes({ marcflavour => 'MARC21', opac => 1 });
581
    is( $notes->[0]->{marcnote}, 'Note1', 'First note' );
582
    is( $notes->[1]->{marcnote}, 'Note2', 'Second note' );
583
    is( $notes->[2]->{marcnote}, 'http://someserver.com', 'URL separated' );
584
    is( $notes->[3]->{marcnote}, 'Note5', 'Fifth note shows after fourth skipped' );
585
    is( @$notes, 4, 'No more notes' );
586
587
    $schema->storage->txn_rollback;
588
};
589
590
subtest 'get_marc_notes() UNIMARC tests' => sub {
591
    plan tests => 3;
592
593
    $schema->storage->txn_begin;
594
595
    t::lib::Mocks::mock_preference( 'NotesToHide', '310' );
596
597
    my $biblio = $builder->build_sample_biblio;
598
    my $record = $biblio->metadata->record;
599
    $record->append_fields(
600
        MARC::Field->new( '300', '', '', a => 'Note1' ),
601
        MARC::Field->new( '300', '', '', a => 'Note2' ),
602
        MARC::Field->new( '310', '', '', a => 'Note3 skipped' ),
603
    );
604
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
605
    $biblio = Koha::Biblios->find( $biblio->biblionumber);
606
    my $notes = $biblio->get_marc_notes({ marcflavour => 'UNIMARC' });
607
    is( $notes->[0]->{marcnote}, 'Note1', 'First note' );
608
    is( $notes->[1]->{marcnote}, 'Note2', 'Second note' );
609
    is( @$notes, 2, 'No more notes' );
610
611
    $schema->storage->txn_rollback;
612
};

Return to bug 27268