| 
      
            Lines 1105-1147
          sub GetMarcSubfieldStructure {
      
      
        Link Here
      
     | 
  
        
          | 1105 | 
           | 
          1105 | 
           | 
        
        
          | 1106 | 
          =head2 GetMarcFromKohaField  | 
          1106 | 
          =head2 GetMarcFromKohaField  | 
        
        
          | 1107 | 
           | 
          1107 | 
           | 
        
          
            
              | 1108 | 
                ($MARCfield,$MARCsubfield)=GetMarcFromKohaField($kohafield,$frameworkcode);  | 
              1108 | 
                  ( $field,$subfield ) = GetMarcFromKohaField( $kohafield );  | 
            
            
               | 
               | 
              1109 | 
                  @fields = GetMarcFromKohaField( $kohafield );  | 
            
            
              | 1110 | 
                  $field = GetMarcFromKohaField( $kohafield );  | 
            
        
          | 1109 | 
           | 
          1111 | 
           | 
        
          
            
              | 1110 | 
              Returns the MARC fields & subfields mapped to the koha field   | 
              1112 | 
                  Returns the MARC fields & subfields mapped to $kohafield.  | 
            
            
              | 1111 | 
              for the given frameworkcode or default framework if $frameworkcode is missing  | 
              1113 | 
                  Since the Default framework is considered as authoritative for such  | 
            
            
               | 
               | 
              1114 | 
                  mappings, the former frameworkcode parameter is obsoleted.  | 
            
            
              | 1115 | 
               | 
            
            
              | 1116 | 
                  In list context all mappings are returned; there can be multiple  | 
            
            
              | 1117 | 
                  mappings. Note that in the above example you could miss a second  | 
            
            
              | 1118 | 
                  mappings in the first call.  | 
            
            
              | 1119 | 
                  In scalar context only the field tag of the first mapping is returned.  | 
            
        
          | 1112 | 
           | 
          1120 | 
           | 
        
        
          | 1113 | 
          =cut  | 
          1121 | 
          =cut  | 
        
        
          | 1114 | 
           | 
          1122 | 
           | 
        
        
          | 1115 | 
          sub GetMarcFromKohaField { | 
          1123 | 
          sub GetMarcFromKohaField { | 
        
          
            
              | 1116 | 
                  my ( $kohafield, $frameworkcode ) = @_;  | 
              1124 | 
                  my ( $kohafield ) = @_;  | 
            
            
              | 1117 | 
                  return (0, undef) unless $kohafield;  | 
              1125 | 
                  return unless $kohafield;  | 
            
            
              | 1118 | 
                  my $mss = GetMarcSubfieldStructure( $frameworkcode );  | 
              1126 | 
                  # The next call uses the Default framework since it is AUTHORITATIVE  | 
            
            
               | 
               | 
              1127 | 
                  # for all Koha to MARC mappings.  | 
            
            
              | 1128 | 
                  my $mss = GetMarcSubfieldStructure( '' ); # Do not change framework  | 
            
        
          | 1119 | 
              my @retval;  | 
          1129 | 
              my @retval;  | 
        
        
          | 1120 | 
              foreach( @{ $mss->{$kohafield} } ) { | 
          1130 | 
              foreach( @{ $mss->{$kohafield} } ) { | 
        
        
          | 1121 | 
                  push @retval, $_->{tagfield}, $_->{tagsubfield}; | 
          1131 | 
                  push @retval, $_->{tagfield}, $_->{tagsubfield}; | 
        
        
          | 1122 | 
              }  | 
          1132 | 
              }  | 
        
          
            
              | 1123 | 
                  return wantarray ? @retval : $retval[0];  | 
              1133 | 
                  return wantarray ? @retval : ( @retval ? $retval[0] : undef );  | 
            
        
          | 1124 | 
          }  | 
          1134 | 
          }  | 
        
        
          | 1125 | 
           | 
          1135 | 
           | 
        
        
          | 1126 | 
          =head2 GetMarcSubfieldStructureFromKohaField  | 
          1136 | 
          =head2 GetMarcSubfieldStructureFromKohaField  | 
        
        
          | 1127 | 
           | 
          1137 | 
           | 
        
          
            
              | 1128 | 
                  my $subfield_structure = &GetMarcSubfieldStructureFromKohaField($kohafield, $frameworkcode);  | 
              1138 | 
                  my $str = GetMarcSubfieldStructureFromKohaField( $kohafield );  | 
            
            
              | 1129 | 
               | 
               | 
               | 
            
            
              | 1130 | 
              Returns a hashref where keys are marc_subfield_structure column names for the  | 
            
            
              | 1131 | 
              row where kohafield=$kohafield for the given framework code.  | 
            
            
              | 1132 | 
              In list context returns a list of those hashrefs in case duplicate Koha to  | 
            
            
              | 1133 | 
              MARC mappings exist.  | 
            
        
          | 1134 | 
           | 
          1139 | 
           | 
        
          
            
              | 1135 | 
              $frameworkcode is optional. If not given, then the default framework is used.  | 
              1140 | 
                  Returns marc subfield structure information for $kohafield.  | 
            
            
               | 
               | 
              1141 | 
                  The Default framework is used, since it is authoritative for kohafield  | 
            
            
              | 1142 | 
                  mappings.  | 
            
            
              | 1143 | 
                  In list context returns a list of all hashrefs, since there may be  | 
            
            
              | 1144 | 
                  multiple mappings. In scalar context the first hashref is returned.  | 
            
        
          | 1136 | 
           | 
          1145 | 
           | 
        
        
          | 1137 | 
          =cut  | 
          1146 | 
          =cut  | 
        
        
          | 1138 | 
           | 
          1147 | 
           | 
        
        
          | 1139 | 
          sub GetMarcSubfieldStructureFromKohaField { | 
          1148 | 
          sub GetMarcSubfieldStructureFromKohaField { | 
        
          
            
              | 1140 | 
                  my ( $kohafield, $frameworkcode ) = @_;  | 
              1149 | 
                  my ( $kohafield ) = @_;  | 
            
        
          | 1141 | 
           | 
          1150 | 
           | 
        
        
          | 1142 | 
              return unless $kohafield;  | 
          1151 | 
              return unless $kohafield;  | 
        
        
          | 1143 | 
           | 
          1152 | 
           | 
        
          
            
              | 1144 | 
                  my $mss = GetMarcSubfieldStructure( $frameworkcode );  | 
              1153 | 
                  # The next call uses the Default framework since it is AUTHORITATIVE  | 
            
            
               | 
               | 
              1154 | 
                  # for all Koha to MARC mappings.  | 
            
            
              | 1155 | 
                  my $mss = GetMarcSubfieldStructure(''); # Do not change framework | 
            
        
          | 1145 | 
              return unless $mss->{$kohafield}; | 
          1156 | 
              return unless $mss->{$kohafield}; | 
        
        
          | 1146 | 
              return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0]; | 
          1157 | 
              return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0]; | 
        
        
          | 1147 | 
          }  | 
          1158 | 
          }  | 
        
  
    | 
      
            Lines 2140-2163
          sub GetFrameworkCode {
      
      
        Link Here
      
     | 
  
        
          | 2140 | 
           | 
          2151 | 
           | 
        
        
          | 2141 | 
          =head2 TransformKohaToMarc  | 
          2152 | 
          =head2 TransformKohaToMarc  | 
        
        
          | 2142 | 
           | 
          2153 | 
           | 
        
          
            
              | 2143 | 
                  $record = TransformKohaToMarc( $hash )  | 
              2154 | 
                  $record = TransformKohaToMarc( $hash [, $params ]  )  | 
            
        
          | 2144 | 
           | 
          2155 | 
           | 
        
          
            
              | 2145 | 
              This function builds partial MARC::Record from a hash  | 
              2156 | 
              This function builds a (partial) MARC::Record from a hash.  | 
            
            
              | 2146 | 
              Hash entries can be from biblio or biblioitems.  | 
              2157 | 
              Hash entries can be from biblio, biblioitems or items.  | 
            
            
               | 
               | 
              2158 | 
              The params hash includes the parameter no_split used in C4::Items.  | 
            
        
          | 2147 | 
           | 
          2159 | 
           | 
        
        
          | 2148 | 
          This function is called in acquisition module, to create a basic catalogue  | 
          2160 | 
          This function is called in acquisition module, to create a basic catalogue  | 
        
          
            
              | 2149 | 
              entry from user entry  | 
              2161 | 
              entry from user entry.  | 
            
        
          | 2150 | 
           | 
          2162 | 
           | 
        
        
          | 2151 | 
          =cut  | 
          2163 | 
          =cut  | 
        
        
          | 2152 | 
           | 
          2164 | 
           | 
        
        
          | 2153 | 
           | 
          2165 | 
           | 
        
        
          | 2154 | 
          sub TransformKohaToMarc { | 
          2166 | 
          sub TransformKohaToMarc { | 
        
          
            
              | 2155 | 
                  my ( $hash, $frameworkcode, $params ) = @_;  | 
              2167 | 
                  my ( $hash, $params ) = @_;  | 
            
        
          | 2156 | 
              my $record = MARC::Record->new();  | 
          2168 | 
              my $record = MARC::Record->new();  | 
        
        
          | 2157 | 
              SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") ); | 
          2169 | 
              SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") ); | 
        
          
            
              | 2158 | 
                  # NOTE: Many older calls do not include a frameworkcode. In that case  | 
              2170 | 
               | 
            
            
              | 2159 | 
                  # we default to Default framework.  | 
              2171 | 
                  # In the next call we use the Default framework, since it is considered  | 
            
            
              | 2160 | 
                  my $mss = GetMarcSubfieldStructure( $frameworkcode//'' );  | 
              2172 | 
                  # authoritative for Koha to Marc mappings.  | 
            
            
               | 
               | 
              2173 | 
                  my $mss = GetMarcSubfieldStructure( '' ); # do not change framework  | 
            
        
          | 2161 | 
              my $tag_hr = {}; | 
          2174 | 
              my $tag_hr = {}; | 
        
        
          | 2162 | 
              while ( my ($kohafield, $value) = each %$hash ) { | 
          2175 | 
              while ( my ($kohafield, $value) = each %$hash ) { | 
        
        
          | 2163 | 
                  foreach my $fld ( @{ $mss->{$kohafield} } ) { | 
          2176 | 
                  foreach my $fld ( @{ $mss->{$kohafield} } ) { | 
        
  
    | 
      
            Lines 2542-2560
          sub TransformHtmlToMarc {
      
      
        Link Here
      
     | 
  
        
          | 2542 | 
           | 
          2555 | 
           | 
        
        
          | 2543 | 
          =head2 TransformMarcToKoha  | 
          2556 | 
          =head2 TransformMarcToKoha  | 
        
        
          | 2544 | 
           | 
          2557 | 
           | 
        
          
            
              | 2545 | 
                $result = TransformMarcToKoha( $record, $frameworkcode, $limit )  | 
              2558 | 
                  $result = TransformMarcToKoha( $record, undef, $limit )  | 
            
        
          | 2546 | 
           | 
          2559 | 
           | 
        
        
          | 2547 | 
          Extract data from a MARC bib record into a hashref representing  | 
          2560 | 
          Extract data from a MARC bib record into a hashref representing  | 
        
          
            
              | 2548 | 
              Koha biblio, biblioitems, and items fields.   | 
              2561 | 
              Koha biblio, biblioitems, and items fields.  | 
            
        
          | 2549 | 
           | 
          2562 | 
           | 
        
        
          | 2550 | 
          If passed an undefined record will log the error and return an empty  | 
          2563 | 
          If passed an undefined record will log the error and return an empty  | 
        
          
            
              | 2551 | 
              hash_ref  | 
              2564 | 
              hash_ref.  | 
            
        
          | 2552 | 
           | 
          2565 | 
           | 
        
        
          | 2553 | 
          =cut  | 
          2566 | 
          =cut  | 
        
        
          | 2554 | 
           | 
          2567 | 
           | 
        
        
          | 2555 | 
          sub TransformMarcToKoha { | 
          2568 | 
          sub TransformMarcToKoha { | 
        
        
          | 2556 | 
              my ( $record, $frameworkcode, $limit_table ) = @_;  | 
          2569 | 
              my ( $record, $frameworkcode, $limit_table ) = @_;  | 
        
          
            
              | 2557 | 
                  $frameworkcode //= q{}; | 
              2570 | 
                  # FIXME  Parameter $frameworkcode is obsolete and will be removed  | 
            
        
          | 2558 | 
              $limit_table //= q{}; | 
          2571 | 
              $limit_table //= q{}; | 
        
        
          | 2559 | 
           | 
          2572 | 
           | 
        
        
          | 2560 | 
              my $result = {}; | 
          2573 | 
              my $result = {}; | 
        
  
    | 
      
            Lines 2568-2580
          sub TransformMarcToKoha {
      
      
        Link Here
      
     | 
  
        
          | 2568 | 
                  %tables = ( items => 1 );  | 
          2581 | 
                  %tables = ( items => 1 );  | 
        
        
          | 2569 | 
              }  | 
          2582 | 
              }  | 
        
        
          | 2570 | 
           | 
          2583 | 
           | 
        
          
            
              | 2571 | 
                  my $mss = GetMarcSubfieldStructure( $frameworkcode );  | 
              2584 | 
                  # The next call acknowledges Default as the authoritative framework  | 
            
            
               | 
               | 
              2585 | 
                  # for Koha to MARC mappings.  | 
            
            
              | 2586 | 
                  my $mss = GetMarcSubfieldStructure(''); # Do not change framework | 
            
        
          | 2572 | 
              foreach my $kohafield ( keys %{ $mss } ) { | 
          2587 | 
              foreach my $kohafield ( keys %{ $mss } ) { | 
        
        
          | 2573 | 
                  my ( $table, $column ) = split /[.]/, $kohafield, 2;  | 
          2588 | 
                  my ( $table, $column ) = split /[.]/, $kohafield, 2;  | 
        
        
          | 2574 | 
                  next unless $tables{$table}; | 
          2589 | 
                  next unless $tables{$table}; | 
        
          
            
              | 2575 | 
                      my $val = TransformMarcToKohaOneField(  | 
              2590 | 
                      my $val = TransformMarcToKohaOneField( $kohafield, $record );  | 
            
            
              | 2576 | 
                          $kohafield, $record, $frameworkcode,  | 
               | 
               | 
            
            
              | 2577 | 
                      );  | 
            
        
          | 2578 | 
                  next if !defined $val;  | 
          2591 | 
                  next if !defined $val;  | 
        
        
          | 2579 | 
                  my $key = _disambiguate( $table, $column );  | 
          2592 | 
                  my $key = _disambiguate( $table, $column );  | 
        
        
          | 2580 | 
                  $result->{$key} = $val; | 
          2593 | 
                  $result->{$key} = $val; | 
        
  
    | 
      
            Lines 2623-2637
          sub _disambiguate {
      
      
        Link Here
      
     | 
  
        
          | 2623 | 
           | 
          2636 | 
           | 
        
        
          | 2624 | 
          =head2 TransformMarcToKohaOneField  | 
          2637 | 
          =head2 TransformMarcToKohaOneField  | 
        
        
          | 2625 | 
           | 
          2638 | 
           | 
        
          
            
              | 2626 | 
                  $val = TransformMarcToKohaOneField( 'biblio.title', $marc, $frameworkcode );  | 
              2639 | 
                  $val = TransformMarcToKohaOneField( 'biblio.title', $marc );  | 
            
            
               | 
               | 
              2640 | 
               | 
            
            
              | 2641 | 
                  Note: The authoritative Default framework is used implicitly.  | 
            
        
          | 2627 | 
           | 
          2642 | 
           | 
        
        
          | 2628 | 
          =cut  | 
          2643 | 
          =cut  | 
        
        
          | 2629 | 
           | 
          2644 | 
           | 
        
        
          | 2630 | 
          sub TransformMarcToKohaOneField { | 
          2645 | 
          sub TransformMarcToKohaOneField { | 
        
          
            
              | 2631 | 
                  my ( $kohafield, $marc, $frameworkcode ) = @_;  | 
              2646 | 
                  my ( $kohafield, $marc ) = @_;  | 
            
        
          | 2632 | 
           | 
          2647 | 
           | 
        
        
          | 2633 | 
              my ( @rv, $retval );  | 
          2648 | 
              my ( @rv, $retval );  | 
        
          
            
              | 2634 | 
                  my @mss = GetMarcSubfieldStructureFromKohaField($kohafield, $frameworkcode);  | 
              2649 | 
                  my @mss = GetMarcSubfieldStructureFromKohaField($kohafield);  | 
            
        
          | 2635 | 
              foreach my $fldhash ( @mss ) { | 
          2650 | 
              foreach my $fldhash ( @mss ) { | 
        
        
          | 2636 | 
                  my $tag = $fldhash->{tagfield}; | 
          2651 | 
                  my $tag = $fldhash->{tagfield}; | 
        
        
          | 2637 | 
                  my $sub = $fldhash->{tagsubfield}; | 
          2652 | 
                  my $sub = $fldhash->{tagsubfield}; |