Lines 415-420
sub GetMarcHoldingsByBiblionumber {
Link Here
|
415 |
return \@records; |
415 |
return \@records; |
416 |
} |
416 |
} |
417 |
|
417 |
|
|
|
418 |
=head2 GetMarcHoldingsFields |
419 |
|
420 |
my @marc_fields = GetMarcHoldingsFields($biblionumber); |
421 |
|
422 |
Returns an array of MARC::Record objects of the holdings for the biblio. |
423 |
|
424 |
=cut |
425 |
|
426 |
sub GetMarcHoldingsFields { |
427 |
my ( $biblionumber ) = @_; |
428 |
# This is so much faster than using Koha::Holdings->search that it makes sense even if it's ugly. |
429 |
my $sth = C4::Context->dbh->prepare( 'SELECT * FROM holdings WHERE biblionumber = ?' ); |
430 |
$sth->execute( $biblionumber ); |
431 |
my $holdings = $sth->fetchall_arrayref({}); |
432 |
$sth->finish(); |
433 |
my @holdings_fields; |
434 |
my ( $holdingstag, $holdingssubfield ) = GetMarcHoldingFromKohaField( 'holdings.holdingbranch' ); |
435 |
ITEMLOOP: foreach my $holding (@$holdings) { |
436 |
my $mungedholding = { |
437 |
map { |
438 |
defined($holding->{$_}) && $holding->{$_} ne '' ? ("holdings.$_" => $holding->{$_}) : () |
439 |
} keys %{ $holding } |
440 |
}; |
441 |
my $marc = TransformKohaHoldingToMarc($mungedholding); |
442 |
push @holdings_fields, $marc->field( $holdingstag ); |
443 |
} |
444 |
return \@holdings_fields; |
445 |
} |
446 |
|
418 |
=head2 GetHoldingFrameworkCode |
447 |
=head2 GetHoldingFrameworkCode |
419 |
|
448 |
|
420 |
$frameworkcode = GetFrameworkCode( $holding_id ) |
449 |
$frameworkcode = GetFrameworkCode( $holding_id ) |
Lines 773-778
sub TransformMarcHoldingToKohaOneField {
Link Here
|
773 |
return $retval; |
802 |
return $retval; |
774 |
} |
803 |
} |
775 |
|
804 |
|
|
|
805 |
=head2 TransformKohaToMarc |
806 |
|
807 |
$record = TransformKohaToMarc( $hash [, $params ] ) |
808 |
|
809 |
This function builds partial MARC::Record from holdings hash entries. |
810 |
This function is called when embedding holdings into a biblio record. |
811 |
|
812 |
=cut |
813 |
|
814 |
sub TransformKohaHoldingToMarc { |
815 |
my ( $hash, $params ) = @_; |
816 |
my $record = MARC::Record->new(); |
817 |
SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") ); |
818 |
|
819 |
# In the next call we use the Default holdings framework, since it is considered |
820 |
# authoritative for Koha to Marc mappings. |
821 |
my $mss = C4::Biblio::GetMarcSubfieldStructure( 'HLD', { unsafe => 1 } ); # do not change framewok |
822 |
my $tag_hr = {}; |
823 |
while ( my ($kohafield, $value) = each %$hash ) { |
824 |
foreach my $fld ( @{ $mss->{$kohafield} } ) { |
825 |
my $tagfield = $fld->{tagfield}; |
826 |
my $tagsubfield = $fld->{tagsubfield}; |
827 |
next if !$tagfield; |
828 |
my @values = $params->{no_split} |
829 |
? ( $value ) |
830 |
: split(/\s?\|\s?/, $value, -1); |
831 |
foreach my $value ( @values ) { |
832 |
next if $value eq ''; |
833 |
$tag_hr->{$tagfield} //= []; |
834 |
push @{$tag_hr->{$tagfield}}, [($tagsubfield, $value)]; |
835 |
} |
836 |
} |
837 |
} |
838 |
foreach my $tag (sort keys %$tag_hr) { |
839 |
my @sfl = @{$tag_hr->{$tag}}; |
840 |
@sfl = sort { $a->[0] cmp $b->[0]; } @sfl; |
841 |
@sfl = map { @{$_}; } @sfl; |
842 |
# Special care for control fields: remove the subfield indication @ |
843 |
# and do not insert indicators. |
844 |
my @ind = $tag < 10 ? () : ( " ", " " ); |
845 |
@sfl = grep { $_ ne '@' } @sfl if $tag < 10; |
846 |
$record->insert_fields_ordered( MARC::Field->new($tag, @ind, @sfl) ); |
847 |
} |
848 |
return $record; |
849 |
} |
850 |
|
776 |
1; |
851 |
1; |
777 |
|
852 |
|
778 |
|
853 |
|