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

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

Return to bug 14306