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

(-)a/C4/Biblio.pm (-23 / +18 lines)
Lines 1746-1755 sub GetMarcISSN { Link Here
1746
1746
1747
=head2 GetMarcNotes
1747
=head2 GetMarcNotes
1748
1748
1749
  $marcnotesarray = GetMarcNotes( $record, $marcflavour );
1749
    $marcnotesarray = GetMarcNotes( $record, $marcflavour );
1750
1750
1751
Get all notes from the MARC record and returns them in an array.
1751
    Get all notes from the MARC record and returns them in an array.
1752
The note are stored in different fields depending on MARC flavour
1752
    The notes are stored in different fields depending on MARC flavour.
1753
    MARC21 field 555 gets special attention for the $u subfields.
1753
1754
1754
=cut
1755
=cut
1755
1756
Lines 1759-1792 sub GetMarcNotes { Link Here
1759
        carp 'GetMarcNotes called on undefined record';
1760
        carp 'GetMarcNotes called on undefined record';
1760
        return;
1761
        return;
1761
    }
1762
    }
1762
    my $scope;
1763
1763
    if ( $marcflavour eq "UNIMARC" ) {
1764
    my $scope = $marcflavour eq "UNIMARC"? '3..': '5..';
1764
        $scope = '3..';
1765
    } else {    # assume marc21 if not unimarc
1766
        $scope = '5..';
1767
    }
1768
    my @marcnotes;
1765
    my @marcnotes;
1769
    my $note = "";
1766
    my %blacklist = map { $_ => 1 }
1770
    my $tag  = "";
1767
        split( /,/, C4::Context->preference('NotesBlacklist'));
1771
    my $marcnote;
1772
    my %blacklist = map { $_ => 1 } split(/,/,C4::Context->preference('NotesBlacklist'));
1773
    foreach my $field ( $record->field($scope) ) {
1768
    foreach my $field ( $record->field($scope) ) {
1774
        my $tag = $field->tag();
1769
        my $tag = $field->tag();
1775
        next if $blacklist{$tag};
1770
        next if $blacklist{ $tag };
1776
1777
        my $value = $field->as_string();
1778
        if( $marcflavour ne 'UNIMARC' && $tag =~ /555/ ) {
1771
        if( $marcflavour ne 'UNIMARC' && $tag =~ /555/ ) {
1779
            my @sub= $field->subfield('u');
1772
            # Field 555$u contains URLs
1780
            foreach my $s (@sub) {
1773
            # We first push the regular subfields and all $u's separately
1781
                next if $s !~ /^http/;
1774
            # Leave further actions to the template
1782
                my $i= index( $value, $s);
1775
            push @marcnotes, { marcnote => $field->as_string('abcd') };
1783
                $value= substr( $value,0, $i) . "<a href=\"$s\" target=\"_blank\">$s</a>" . substr( $value, $i + length($s) );
1776
            foreach my $sub ( $field->subfield('u') ) {
1777
                push @marcnotes, { marcnote => $sub };
1784
            }
1778
            }
1779
        } else {
1780
            push @marcnotes, { marcnote => $field->as_string() };
1785
        }
1781
        }
1786
        push @marcnotes, { marcnote => $value };
1787
    }
1782
    }
1788
    return \@marcnotes;
1783
    return \@marcnotes;
1789
}    # end GetMarcNotes
1784
}
1790
1785
1791
=head2 GetMarcSubjects
1786
=head2 GetMarcSubjects
1792
1787
(-)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