use YAML; #marcrecords2csv
use Template;
use Text::CSV::Encoded; #marc2csv
+use Koha::SimpleMARC qw(read_field);
use vars qw($VERSION @ISA @EXPORT);
if ($f500) {
$abstract = $f500->subfield('a');
}
- my $fields = {
- DB => C4::Context->preference("LibraryName"),
- Title => $marc_rec_obj->title(),
- Author => $marc_rec_obj->author(),
- Publisher => $f710a,
- City => $f260a,
- Year => $marc_rec_obj->publication_date,
- Abstract => $abstract,
- };
- my $endnote;
- my $style = new Biblio::EndnoteStyle();
- my $template;
- $template.= "DB - DB\n" if C4::Context->preference("LibraryName");
- $template.="T1 - Title\n" if $marc_rec_obj->title();
- $template.="A1 - Author\n" if $marc_rec_obj->author();
- $template.="PB - Publisher\n" if $f710a;
- $template.="CY - City\n" if $f260a;
- $template.="Y1 - Year\n" if $marc_rec_obj->publication_date;
- $template.="AB - Abstract\n" if $abstract;
- my ($text, $errmsg) = $style->format($template, $fields);
- return ($text);
-
+ my $fields = {
+ DB => C4::Context->preference("LibraryName"),
+ Title => $marc_rec_obj->title(),
+ Author => $marc_rec_obj->author(),
+ Publisher => $f710a,
+ City => $f260a,
+ Year => $marc_rec_obj->publication_date,
+ Abstract => $abstract,
+ };
+ my $endnote;
+ my $style = new Biblio::EndnoteStyle();
+ my $template;
+ $template.= "DB - DB\n" if C4::Context->preference("LibraryName");
+ $template.="T1 - Title\n" if $marc_rec_obj->title();
+ $template.="A1 - Author\n" if $marc_rec_obj->author();
+ $template.="PB - Publisher\n" if $f710a;
+ $template.="CY - City\n" if $f260a;
+ $template.="Y1 - Year\n" if $marc_rec_obj->publication_date;
+ $template.="AB - Abstract\n" if $abstract;
+ my ($text, $errmsg) = $style->format($template, $fields);
+ return ($text);
+
}
=head2 marc2csv - Convert several records from UNIMARC to CSV
my $error;
unless($flavour) {$flavour = C4::Context->preference("marcflavour")};
unless($to_encoding) {$to_encoding = "UTF-8"};
-
+
# ISO-2709 Record (MARC21 or UNIMARC)
if (lc($format) =~ /^marc$/o) {
# if we're converting encoding of an ISO2709 file, we need to roundtrip through XML
unless ($error) {
($error,$newrecord) = marcxml2marc($marcxml,$to_encoding,$flavour);
}
-
+
# MARCXML Record
} elsif (lc($format) =~ /^marcxml$/o) { # MARCXML Record
my $marc;
);
}
- $tex .= "\@book{";
+ my $BibtexExportAdditionalFields = C4::Context->preference('BibtexExportAdditionalFields');
+ my $additional_fields;
+ if ($BibtexExportAdditionalFields) {
+ $BibtexExportAdditionalFields = "$BibtexExportAdditionalFields\n\n";
+ $additional_fields = eval { YAML::Load($BibtexExportAdditionalFields); };
+ if ($@) {
+ warn "Unable to parse BibtexExportAdditionalFields : $@";
+ $additional_fields = undef;
+ }
+ }
+
+ if ( $additional_fields && $additional_fields->{'@'} ) {
+ my ( $f, $sf ) = split( /\$/, $additional_fields->{'@'} );
+ my ( $type ) = read_field( { record => $record, field => $f, subfield => $sf, field_numbers => [1] } );
+
+ if ($type) {
+ $tex .= '@' . $type . '{';
+ }
+ else {
+ $tex .= "\@book{";
+ }
+ }
+ else {
+ $tex .= "\@book{";
+ }
+
my @elt;
for ( my $i = 0 ; $i < scalar( @bh ) ; $i = $i + 2 ) {
next unless $bh[$i+1];
push @elt, qq|\t$bh[$i] = {$bh[$i+1]}|;
}
$tex .= join(",\n", $id, @elt);
- $tex .= "\n}\n";
+
+ if ($additional_fields) {
+ $tex .= ",\n";
+ foreach my $bibtex_tag ( keys %$additional_fields ) {
+ next if $bibtex_tag eq '@';
+
+ my @fields =
+ ref( $additional_fields->{$bibtex_tag} ) eq 'ARRAY'
+ ? @{ $additional_fields->{$bibtex_tag} }
+ : $additional_fields->{$bibtex_tag};
+
+ for my $tag (@fields) {
+ my ( $f, $sf ) = split( /\$/, $tag );
+ my @values = read_field( { record => $record, field => $f, subfield => $sf } );
+ foreach my $v (@values) {
+ $tex .= qq(\t$bibtex_tag = {$v}\n);
+ }
+ }
+ }
+ }
+ else {
+ $tex .= "\n";
+ }
+
+ $tex .= "}\n";
return $tex;
}