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

(-)a/C4/Biblio.pm (-23 / +18 lines)
Lines 1767-1776 sub GetMarcISSN { Link Here
1767
1767
1768
=head2 GetMarcNotes
1768
=head2 GetMarcNotes
1769
1769
1770
  $marcnotesarray = GetMarcNotes( $record, $marcflavour );
1770
    $marcnotesarray = GetMarcNotes( $record, $marcflavour );
1771
1771
1772
Get all notes from the MARC record and returns them in an array.
1772
    Get all notes from the MARC record and returns them in an array.
1773
The note are stored in different fields depending on MARC flavour
1773
    The notes are stored in different fields depending on MARC flavour.
1774
    MARC21 field 555 gets special attention for the $u subfields.
1774
1775
1775
=cut
1776
=cut
1776
1777
Lines 1780-1813 sub GetMarcNotes { Link Here
1780
        carp 'GetMarcNotes called on undefined record';
1781
        carp 'GetMarcNotes called on undefined record';
1781
        return;
1782
        return;
1782
    }
1783
    }
1783
    my $scope;
1784
1784
    if ( $marcflavour eq "UNIMARC" ) {
1785
    my $scope = $marcflavour eq "UNIMARC"? '3..': '5..';
1785
        $scope = '3..';
1786
    } else {    # assume marc21 if not unimarc
1787
        $scope = '5..';
1788
    }
1789
    my @marcnotes;
1786
    my @marcnotes;
1790
    my $note = "";
1787
    my %blacklist = map { $_ => 1 }
1791
    my $tag  = "";
1788
        split( /,/, C4::Context->preference('NotesBlacklist'));
1792
    my $marcnote;
1793
    my %blacklist = map { $_ => 1 } split(/,/,C4::Context->preference('NotesBlacklist'));
1794
    foreach my $field ( $record->field($scope) ) {
1789
    foreach my $field ( $record->field($scope) ) {
1795
        my $tag = $field->tag();
1790
        my $tag = $field->tag();
1796
        next if $blacklist{$tag};
1791
        next if $blacklist{ $tag };
1797
1798
        my $value = $field->as_string();
1799
        if( $marcflavour ne 'UNIMARC' && $tag =~ /555/ ) {
1792
        if( $marcflavour ne 'UNIMARC' && $tag =~ /555/ ) {
1800
            my @sub= $field->subfield('u');
1793
            # Field 555$u contains URLs
1801
            foreach my $s (@sub) {
1794
            # We first push the regular subfields and all $u's separately
1802
                next if $s !~ /^http/;
1795
            # Leave further actions to the template
1803
                my $i= index( $value, $s);
1796
            push @marcnotes, { marcnote => $field->as_string('abcd') };
1804
                $value= substr( $value,0, $i) . "<a href=\"$s\" target=\"_blank\">$s</a>" . substr( $value, $i + length($s) );
1797
            foreach my $sub ( $field->subfield('u') ) {
1798
                push @marcnotes, { marcnote => $sub };
1805
            }
1799
            }
1800
        } else {
1801
            push @marcnotes, { marcnote => $field->as_string() };
1806
        }
1802
        }
1807
        push @marcnotes, { marcnote => $value };
1808
    }
1803
    }
1809
    return \@marcnotes;
1804
    return \@marcnotes;
1810
}    # end GetMarcNotes
1805
}
1811
1806
1812
=head2 GetMarcSubjects
1807
=head2 GetMarcSubjects
1813
1808
(-)a/t/db_dependent/Biblio.t (-7 / +4 lines)
Lines 205-222 sub run_tests { Link Here
205
    } else {
205
    } else {
206
        $biblioitemnumbertotest = $updatedrecord->field($biblioitem_tag)->subfield($biblioitem_subfield);
206
        $biblioitemnumbertotest = $updatedrecord->field($biblioitem_tag)->subfield($biblioitem_subfield);
207
    }
207
    }
208
    is ($newincbiblioitemnumber, $biblioitemnumbertotest);
208
    is ($newincbiblioitemnumber, $biblioitemnumbertotest, 'Check newincbiblioitemnumber');
209
209
210
    # test for GetMarcNotes
210
    # test for GetMarcNotes
211
    my $a1= GetMarcNotes( $marc_record, $marcflavour );
211
    my $a1= GetMarcNotes( $marc_record, $marcflavour );
212
    my $field2 = MARC::Field->new( $marcflavour eq 'UNIMARC'? 300: 555, 0, '', a=> 'Some text', u=> 'http://url-1.com', u=> 'nohttp://something_else' );
212
    my $field2 = MARC::Field->new( $marcflavour eq 'UNIMARC'? 300: 555, 0, '', a=> 'Some text', u=> 'http://url-1.com', u=> 'nohttp://something_else' );
213
    $marc_record->append_fields( $field2 );
213
    $marc_record->append_fields( $field2 );
214
    my $a2= GetMarcNotes( $marc_record, $marcflavour );
214
    my $a2= GetMarcNotes( $marc_record, $marcflavour );
215
    my $last= @$a2? $a2->[@$a2-1]->{marcnote}: '';
215
    is( ( $marcflavour eq 'UNIMARC' && @$a2 == @$a1 + 1 ) ||
216
    is( @$a2 == @$a1 + 1 && (
216
        ( $marcflavour ne 'UNIMARC' && @$a2 == @$a1 + 3 ), 1,
217
        ( $marcflavour eq 'UNIMARC' && $last eq $field2->as_string() ) ||
217
        'Check the number of returned notes of GetMarcNotes' );
218
        ( $marcflavour ne 'UNIMARC' && $last =~ /\<a href=/ )),
219
        1, 'Test for GetMarcNotes' );
220
}
218
}
221
219
222
sub mock_marcfromkohafield {
220
sub mock_marcfromkohafield {
223
- 

Return to bug 14306