Lines 291-297
sub ModBiblio {
Link Here
|
291 |
|
291 |
|
292 |
$frameworkcode = "" if !$frameworkcode || $frameworkcode eq "Default"; # XXX |
292 |
$frameworkcode = "" if !$frameworkcode || $frameworkcode eq "Default"; # XXX |
293 |
|
293 |
|
294 |
_strip_item_fields($record, $frameworkcode); |
294 |
_strip_item_fields($record); |
295 |
|
295 |
|
296 |
# update biblionumber and biblioitemnumber in MARC |
296 |
# update biblionumber and biblioitemnumber in MARC |
297 |
# FIXME - this is assuming a 1 to 1 relationship between |
297 |
# FIXME - this is assuming a 1 to 1 relationship between |
Lines 325-331
sub ModBiblio {
Link Here
|
325 |
|
325 |
|
326 |
=head2 _strip_item_fields |
326 |
=head2 _strip_item_fields |
327 |
|
327 |
|
328 |
_strip_item_fields($record, $frameworkcode) |
328 |
_strip_item_fields($record) |
329 |
|
329 |
|
330 |
Utility routine to remove item tags from a |
330 |
Utility routine to remove item tags from a |
331 |
MARC bib. |
331 |
MARC bib. |
Lines 334-342
MARC bib.
Link Here
|
334 |
|
334 |
|
335 |
sub _strip_item_fields { |
335 |
sub _strip_item_fields { |
336 |
my $record = shift; |
336 |
my $record = shift; |
337 |
my $frameworkcode = shift; |
|
|
338 |
# get the items before and append them to the biblio before updating the record, atm we just have the biblio |
337 |
# get the items before and append them to the biblio before updating the record, atm we just have the biblio |
339 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); |
338 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" ); |
340 |
|
339 |
|
341 |
# delete any item fields from incoming record to avoid |
340 |
# delete any item fields from incoming record to avoid |
342 |
# duplication or incorrect data - use AddItem() or ModItem() |
341 |
# duplication or incorrect data - use AddItem() or ModItem() |
Lines 1076-1089
sub GetMarcSubfieldStructure {
Link Here
|
1076 |
sub GetMarcFromKohaField { |
1075 |
sub GetMarcFromKohaField { |
1077 |
my ( $kohafield ) = @_; |
1076 |
my ( $kohafield ) = @_; |
1078 |
return unless $kohafield; |
1077 |
return unless $kohafield; |
1079 |
# The next call uses the Default framework since it is AUTHORITATIVE |
1078 |
|
1080 |
# for all Koha to MARC mappings. |
1079 |
my $cache = Koha::Caches->get_instance(); |
1081 |
my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework |
1080 |
my $cache_key = "MarcFromKohaField-$kohafield"; |
1082 |
my @retval; |
1081 |
my $cached = $cache->get_from_cache($cache_key); |
1083 |
foreach( @{ $mss->{$kohafield} } ) { |
1082 |
if ( !defined $cached ) { |
1084 |
push @retval, $_->{tagfield}, $_->{tagsubfield}; |
1083 |
# The next call uses the Default framework since it is AUTHORITATIVE |
1085 |
} |
1084 |
# for all Koha to MARC mappings. |
1086 |
return wantarray ? @retval : ( @retval ? $retval[0] : undef ); |
1085 |
my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework |
|
|
1086 |
my @retval; |
1087 |
foreach( @{ $mss->{$kohafield} } ) { |
1088 |
push @retval, $_->{tagfield}, $_->{tagsubfield}; |
1089 |
} |
1090 |
$cached = \@retval; |
1091 |
$cache->set_in_cache( $cache_key, $cached ); |
1092 |
} |
1093 |
return wantarray ? @$cached : ( @$cached ? $cached->[0] : undef ); |
1087 |
} |
1094 |
} |
1088 |
|
1095 |
|
1089 |
=head2 GetMarcSubfieldStructureFromKohaField |
1096 |
=head2 GetMarcSubfieldStructureFromKohaField |
Lines 2792-2798
override if necessary.
Link Here
|
2792 |
|
2799 |
|
2793 |
sub EmbedItemsInMarcBiblio { |
2800 |
sub EmbedItemsInMarcBiblio { |
2794 |
my ($params) = @_; |
2801 |
my ($params) = @_; |
2795 |
my ($marc, $biblionumber, $itemnumbers, $opac, $borcat); |
2802 |
my ($marc, $biblionumber, $itemnumbers, $use_hidingrules, $borcat); |
2796 |
$marc = $params->{marc_record}; |
2803 |
$marc = $params->{marc_record}; |
2797 |
if ( !$marc ) { |
2804 |
if ( !$marc ) { |
2798 |
carp 'EmbedItemsInMarcBiblio: No MARC record passed'; |
2805 |
carp 'EmbedItemsInMarcBiblio: No MARC record passed'; |
Lines 2800-2848
sub EmbedItemsInMarcBiblio {
Link Here
|
2800 |
} |
2807 |
} |
2801 |
$biblionumber = $params->{biblionumber}; |
2808 |
$biblionumber = $params->{biblionumber}; |
2802 |
$itemnumbers = $params->{item_numbers}; |
2809 |
$itemnumbers = $params->{item_numbers}; |
2803 |
$opac = $params->{opac}; |
2810 |
$use_hidingrules = $params->{opac}; |
2804 |
$borcat = $params->{borcat} // q{}; |
2811 |
$borcat = $params->{borcat} // q{}; |
2805 |
|
2812 |
|
2806 |
$itemnumbers = [] unless defined $itemnumbers; |
2813 |
$itemnumbers = [] unless defined $itemnumbers; |
2807 |
|
2814 |
|
2808 |
my $frameworkcode = GetFrameworkCode($biblionumber); |
2815 |
_strip_item_fields($marc); |
2809 |
_strip_item_fields($marc, $frameworkcode); |
|
|
2810 |
|
2816 |
|
2811 |
# ... and embed the current items |
2817 |
my $hidingrules = {}; |
2812 |
my $dbh = C4::Context->dbh; |
2818 |
if ($use_hidingrules && $borcat && !UseHidingRulesWithBorrowerCategory($borcat)) { |
2813 |
my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?"); |
2819 |
# don't hide anything from this borrower category |
2814 |
$sth->execute($biblionumber); |
2820 |
$use_hidingrules = 0; |
2815 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); |
2821 |
} |
2816 |
|
2822 |
|
2817 |
my @item_fields; # Array holding the actual MARC data for items to be included. |
2823 |
my $yaml = $use_hidingrules ? C4::Context->preference('OpacHiddenItems') : ''; |
2818 |
my @items; # Array holding items which are both in the list (sitenumbers) |
2824 |
if ( $yaml =~ /\S/ ) { |
2819 |
# and on this biblionumber |
2825 |
$yaml = "$yaml\n\n"; # YAML is anal on ending \n. Surplus does not hurt |
|
|
2826 |
eval { |
2827 |
$hidingrules = YAML::Load($yaml); |
2828 |
}; |
2829 |
if ($@) { |
2830 |
carp "Unable to parse OpacHiddenItems syspref : $@"; |
2831 |
} |
2832 |
} |
2820 |
|
2833 |
|
2821 |
# Flag indicating if there is potential hiding. |
2834 |
my $item_fields = C4::Items::GetMarcItemFields( $biblionumber, $itemnumbers, $hidingrules ); |
2822 |
my $opachiddenitems = $opac |
|
|
2823 |
&& ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ ); |
2824 |
|
2835 |
|
2825 |
require C4::Items; |
2836 |
$marc->append_fields(@$item_fields) if ( @$item_fields ); |
2826 |
while ( my ($itemnumber) = $sth->fetchrow_array ) { |
|
|
2827 |
next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers; |
2828 |
my $i = $opachiddenitems ? C4::Items::GetItem($itemnumber) : undef; |
2829 |
push @items, { itemnumber => $itemnumber, item => $i }; |
2830 |
} |
2831 |
my @items2pass = map { $_->{item} } @items; |
2832 |
my @hiddenitems = |
2833 |
$opachiddenitems |
2834 |
? C4::Items::GetHiddenItemnumbers({ |
2835 |
items => \@items2pass, |
2836 |
borcat => $borcat }) |
2837 |
: (); |
2838 |
# Convert to a hash for quick searching |
2839 |
my %hiddenitems = map { $_ => 1 } @hiddenitems; |
2840 |
foreach my $itemnumber ( map { $_->{itemnumber} } @items ) { |
2841 |
next if $hiddenitems{$itemnumber}; |
2842 |
my $item_marc = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); |
2843 |
push @item_fields, $item_marc->field($itemtag); |
2844 |
} |
2845 |
$marc->append_fields(@item_fields); |
2846 |
} |
2837 |
} |
2847 |
|
2838 |
|
2848 |
=head1 INTERNAL FUNCTIONS |
2839 |
=head1 INTERNAL FUNCTIONS |