Lines 310-316
sub ModBiblio {
Link Here
|
310 |
|
310 |
|
311 |
$frameworkcode = "" if !$frameworkcode || $frameworkcode eq "Default"; # XXX |
311 |
$frameworkcode = "" if !$frameworkcode || $frameworkcode eq "Default"; # XXX |
312 |
|
312 |
|
313 |
_strip_item_fields($record, $frameworkcode); |
313 |
_strip_item_fields($record); |
314 |
|
314 |
|
315 |
# update biblionumber and biblioitemnumber in MARC |
315 |
# update biblionumber and biblioitemnumber in MARC |
316 |
# FIXME - this is assuming a 1 to 1 relationship between |
316 |
# FIXME - this is assuming a 1 to 1 relationship between |
Lines 344-350
sub ModBiblio {
Link Here
|
344 |
|
344 |
|
345 |
=head2 _strip_item_fields |
345 |
=head2 _strip_item_fields |
346 |
|
346 |
|
347 |
_strip_item_fields($record, $frameworkcode) |
347 |
_strip_item_fields($record) |
348 |
|
348 |
|
349 |
Utility routine to remove item tags from a |
349 |
Utility routine to remove item tags from a |
350 |
MARC bib. |
350 |
MARC bib. |
Lines 353-361
MARC bib.
Link Here
|
353 |
|
353 |
|
354 |
sub _strip_item_fields { |
354 |
sub _strip_item_fields { |
355 |
my $record = shift; |
355 |
my $record = shift; |
356 |
my $frameworkcode = shift; |
|
|
357 |
# get the items before and append them to the biblio before updating the record, atm we just have the biblio |
356 |
# get the items before and append them to the biblio before updating the record, atm we just have the biblio |
358 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); |
357 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" ); |
359 |
|
358 |
|
360 |
# delete any item fields from incoming record to avoid |
359 |
# delete any item fields from incoming record to avoid |
361 |
# duplication or incorrect data - use AddItem() or ModItem() |
360 |
# duplication or incorrect data - use AddItem() or ModItem() |
Lines 1089-1102
sub GetMarcSubfieldStructure {
Link Here
|
1089 |
sub GetMarcFromKohaField { |
1088 |
sub GetMarcFromKohaField { |
1090 |
my ( $kohafield ) = @_; |
1089 |
my ( $kohafield ) = @_; |
1091 |
return unless $kohafield; |
1090 |
return unless $kohafield; |
1092 |
# The next call uses the Default framework since it is AUTHORITATIVE |
1091 |
|
1093 |
# for all Koha to MARC mappings. |
1092 |
my $cache = Koha::Caches->get_instance(); |
1094 |
my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework |
1093 |
my $cache_key = "MarcFromKohaField-$kohafield"; |
1095 |
my @retval; |
1094 |
my $cached = $cache->get_from_cache($cache_key); |
1096 |
foreach( @{ $mss->{$kohafield} } ) { |
1095 |
if ( !defined $cached ) { |
1097 |
push @retval, $_->{tagfield}, $_->{tagsubfield}; |
1096 |
# The next call uses the Default framework since it is AUTHORITATIVE |
1098 |
} |
1097 |
# for all Koha to MARC mappings. |
1099 |
return wantarray ? @retval : ( @retval ? $retval[0] : undef ); |
1098 |
my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework |
|
|
1099 |
my @retval; |
1100 |
foreach( @{ $mss->{$kohafield} } ) { |
1101 |
push @retval, $_->{tagfield}, $_->{tagsubfield}; |
1102 |
} |
1103 |
$cached = \@retval; |
1104 |
$cache->set_in_cache( $cache_key, $cached ); |
1105 |
} |
1106 |
return wantarray ? @$cached : ( @$cached ? $cached->[0] : undef ); |
1100 |
} |
1107 |
} |
1101 |
|
1108 |
|
1102 |
=head2 GetMarcSubfieldStructureFromKohaField |
1109 |
=head2 GetMarcSubfieldStructureFromKohaField |
Lines 2792-2827
sub EmbedItemsInMarcBiblio {
Link Here
|
2792 |
|
2799 |
|
2793 |
$itemnumbers = [] unless defined $itemnumbers; |
2800 |
$itemnumbers = [] unless defined $itemnumbers; |
2794 |
|
2801 |
|
2795 |
my $frameworkcode = GetFrameworkCode($biblionumber); |
2802 |
_strip_item_fields($marc); |
2796 |
_strip_item_fields($marc, $frameworkcode); |
2803 |
|
|
|
2804 |
my $hidingrules = {}; |
2805 |
my $yaml = $opac ? C4::Context->preference('OpacHiddenItems') : ''; |
2806 |
if ( $yaml =~ /\S/ ) { |
2807 |
$yaml = "$yaml\n\n"; # YAML is anal on ending \n. Surplus does not hurt |
2808 |
eval { |
2809 |
$hidingrules = YAML::Load($yaml); |
2810 |
}; |
2811 |
if ($@) { |
2812 |
carp "Unable to parse OpacHiddenItems syspref : $@"; |
2813 |
} |
2814 |
} |
2797 |
|
2815 |
|
2798 |
# ... and embed the current items |
|
|
2799 |
my $dbh = C4::Context->dbh; |
2800 |
my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?"); |
2801 |
$sth->execute($biblionumber); |
2802 |
my @item_fields; |
2803 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); |
2804 |
my @items; |
2805 |
my $opachiddenitems = $opac |
2806 |
&& ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ ); |
2807 |
require C4::Items; |
2816 |
require C4::Items; |
2808 |
while ( my ($itemnumber) = $sth->fetchrow_array ) { |
2817 |
|
2809 |
next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers; |
2818 |
my $item_fields = C4::Items::GetMarcItemFields( $biblionumber, $itemnumbers, $hidingrules ); |
2810 |
my $i = $opachiddenitems ? C4::Items::GetItem($itemnumber) : undef; |
2819 |
|
2811 |
push @items, { itemnumber => $itemnumber, item => $i }; |
2820 |
$marc->append_fields(@$item_fields) if ( @$item_fields ); |
2812 |
} |
|
|
2813 |
my @hiddenitems = |
2814 |
$opachiddenitems |
2815 |
? C4::Items::GetHiddenItemnumbers( map { $_->{item} } @items ) |
2816 |
: (); |
2817 |
# Convert to a hash for quick searching |
2818 |
my %hiddenitems = map { $_ => 1 } @hiddenitems; |
2819 |
foreach my $itemnumber ( map { $_->{itemnumber} } @items ) { |
2820 |
next if $hiddenitems{$itemnumber}; |
2821 |
my $item_marc = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); |
2822 |
push @item_fields, $item_marc->field($itemtag); |
2823 |
} |
2824 |
$marc->append_fields(@item_fields); |
2825 |
} |
2821 |
} |
2826 |
|
2822 |
|
2827 |
=head1 INTERNAL FUNCTIONS |
2823 |
=head1 INTERNAL FUNCTIONS |