@@ -, +, @@ GetRecordValue subroutine --- --- ------ --- --- C4/Biblio.pm | 37 ++++++++++++++++++++++++++++++++++--- 1 files changed, 34 insertions(+), 3 deletions(-) --- a/C4/Biblio.pm +++ a/C4/Biblio.pm @@ -674,14 +674,14 @@ sub _check_valid_auth_link { =head2 GetRecordValue - my $values = GetRecordValue($field, $record, $frameworkcode); + my $values = GetRecordValue($field, $record, $frameworkcode, $as_string); Get MARC fields from a keyword defined in fieldmapping table. =cut sub GetRecordValue { - my ( $field, $record, $frameworkcode ) = @_; + my ( $field, $record, $frameworkcode, $as_string ) = @_; my $dbh = C4::Context->dbh; my $sth = $dbh->prepare('SELECT fieldcode, subfieldcode FROM fieldmapping WHERE frameworkcode = ? AND field = ?'); @@ -701,8 +701,39 @@ sub GetRecordValue { } } } + + if ($as_string) { + my $string = _array_of_hashes_to_string(\@result, ' '); + return $string; + } else { + return \@result; + } +} - return \@result; +=head2 _array_of_hashes_to_string + + my $string = _array_of_hashes_to_string($array, $glue); + + Transform an array ref of hash refs into a string + +=cut + +sub _array_of_hashes_to_string { + my ( $array, $glue ) = @_; + my $string = ''; + + if ($array) { + for my $element (@$array) { + if ($element) { + foreach my $key ( keys %$element ) { + $string .= $element->{$key} . $glue; + } + } + } + } + + $string =~ s/\s+$//; + return $string; } =head2 SetFieldMapping --