X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FBiblio.pm;h=558b228e4b2bd7b66f81f1442aa49e468c44ea9c;hb=b5e18fe431131000994189f855f9b9245a5fdcb3;hp=c4e107ca43c028c24f9079e6feceb5de07927676;hpb=5841954b36547699a7bdbcb0586c8d647fec44e8;p=koha_gimpoz diff --git a/C4/Biblio.pm b/C4/Biblio.pm index c4e107ca43..558b228e4b 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -26,9 +26,6 @@ use MARC::Record; use MARC::File::USMARC; use MARC::File::XML; use ZOOM; - -use Data::Dumper; - use C4::Koha; use C4::Dates qw/format_date/; use C4::Log; # logaction @@ -2359,58 +2356,70 @@ sub TransformHtmlToMarc { sub TransformMarcToKoha { my ( $dbh, $record, $frameworkcode, $table ) = @_; - + my $result; - # sometimes we only want to return the items data - # hmm this was just added, ill tidy this up too later - if ($table eq 'items') { - my $sth = $dbh->prepare("SHOW COLUMNS FROM items"); - $sth->execute(); - while ( (my $field) = $sth->fetchrow ) { - $result = &TransformMarcToKohaOneField( "items", $field, $record, $result, $frameworkcode ); - } - return $result; + # sometimes we only want to return the items data + if ($table eq 'items') { + my $sth = $dbh->prepare("SHOW COLUMNS FROM items"); + $sth->execute(); + while ( (my $field) = $sth->fetchrow ) { + my $value = get_koha_field_from_marc($table,$field,$record,$frameworkcode); + my $key = _disambiguate($table, $field); + if ($result->{$key}) { + $result->{$key} .= " | " . $value; + } else { + $result->{$key} = $value; + } + } + return $result; + } else { + my @tables = ('biblio','biblioitems','items'); + foreach my $table (@tables){ + my $sth2 = $dbh->prepare("SHOW COLUMNS from $table"); + $sth2->execute; + while (my ($field) = $sth2->fetchrow){ + # FIXME use of _disambiguate is a temporary hack + # $result->{_disambiguate($table, $field)} = get_koha_field_from_marc($table,$field,$record,$frameworkcode); + my $value = get_koha_field_from_marc($table,$field,$record,$frameworkcode); + my $key = _disambiguate($table, $field); + if ($result->{$key}) { + # FIXME - hack to not bring in duplicates of the same value + unless (($key eq "biblionumber" or $key eq "biblioitemnumber") and ($value eq "")) { + $result->{$key} .= " | " . $value; + } + } else { + $result->{$key} = $value; + } + } + $sth2->finish(); + } + # modify copyrightdate to keep only the 1st year found + my $temp = $result->{'copyrightdate'}; + $temp =~ m/c(\d\d\d\d)/; # search cYYYY first + if ( $1 > 0 ) { + $result->{'copyrightdate'} = $1; + } + else { # if no cYYYY, get the 1st date. + $temp =~ m/(\d\d\d\d)/; + $result->{'copyrightdate'} = $1; + } + + # modify publicationyear to keep only the 1st year found + $temp = $result->{'publicationyear'}; + $temp =~ m/c(\d\d\d\d)/; # search cYYYY first + if ( $1 > 0 ) { + $result->{'publicationyear'} = $1; + } + else { # if no cYYYY, get the 1st date. + $temp =~ m/(\d\d\d\d)/; + $result->{'publicationyear'} = $1; + } + return $result; } - else { - my @tables = ('biblio','biblioitems','items'); - foreach my $table (@tables){ - my $sth2 = $dbh->prepare("SHOW COLUMNS from $table"); - $sth2->execute; - while (my ($field) = $sth2->fetchrow){ - # id like to do this, it will break lots of other places, but doing it will stop the namespace clashes -# $result->{$table.'.'.$field} = get_kohafield_from_marc($table,$field,$record,$frameworkcode); - # so for now doing this\ - $result = TransformMarcToKohaOneField( $table, $field, $record, $result, $frameworkcode ); - } - } - - # not sure about this stuff, will revisit - # - # modify copyrightdate to keep only the 1st year found - my $temp = $result->{'copyrightdate'}; - $temp =~ m/c(\d\d\d\d)/; # search cYYYY first - if ( $1 > 0 ) { - $result->{'copyrightdate'} = $1; - } - else { # if no cYYYY, get the 1st date. - $temp =~ m/(\d\d\d\d)/; - $result->{'copyrightdate'} = $1; - } - - # modify publicationyear to keep only the 1st year found - $temp = $result->{'publicationyear'}; - $temp =~ m/c(\d\d\d\d)/; # search cYYYY first - if ( $1 > 0 ) { - $result->{'publicationyear'} = $1; - } - else { # if no cYYYY, get the 1st date. - $temp =~ m/(\d\d\d\d)/; - $result->{'publicationyear'} = $1; - } - return $result; - } } + + =head2 _disambiguate =over 4 @@ -2454,12 +2463,23 @@ sub _disambiguate { } -# sub to replace TransformMarcToKohaOneField +=head2 get_koha_field_from_marc -sub get_kohafield_from_marc { - my ($koha_table,$koha_field,$record,$frameworkcode) = @_; - my ( $tagfield, $subfield ) = GetMarcFromKohaField( $koha_table.'.'.$koha_field, $frameworkcode ); - my $kohafield; +=over 4 + +$result->{_disambiguate($table, $field)} = get_koha_field_from_marc($table,$field,$record,$frameworkcode); + +Internal function to map data from the MARC record to a specific non-MARC field. +FIXME: this is meant to replace TransformMarcToKohaOneField after more testing. + +=back + +=cut + +sub get_koha_field_from_marc { + my ($koha_table,$koha_column,$record,$frameworkcode) = @_; + my ( $tagfield, $subfield ) = GetMarcFromKohaField( $koha_table.'.'.$koha_column, $frameworkcode ); + my $kohafield; foreach my $field ( $record->field($tagfield) ) { if ( $field->tag() < 10 ) { if ( $kohafield ) { @@ -2488,7 +2508,7 @@ sub get_kohafield_from_marc { } } return $kohafield; -} +} =head2 TransformMarcToKohaOneField