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