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