| Lines 1109-1151
          sub GetMarcSubfieldStructure {
      
      
        Link Here | 
        
          | 1109 |  | 1109 |  | 
        
          | 1110 | =head2 GetMarcFromKohaField | 1110 | =head2 GetMarcFromKohaField | 
        
          | 1111 |  | 1111 |  | 
          
            
              | 1112 |   ($MARCfield,$MARCsubfield)=GetMarcFromKohaField($kohafield,$frameworkcode); | 1112 |     ( $field,$subfield ) = GetMarcFromKohaField( $kohafield ); | 
            
              |  |  | 1113 |     @fields = GetMarcFromKohaField( $kohafield ); | 
            
              | 1114 |     $field = GetMarcFromKohaField( $kohafield ); | 
        
          | 1113 |  | 1115 |  | 
          
            
              | 1114 | Returns the MARC fields & subfields mapped to the koha field  | 1116 |     Returns the MARC fields & subfields mapped to $kohafield. | 
            
              | 1115 | for the given frameworkcode or default framework if $frameworkcode is missing | 1117 |     Since the Default framework is considered as authoritative for such | 
            
              |  |  | 1118 |     mappings, the former frameworkcode parameter is obsoleted. | 
            
              | 1119 |  | 
            
              | 1120 |     In list context all mappings are returned; there can be multiple | 
            
              | 1121 |     mappings. Note that in the above example you could miss a second | 
            
              | 1122 |     mappings in the first call. | 
            
              | 1123 |     In scalar context only the field tag of the first mapping is returned. | 
        
          | 1116 |  | 1124 |  | 
        
          | 1117 | =cut | 1125 | =cut | 
        
          | 1118 |  | 1126 |  | 
        
          | 1119 | sub GetMarcFromKohaField { | 1127 | sub GetMarcFromKohaField { | 
          
            
              | 1120 |     my ( $kohafield, $frameworkcode ) = @_; | 1128 |     my ( $kohafield ) = @_; | 
            
              | 1121 |     return (0, undef) unless $kohafield; | 1129 |     return unless $kohafield; | 
            
              | 1122 |     my $mss = GetMarcSubfieldStructure( $frameworkcode ); | 1130 |     # The next call uses the Default framework since it is AUTHORITATIVE | 
            
              |  |  | 1131 |     # for all Koha to MARC mappings. | 
            
              | 1132 |     my $mss = GetMarcSubfieldStructure( '' ); # Do not change framework | 
        
          | 1123 |     my @retval; | 1133 |     my @retval; | 
        
          | 1124 |     foreach( @{ $mss->{$kohafield} } ) { | 1134 |     foreach( @{ $mss->{$kohafield} } ) { | 
        
          | 1125 |         push @retval, $_->{tagfield}, $_->{tagsubfield}; | 1135 |         push @retval, $_->{tagfield}, $_->{tagsubfield}; | 
        
          | 1126 |     } | 1136 |     } | 
          
            
              | 1127 |     return wantarray ? @retval : $retval[0]; | 1137 |     return wantarray ? @retval : ( @retval ? $retval[0] : undef ); | 
        
          | 1128 | } | 1138 | } | 
        
          | 1129 |  | 1139 |  | 
        
          | 1130 | =head2 GetMarcSubfieldStructureFromKohaField | 1140 | =head2 GetMarcSubfieldStructureFromKohaField | 
        
          | 1131 |  | 1141 |  | 
          
            
              | 1132 |     my $subfield_structure = &GetMarcSubfieldStructureFromKohaField($kohafield, $frameworkcode); | 1142 |     my $str = GetMarcSubfieldStructureFromKohaField( $kohafield ); | 
            
              | 1133 |  |  |  | 
            
              | 1134 | Returns a hashref where keys are marc_subfield_structure column names for the | 
            
              | 1135 | row where kohafield=$kohafield for the given framework code. | 
            
              | 1136 | In list context returns a list of those hashrefs in case duplicate Koha to | 
            
              | 1137 | MARC mappings exist. | 
        
          | 1138 |  | 1143 |  | 
          
            
              | 1139 | $frameworkcode is optional. If not given, then the default framework is used. | 1144 |     Returns marc subfield structure information for $kohafield. | 
            
              |  |  | 1145 |     The Default framework is used, since it is authoritative for kohafield | 
            
              | 1146 |     mappings. | 
            
              | 1147 |     In list context returns a list of all hashrefs, since there may be | 
            
              | 1148 |     multiple mappings. In scalar context the first hashref is returned. | 
        
          | 1140 |  | 1149 |  | 
        
          | 1141 | =cut | 1150 | =cut | 
        
          | 1142 |  | 1151 |  | 
        
          | 1143 | sub GetMarcSubfieldStructureFromKohaField { | 1152 | sub GetMarcSubfieldStructureFromKohaField { | 
          
            
              | 1144 |     my ( $kohafield, $frameworkcode ) = @_; | 1153 |     my ( $kohafield ) = @_; | 
        
          | 1145 |  | 1154 |  | 
        
          | 1146 |     return unless $kohafield; | 1155 |     return unless $kohafield; | 
        
          | 1147 |  | 1156 |  | 
          
            
              | 1148 |     my $mss = GetMarcSubfieldStructure( $frameworkcode ); | 1157 |     # The next call uses the Default framework since it is AUTHORITATIVE | 
            
              |  |  | 1158 |     # for all Koha to MARC mappings. | 
            
              | 1159 |     my $mss = GetMarcSubfieldStructure(''); # Do not change framework | 
        
          | 1149 |     return unless $mss->{$kohafield}; | 1160 |     return unless $mss->{$kohafield}; | 
        
          | 1150 |     return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0]; | 1161 |     return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0]; | 
        
          | 1151 | } | 1162 | } | 
  
    | Lines 2158-2181
          sub GetFrameworkCode {
      
      
        Link Here | 
        
          | 2158 |  | 2169 |  | 
        
          | 2159 | =head2 TransformKohaToMarc | 2170 | =head2 TransformKohaToMarc | 
        
          | 2160 |  | 2171 |  | 
          
            
              | 2161 |     $record = TransformKohaToMarc( $hash ) | 2172 |     $record = TransformKohaToMarc( $hash [, $params ]  ) | 
        
          | 2162 |  | 2173 |  | 
          
            
              | 2163 | This function builds partial MARC::Record from a hash | 2174 | This function builds a (partial) MARC::Record from a hash. | 
            
              | 2164 | Hash entries can be from biblio or biblioitems. | 2175 | Hash entries can be from biblio, biblioitems or items. | 
            
              |  |  | 2176 | The params hash includes the parameter no_split used in C4::Items. | 
        
          | 2165 |  | 2177 |  | 
        
          | 2166 | This function is called in acquisition module, to create a basic catalogue | 2178 | This function is called in acquisition module, to create a basic catalogue | 
          
            
              | 2167 | entry from user entry | 2179 | entry from user entry. | 
        
          | 2168 |  | 2180 |  | 
        
          | 2169 | =cut | 2181 | =cut | 
        
          | 2170 |  | 2182 |  | 
        
          | 2171 |  | 2183 |  | 
        
          | 2172 | sub TransformKohaToMarc { | 2184 | sub TransformKohaToMarc { | 
          
            
              | 2173 |     my ( $hash, $frameworkcode, $params ) = @_; | 2185 |     my ( $hash, $params ) = @_; | 
        
          | 2174 |     my $record = MARC::Record->new(); | 2186 |     my $record = MARC::Record->new(); | 
        
          | 2175 |     SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") ); | 2187 |     SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") ); | 
          
            
              | 2176 |     # NOTE: Many older calls do not include a frameworkcode. In that case | 2188 |  | 
            
              | 2177 |     # we default to Default framework. | 2189 |     # In the next call we use the Default framework, since it is considered | 
            
              | 2178 |     my $mss = GetMarcSubfieldStructure( $frameworkcode//'' ); | 2190 |     # authoritative for Koha to Marc mappings. | 
            
              |  |  | 2191 |     my $mss = GetMarcSubfieldStructure( '' ); # do not change framework | 
        
          | 2179 |     my $tag_hr = {}; | 2192 |     my $tag_hr = {}; | 
        
          | 2180 |     while ( my ($kohafield, $value) = each %$hash ) { | 2193 |     while ( my ($kohafield, $value) = each %$hash ) { | 
        
          | 2181 |         foreach my $fld ( @{ $mss->{$kohafield} } ) { | 2194 |         foreach my $fld ( @{ $mss->{$kohafield} } ) { | 
  
    | Lines 2560-2578
          sub TransformHtmlToMarc {
      
      
        Link Here | 
        
          | 2560 |  | 2573 |  | 
        
          | 2561 | =head2 TransformMarcToKoha | 2574 | =head2 TransformMarcToKoha | 
        
          | 2562 |  | 2575 |  | 
          
            
              | 2563 |   $result = TransformMarcToKoha( $record, $frameworkcode, $limit ) | 2576 |     $result = TransformMarcToKoha( $record, undef, $limit ) | 
        
          | 2564 |  | 2577 |  | 
        
          | 2565 | Extract data from a MARC bib record into a hashref representing | 2578 | Extract data from a MARC bib record into a hashref representing | 
          
            
              | 2566 | Koha biblio, biblioitems, and items fields.  | 2579 | Koha biblio, biblioitems, and items fields. | 
        
          | 2567 |  | 2580 |  | 
        
          | 2568 | If passed an undefined record will log the error and return an empty | 2581 | If passed an undefined record will log the error and return an empty | 
          
            
              | 2569 | hash_ref | 2582 | hash_ref. | 
        
          | 2570 |  | 2583 |  | 
        
          | 2571 | =cut | 2584 | =cut | 
        
          | 2572 |  | 2585 |  | 
        
          | 2573 | sub TransformMarcToKoha { | 2586 | sub TransformMarcToKoha { | 
        
          | 2574 |     my ( $record, $frameworkcode, $limit_table ) = @_; | 2587 |     my ( $record, $frameworkcode, $limit_table ) = @_; | 
          
            
              | 2575 |     $frameworkcode //= q{}; | 2588 |     # FIXME  Parameter $frameworkcode is obsolete and will be removed | 
        
          | 2576 |     $limit_table //= q{}; | 2589 |     $limit_table //= q{}; | 
        
          | 2577 |  | 2590 |  | 
        
          | 2578 |     my $result = {}; | 2591 |     my $result = {}; | 
  
    | Lines 2586-2598
          sub TransformMarcToKoha {
      
      
        Link Here | 
        
          | 2586 |         %tables = ( items => 1 ); | 2599 |         %tables = ( items => 1 ); | 
        
          | 2587 |     } | 2600 |     } | 
        
          | 2588 |  | 2601 |  | 
          
            
              | 2589 |     my $mss = GetMarcSubfieldStructure( $frameworkcode ); | 2602 |     # The next call acknowledges Default as the authoritative framework | 
            
              |  |  | 2603 |     # for Koha to MARC mappings. | 
            
              | 2604 |     my $mss = GetMarcSubfieldStructure(''); # Do not change framework | 
        
          | 2590 |     foreach my $kohafield ( keys %{ $mss } ) { | 2605 |     foreach my $kohafield ( keys %{ $mss } ) { | 
        
          | 2591 |         my ( $table, $column ) = split /[.]/, $kohafield, 2; | 2606 |         my ( $table, $column ) = split /[.]/, $kohafield, 2; | 
        
          | 2592 |         next unless $tables{$table}; | 2607 |         next unless $tables{$table}; | 
          
            
              | 2593 |         my $val = TransformMarcToKohaOneField( | 2608 |         my $val = TransformMarcToKohaOneField( $kohafield, $record ); | 
            
              | 2594 |             $kohafield, $record, $frameworkcode, |  |  | 
            
              | 2595 |         ); | 
        
          | 2596 |         next if !defined $val; | 2609 |         next if !defined $val; | 
        
          | 2597 |         my $key = _disambiguate( $table, $column ); | 2610 |         my $key = _disambiguate( $table, $column ); | 
        
          | 2598 |         $result->{$key} = $val; | 2611 |         $result->{$key} = $val; | 
  
    | Lines 2641-2655
          sub _disambiguate {
      
      
        Link Here | 
        
          | 2641 |  | 2654 |  | 
        
          | 2642 | =head2 TransformMarcToKohaOneField | 2655 | =head2 TransformMarcToKohaOneField | 
        
          | 2643 |  | 2656 |  | 
          
            
              | 2644 |     $val = TransformMarcToKohaOneField( 'biblio.title', $marc, $frameworkcode ); | 2657 |     $val = TransformMarcToKohaOneField( 'biblio.title', $marc ); | 
            
              |  |  | 2658 |  | 
            
              | 2659 |     Note: The authoritative Default framework is used implicitly. | 
        
          | 2645 |  | 2660 |  | 
        
          | 2646 | =cut | 2661 | =cut | 
        
          | 2647 |  | 2662 |  | 
        
          | 2648 | sub TransformMarcToKohaOneField { | 2663 | sub TransformMarcToKohaOneField { | 
          
            
              | 2649 |     my ( $kohafield, $marc, $frameworkcode ) = @_; | 2664 |     my ( $kohafield, $marc ) = @_; | 
        
          | 2650 |  | 2665 |  | 
        
          | 2651 |     my ( @rv, $retval ); | 2666 |     my ( @rv, $retval ); | 
          
            
              | 2652 |     my @mss = GetMarcSubfieldStructureFromKohaField($kohafield, $frameworkcode); | 2667 |     my @mss = GetMarcSubfieldStructureFromKohaField($kohafield); | 
        
          | 2653 |     foreach my $fldhash ( @mss ) { | 2668 |     foreach my $fldhash ( @mss ) { | 
        
          | 2654 |         my $tag = $fldhash->{tagfield}; | 2669 |         my $tag = $fldhash->{tagfield}; | 
        
          | 2655 |         my $sub = $fldhash->{tagsubfield}; | 2670 |         my $sub = $fldhash->{tagsubfield}; |