- my ($f,$item,$record) = @_;
- my $kohatables= &_descKohaTables();
- my $datastring;
- my $last_f = $f;
- my $match_kohatable = join('|', (@{$kohatables->{biblio}},@{$kohatables->{biblioitems}},@{$kohatables->{items}}) );
- while( $f ) {
- if( $f =~ /^'(.*)'.*/ ) {
- # single quotes indicate a static text string.
- $datastring .= $1 ;
- $f = $';
- } elsif ( $f =~ /^($match_kohatable).*/ ) {
- # grep /$f/, (@$kohatables->{biblio},@$kohatables->{biblioitems},@$kohatables->{items}) ) {
- $datastring .= $item->{$f};
- $f = $';
- } elsif ( $f =~ /^([0-9a-z]{3})(\w)(\W*).*/ ) {
- $datastring .= $record->subfield($1,$2) . $3 if($record->subfield($1,$2)) ;
- $f = $';
- }
- last if ( $f eq $last_f ); # failed to match
- }
- return $datastring;
+ my ( $f, $item, $record ) = @_;
+ my $kohatables = &_descKohaTables();
+ my $datastring = '';
+ my $match_kohatable = join(
+ '|',
+ (
+ @{ $kohatables->{biblio} },
+ @{ $kohatables->{biblioitems} },
+ @{ $kohatables->{items} }
+ )
+ );
+ while ($f) {
+ $f =~ s/^\s?//;
+ if ( $f =~ /^'(.*)'.*/ ) {
+ # single quotes indicate a static text string.
+ $datastring .= $1;
+ $f = $';
+ }
+ elsif ( $f =~ /^($match_kohatable).*/ ) {
+ $datastring .= $item->{$f};
+ $f = $';
+ }
+ elsif ( $f =~ /^([0-9a-z]{3})(\w)(\W?).*?/ ) {
+ my $marc_field = $1;
+ foreach my $subfield ($record->field($marc_field)) {
+ if ( $subfield->subfield('9') eq $item->{'itemnumber'} ) {
+ $datastring .= $subfield->subfield($2 ) . $3;
+ last;
+ }
+ }
+ $f = $';
+ }
+ else {
+ last; # Failed to match
+ }
+ }
+ return $datastring;