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