| 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 2804-2810
          override if necessary.
      
      
        Link Here | 
        
          | 2804 |  | 2811 |  | 
        
          | 2805 | sub EmbedItemsInMarcBiblio { | 2812 | sub EmbedItemsInMarcBiblio { | 
        
          | 2806 |     my ($params) = @_; | 2813 |     my ($params) = @_; | 
          
            
              | 2807 |     my ($marc, $biblionumber, $itemnumbers, $opac, $borcat); | 2814 |     my ($marc, $biblionumber, $itemnumbers, $use_hidingrules, $borcat); | 
        
          | 2808 |     $marc = $params->{marc_record}; | 2815 |     $marc = $params->{marc_record}; | 
        
          | 2809 |     if ( !$marc ) { | 2816 |     if ( !$marc ) { | 
        
          | 2810 |         carp 'EmbedItemsInMarcBiblio: No MARC record passed'; | 2817 |         carp 'EmbedItemsInMarcBiblio: No MARC record passed'; | 
  
    | Lines 2812-2860
          sub EmbedItemsInMarcBiblio {
      
      
        Link Here | 
        
          | 2812 |     } | 2819 |     } | 
        
          | 2813 |     $biblionumber = $params->{biblionumber}; | 2820 |     $biblionumber = $params->{biblionumber}; | 
        
          | 2814 |     $itemnumbers = $params->{item_numbers}; | 2821 |     $itemnumbers = $params->{item_numbers}; | 
          
            
              | 2815 |     $opac = $params->{opac}; | 2822 |     $use_hidingrules = $params->{opac}; | 
        
          | 2816 |     $borcat = $params->{borcat} // q{}; | 2823 |     $borcat = $params->{borcat} // q{}; | 
        
          | 2817 |  | 2824 |  | 
        
          | 2818 |     $itemnumbers = [] unless defined $itemnumbers; | 2825 |     $itemnumbers = [] unless defined $itemnumbers; | 
        
          | 2819 |  | 2826 |  | 
          
            
              | 2820 |     my $frameworkcode = GetFrameworkCode($biblionumber); | 2827 |     _strip_item_fields($marc); | 
            
              | 2821 |     _strip_item_fields($marc, $frameworkcode); |  |  | 
        
          | 2822 |  | 2828 |  | 
          
            
              | 2823 |     # ... and embed the current items | 2829 |     my $hidingrules = {}; | 
            
              | 2824 |     my $dbh = C4::Context->dbh; | 2830 |     if ($use_hidingrules && $borcat && !UseHidingRulesWithBorrowerCategory($borcat)) { | 
            
              | 2825 |     my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?"); | 2831 |         # don't hide anything from this borrower category | 
            
              | 2826 |     $sth->execute($biblionumber); | 2832 |         $use_hidingrules = 0; | 
            
              | 2827 |     my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); | 2833 |     } | 
        
          | 2828 |  | 2834 |  | 
          
            
              | 2829 |     my @item_fields; # Array holding the actual MARC data for items to be included. | 2835 |     my $yaml = $use_hidingrules ? C4::Context->preference('OpacHiddenItems') : ''; | 
            
              | 2830 |     my @items;       # Array holding items which are both in the list (sitenumbers) | 2836 |     if ( $yaml =~ /\S/ ) { | 
            
              | 2831 |                      # and on this biblionumber | 2837 |         $yaml = "$yaml\n\n"; # YAML is anal on ending \n. Surplus does not hurt | 
            
              |  |  | 2838 |         eval { | 
            
              | 2839 |             $hidingrules = YAML::Load($yaml); | 
            
              | 2840 |         }; | 
            
              | 2841 |         if ($@) { | 
            
              | 2842 |             carp "Unable to parse OpacHiddenItems syspref : $@"; | 
            
              | 2843 |         } | 
            
              | 2844 |     } | 
        
          | 2832 |  | 2845 |  | 
          
            
              | 2833 |     # Flag indicating if there is potential hiding. | 2846 |     my $item_fields = C4::Items::GetMarcItemFields( $biblionumber, $itemnumbers, $hidingrules ); | 
            
              | 2834 |     my $opachiddenitems = $opac |  |  | 
            
              | 2835 |       && ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ ); | 
        
          | 2836 |  | 2847 |  | 
          
            
              | 2837 |     require C4::Items; | 2848 |     $marc->append_fields(@$item_fields) if ( @$item_fields ); | 
            
              | 2838 |     while ( my ($itemnumber) = $sth->fetchrow_array ) { |  |  | 
            
              | 2839 |         next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers; | 
            
              | 2840 |         my $i = $opachiddenitems ? C4::Items::GetItem($itemnumber) : undef; | 
            
              | 2841 |         push @items, { itemnumber => $itemnumber, item => $i }; | 
            
              | 2842 |     } | 
            
              | 2843 |     my @items2pass = map { $_->{item} } @items; | 
            
              | 2844 |     my @hiddenitems = | 
            
              | 2845 |       $opachiddenitems | 
            
              | 2846 |       ? C4::Items::GetHiddenItemnumbers({ | 
            
              | 2847 |             items  => \@items2pass, | 
            
              | 2848 |             borcat => $borcat }) | 
            
              | 2849 |       : (); | 
            
              | 2850 |     # Convert to a hash for quick searching | 
            
              | 2851 |     my %hiddenitems = map { $_ => 1 } @hiddenitems; | 
            
              | 2852 |     foreach my $itemnumber ( map { $_->{itemnumber} } @items ) { | 
            
              | 2853 |         next if $hiddenitems{$itemnumber}; | 
            
              | 2854 |         my $item_marc = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); | 
            
              | 2855 |         push @item_fields, $item_marc->field($itemtag); | 
            
              | 2856 |     } | 
            
              | 2857 |     $marc->append_fields(@item_fields); | 
        
          | 2858 | } | 2849 | } | 
        
          | 2859 |  | 2850 |  | 
        
          | 2860 | =head1 INTERNAL FUNCTIONS | 2851 | =head1 INTERNAL FUNCTIONS |