- # 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;