|
Lines 426-431
sub GetMarcHoldingsByBiblionumber {
Link Here
|
| 426 |
return \@records; |
426 |
return \@records; |
| 427 |
} |
427 |
} |
| 428 |
|
428 |
|
|
|
429 |
=head2 GetMarcHoldingsFields |
| 430 |
|
| 431 |
my @marc_fields = GetMarcHoldingsFields($biblionumber); |
| 432 |
|
| 433 |
Returns an array of MARC::Record objects of the holdings for the biblio. |
| 434 |
|
| 435 |
=cut |
| 436 |
|
| 437 |
sub GetMarcHoldingsFields { |
| 438 |
my ( $biblionumber ) = @_; |
| 439 |
# This is so much faster than using Koha::Holdings->search that it makes sense even if it's ugly. |
| 440 |
my $sth = C4::Context->dbh->prepare( 'SELECT * FROM holdings WHERE biblionumber = ?' ); |
| 441 |
$sth->execute( $biblionumber ); |
| 442 |
my $holdings = $sth->fetchall_arrayref({}); |
| 443 |
$sth->finish(); |
| 444 |
my @holdings_fields; |
| 445 |
my ( $holdingstag, $holdingssubfield ) = GetMarcHoldingFromKohaField( 'holdings.holdingbranch' ); |
| 446 |
ITEMLOOP: foreach my $holding (@$holdings) { |
| 447 |
my $mungedholding = { |
| 448 |
map { |
| 449 |
defined($holding->{$_}) && $holding->{$_} ne '' ? ("holdings.$_" => $holding->{$_}) : () |
| 450 |
} keys %{ $holding } |
| 451 |
}; |
| 452 |
my $marc = TransformKohaHoldingToMarc($mungedholding); |
| 453 |
push @holdings_fields, $marc->field( $holdingstag ); |
| 454 |
} |
| 455 |
return \@holdings_fields; |
| 456 |
} |
| 457 |
|
| 429 |
=head2 GetHoldingFrameworkCode |
458 |
=head2 GetHoldingFrameworkCode |
| 430 |
|
459 |
|
| 431 |
$frameworkcode = GetFrameworkCode( $holding_id ) |
460 |
$frameworkcode = GetFrameworkCode( $holding_id ) |
|
Lines 788-793
sub TransformMarcHoldingToKohaOneField {
Link Here
|
| 788 |
return $retval; |
817 |
return $retval; |
| 789 |
} |
818 |
} |
| 790 |
|
819 |
|
|
|
820 |
=head2 TransformKohaHoldingToMarc |
| 821 |
|
| 822 |
$record = TransformKohaToMarc( $hash [, $params ] ) |
| 823 |
|
| 824 |
This function builds partial MARC::Record from holdings hash entries. |
| 825 |
This function is called when embedding holdings into a biblio record. |
| 826 |
|
| 827 |
=cut |
| 828 |
|
| 829 |
sub TransformKohaHoldingToMarc { |
| 830 |
my ( $hash, $params ) = @_; |
| 831 |
|
| 832 |
my $record = MARC::Record->new(); |
| 833 |
SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") ); |
| 834 |
|
| 835 |
# In the next call we use the Default holdings framework, since it is considered |
| 836 |
# authoritative for Koha to Marc mappings. |
| 837 |
my $mss = C4::Biblio::GetMarcSubfieldStructure( 'HLD', { unsafe => 1 } ); # do not change framewok |
| 838 |
my $tag_hr = {}; |
| 839 |
while ( my ($kohafield, $value) = each %$hash ) { |
| 840 |
foreach my $fld ( @{ $mss->{$kohafield} } ) { |
| 841 |
my $tagfield = $fld->{tagfield}; |
| 842 |
my $tagsubfield = $fld->{tagsubfield}; |
| 843 |
next if !$tagfield; |
| 844 |
my @values = $params->{no_split} |
| 845 |
? ( $value ) |
| 846 |
: split(/\s?\|\s?/, $value, -1); |
| 847 |
foreach my $value ( @values ) { |
| 848 |
next if $value eq ''; |
| 849 |
$tag_hr->{$tagfield} //= []; |
| 850 |
push @{$tag_hr->{$tagfield}}, [($tagsubfield, $value)]; |
| 851 |
} |
| 852 |
} |
| 853 |
} |
| 854 |
foreach my $tag (sort keys %$tag_hr) { |
| 855 |
my @sfl = @{$tag_hr->{$tag}}; |
| 856 |
@sfl = sort { $a->[0] cmp $b->[0]; } @sfl; |
| 857 |
@sfl = map { @{$_}; } @sfl; |
| 858 |
# Special care for control fields: remove the subfield indication @ |
| 859 |
# and do not insert indicators. |
| 860 |
my @ind = $tag < 10 ? () : ( " ", " " ); |
| 861 |
@sfl = grep { $_ ne '@' } @sfl if $tag < 10; |
| 862 |
$record->insert_fields_ordered( MARC::Field->new($tag, @ind, @sfl) ); |
| 863 |
} |
| 864 |
return $record; |
| 865 |
} |
| 866 |
|
| 791 |
1; |
867 |
1; |
| 792 |
|
868 |
|
| 793 |
|
869 |
|