[Koha-patches] [PATCH 43/54] CSV export : deal with control fields to avoid an error (C4/Record.pm)

paul.poulain at biblibre.com paul.poulain at biblibre.com
Thu Dec 16 11:54:37 CET 2010


From: Paul Poulain <paul.poulain at biblibre.com>

---
 C4/Record.pm |   49 ++++++++++++++++++++++++++++++-------------------
 1 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/C4/Record.pm b/C4/Record.pm
index 497c03d..4c8eb8e 100644
--- a/C4/Record.pm
+++ b/C4/Record.pm
@@ -460,26 +460,37 @@ sub marcrecord2csv {
 		}
 	    }
 	    push (@fieldstab, join($subfieldseparator, @tmpfields));  		
-	# Or a field
-	} else {
-	    my @fields = ($record->field($marcfield));
-	    my $authvalues = GetKohaAuthorisedValuesFromField($marcfield, undef, $frameworkcode, undef);
-
-	    my @valuesarray;
-	    foreach (@fields) {
-		my $value;
-
-		# Getting authorised value
-		$value = defined $authvalues->{$_->as_string} ? $authvalues->{$_->as_string} : $_->as_string;
-
-		# Field processing
-		eval $fieldprocessing if ($fieldprocessing);
+   	    # Or a field
 
-		push @valuesarray, $value;
-	    }
-	    push (@fieldstab, join($fieldseparator, @valuesarray)); 
-	 }
-    };
+        } else {
+            my @fields = ( $record->field($marcfield) );
+            my $authvalues = GetKohaAuthorisedValuesFromField( $marcfield, undef, $frameworkcode, undef );
+
+            my @valuesarray;
+            foreach (@fields) {
+                my $value;
+
+               # If it is a control field
+               if ($_->is_control_field) {
+                   $value = defined $authvalues->{$_->as_string} ? $authvalues->{$_->as_string} : $_->as_string;
+               } else {
+                   # If it is a field, we gather all subfields, joined by the subfield separator
+                   my @subvaluesarray;
+                   my @subfields = $_->subfields;
+                   foreach my $subfield (@subfields) {
+                       push (@subvaluesarray, defined $authvalues->{$subfield->[1]} ? $authvalues->{$subfield->[1]} : $subfield->[1]);
+                   }
+                   $value = join ($subfieldseparator, @subvaluesarray);
+               }
+
+                # Field processing
+                eval $fieldprocessing if ($fieldprocessing);
+
+                push @valuesarray, $value;
+            }
+            push( @fieldstab, join( $fieldseparator, @valuesarray ) );
+        }
+    }
 
     $csv->combine(@fieldstab);
     $output .= $csv->string() . "\n";
-- 
1.7.1



More information about the Koha-patches mailing list