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