|
Lines 368-419
sub _do_xslt_proc {
Link Here
|
| 368 |
sub _add_custom_field_rowdata { |
368 |
sub _add_custom_field_rowdata { |
| 369 |
my ( $row, $record, $pref_newtags ) = @_; |
369 |
my ( $row, $record, $pref_newtags ) = @_; |
| 370 |
$pref_newtags //= ''; |
370 |
$pref_newtags //= ''; |
| 371 |
my $pref_flavour = C4::Context->preference('MarcFlavour'); |
371 |
$pref_newtags =~ s/\h+//g; |
| 372 |
|
|
|
| 373 |
$pref_newtags =~ s/^\s+|\s+$//g; |
| 374 |
$pref_newtags =~ s/\h+/ /g; |
| 375 |
|
372 |
|
| 376 |
my @addnumberfields; |
373 |
my @addnumberfields; |
| 377 |
|
374 |
foreach my $field ( split /,/, $pref_newtags ) { |
| 378 |
foreach my $field ( split /\,/, $pref_newtags ) { |
375 |
my @content; |
| 379 |
$field =~ s/^\s+|\s+$//g; # trim whitespace |
376 |
my ( $tag, $add_spec ) = ( $field =~ /^(\d+)(|\$[0-9a-z]+|p\d+-\d+|p\d+)$/ ); |
| 380 |
my ( $tag, $subtags ) = split( /\$/, $field ); |
377 |
next if $tag && exists $row->{$tag}; # Silently ignore double entries in pref |
| 381 |
|
378 |
if ( !$tag || ( $tag < 10 && $add_spec =~ /^\$/ ) || ( $tag >= 10 && $add_spec =~ /^p/ ) ) { |
| 382 |
if ( $record->field($tag) ) { |
379 |
warn "Breeding: invalid expression in AdditionalFieldsInZ3950Result(Auth)Search: $field"; |
| 383 |
my @content = (); |
380 |
next; |
| 384 |
|
381 |
} elsif ( $tag eq '000' ) { |
|
|
382 |
push @content, ( _extract_positions( $record->leader, $add_spec ) ); |
| 383 |
} elsif ( $tag =~ /^00\d$/ ) { # control field |
| 384 |
my $marcfield = $record->field($tag); |
| 385 |
push @content, ( _extract_positions( $marcfield->data, $add_spec ) ); |
| 386 |
} else { |
| 385 |
for my $marcfield ( $record->field($tag) ) { |
387 |
for my $marcfield ( $record->field($tag) ) { |
| 386 |
if ($subtags) { |
388 |
foreach my $subfield ( $marcfield->subfields ) { |
| 387 |
my $str = ''; |
389 |
next unless !$add_spec || $subfield->[0] =~ /[$add_spec]/; |
| 388 |
for my $code ( split //, $subtags ) { |
390 |
push @content, '[' . $subfield->[0] . ']' . $subfield->[1]; |
| 389 |
if ( $marcfield->subfield($code) ) { |
|
|
| 390 |
$str .= $marcfield->subfield($code) . ' '; |
| 391 |
} |
| 392 |
} |
| 393 |
if ( not $str eq '' ) { |
| 394 |
push @content, $str; |
| 395 |
} |
| 396 |
} elsif ( $tag == 10 ) { |
| 397 |
push @content, ( $pref_flavour eq "MARC21" ? $marcfield->data : $marcfield->as_string ); |
| 398 |
} elsif ( $tag < 10 ) { |
| 399 |
push @content, $marcfield->data(); |
| 400 |
} else { |
| 401 |
push @content, $marcfield->as_string(); |
| 402 |
} |
391 |
} |
| 403 |
} |
392 |
} |
| 404 |
|
393 |
} |
| 405 |
if (@content) { |
394 |
if (@content) { |
| 406 |
$row->{$field} = \@content; |
395 |
$row->{$tag} = [@content]; |
| 407 |
push( @addnumberfields, $field ); |
396 |
push @addnumberfields, $tag; |
| 408 |
} |
|
|
| 409 |
} |
397 |
} |
| 410 |
} |
398 |
} |
| 411 |
|
399 |
$row->{addnumberfields} = [ sort @addnumberfields ]; |
| 412 |
$row->{'addnumberfields'} = \@addnumberfields; |
|
|
| 413 |
|
| 414 |
return $row; |
400 |
return $row; |
| 415 |
} |
401 |
} |
| 416 |
|
402 |
|
|
|
403 |
sub _extract_positions { |
| 404 |
my ( $data, $spec ) = @_; |
| 405 |
if ( !$spec ) { |
| 406 |
return $data; |
| 407 |
} elsif ( $spec =~ /p(\d+)$/ ) { |
| 408 |
my $pos = $1; |
| 409 |
return if $pos >= length($data); |
| 410 |
return "[$pos]" . substr( $data, $pos, 1 ); |
| 411 |
} elsif ( $spec =~ /p(\d+)-(\d+)/ ) { |
| 412 |
my ( $start, $end ) = ( $1, $2 ); |
| 413 |
return if $end < $start || $start >= length($data); |
| 414 |
return "[$start-$end]" . substr( $data, $start, $end - $start + 1 ); |
| 415 |
} |
| 416 |
return; |
| 417 |
} |
| 418 |
|
| 417 |
sub _isbn_replace { |
419 |
sub _isbn_replace { |
| 418 |
my ($isbn) = @_; |
420 |
my ($isbn) = @_; |
| 419 |
return unless defined $isbn; |
421 |
return unless defined $isbn; |