Lines 2948-3063
sub prepare_host_field {
Link Here
|
2948 |
|
2948 |
|
2949 |
my $biblio = Koha::Biblios->find($hostbiblio); |
2949 |
my $biblio = Koha::Biblios->find($hostbiblio); |
2950 |
my $host = $biblio->metadata->record; |
2950 |
my $host = $biblio->metadata->record; |
|
|
2951 |
my $prepared_host_field = C4::Context->yaml_preference('PrepareHostField') || q{}; |
2951 |
# unfortunately as_string does not 'do the right thing' |
2952 |
# unfortunately as_string does not 'do the right thing' |
2952 |
# if field returns undef |
2953 |
# if field returns undef |
2953 |
my %sfd; |
2954 |
my %sfd; |
2954 |
my $field; |
2955 |
my $field; |
2955 |
my $host_field; |
2956 |
my $host_field; |
2956 |
if ( $marcflavour eq 'MARC21' ) { |
2957 |
if ( $prepared_host_field ) { |
2957 |
if ( $field = $host->field('100') || $host->field('110') || $host->field('11') ) { |
2958 |
foreach my $key (keys %$prepared_host_field) { |
2958 |
my $s = $field->as_string('ab'); |
2959 |
my ($tag, $subfields) = split(/\$/, $key); |
2959 |
if ($s) { |
2960 |
my ($part_field, $part_subfield) = split(/\$/, $prepared_host_field->{$key}); |
2960 |
$sfd{a} = $s; |
2961 |
my $field = $host->field($tag); |
|
|
2962 |
if ( $field ) { |
2963 |
if ($field->is_control_field) { |
2964 |
$sfd{$part_subfield} = $field->data(); |
2965 |
} else { |
2966 |
my $s = $field->as_string($subfields); |
2967 |
if ($s) { |
2968 |
$sfd{$part_subfield} = $s; |
2969 |
} |
2970 |
} |
2961 |
} |
2971 |
} |
2962 |
} |
2972 |
if (%sfd) { |
2963 |
if ( $field = $host->field('245') ) { |
2973 |
$host_field = MARC::Field->new( $part_field, '0', ' ', %sfd ); |
2964 |
my $s = $field->as_string('a'); |
|
|
2965 |
if ($s) { |
2966 |
$sfd{t} = $s; |
2967 |
} |
2974 |
} |
2968 |
} |
2975 |
} |
2969 |
if ( $field = $host->field('260') ) { |
2976 |
|
2970 |
my $s = $field->as_string('abc'); |
2977 |
return $host_field; |
2971 |
if ($s) { |
2978 |
} else { |
2972 |
$sfd{d} = $s; |
2979 |
if ( $marcflavour eq 'MARC21' ) { |
|
|
2980 |
if ( $field = $host->field('100') || $host->field('110') || $host->field('11') ) { |
2981 |
my $s = $field->as_string('ab'); |
2982 |
if ($s) { |
2983 |
$sfd{a} = $s; |
2984 |
} |
2973 |
} |
2985 |
} |
2974 |
} |
2986 |
if ( $field = $host->field('245') ) { |
2975 |
if ( $field = $host->field('240') ) { |
2987 |
my $s = $field->as_string('a'); |
2976 |
my $s = $field->as_string(); |
2988 |
if ($s) { |
2977 |
if ($s) { |
2989 |
$sfd{t} = $s; |
2978 |
$sfd{b} = $s; |
2990 |
} |
2979 |
} |
2991 |
} |
2980 |
} |
2992 |
if ( $field = $host->field('260') ) { |
2981 |
if ( $field = $host->field('022') ) { |
2993 |
my $s = $field->as_string('abc'); |
2982 |
my $s = $field->as_string('a'); |
2994 |
if ($s) { |
2983 |
if ($s) { |
2995 |
$sfd{d} = $s; |
2984 |
$sfd{x} = $s; |
2996 |
} |
2985 |
} |
2997 |
} |
2986 |
} |
2998 |
if ( $field = $host->field('240') ) { |
2987 |
if ( $field = $host->field('020') ) { |
2999 |
my $s = $field->as_string(); |
2988 |
my $s = $field->as_string('a'); |
3000 |
if ($s) { |
2989 |
if ($s) { |
3001 |
$sfd{b} = $s; |
2990 |
$sfd{z} = $s; |
3002 |
} |
2991 |
} |
3003 |
} |
2992 |
} |
3004 |
if ( $field = $host->field('022') ) { |
2993 |
if ( $field = $host->field('001') ) { |
3005 |
my $s = $field->as_string('a'); |
2994 |
$sfd{w} = $field->data(),; |
3006 |
if ($s) { |
2995 |
} |
3007 |
$sfd{x} = $s; |
2996 |
$host_field = MARC::Field->new( 773, '0', ' ', %sfd ); |
3008 |
} |
2997 |
return $host_field; |
|
|
2998 |
} |
2999 |
elsif ( $marcflavour eq 'UNIMARC' ) { |
3000 |
#author |
3001 |
if ( $field = $host->field('700') || $host->field('710') || $host->field('720') ) { |
3002 |
my $s = $field->as_string('ab'); |
3003 |
if ($s) { |
3004 |
$sfd{a} = $s; |
3005 |
} |
3009 |
} |
3006 |
} |
3010 |
if ( $field = $host->field('020') ) { |
3007 |
#title |
3011 |
my $s = $field->as_string('a'); |
3008 |
if ( $field = $host->field('200') ) { |
3012 |
if ($s) { |
3009 |
my $s = $field->as_string('a'); |
3013 |
$sfd{z} = $s; |
3010 |
if ($s) { |
3014 |
} |
3011 |
$sfd{t} = $s; |
|
|
3012 |
} |
3015 |
} |
3013 |
} |
3016 |
if ( $field = $host->field('001') ) { |
3014 |
#place of publicaton |
3017 |
$sfd{w} = $field->data(),; |
3015 |
if ( $field = $host->field('210') ) { |
|
|
3016 |
my $s = $field->as_string('a'); |
3017 |
if ($s) { |
3018 |
$sfd{c} = $s; |
3019 |
} |
3018 |
} |
3020 |
} |
3019 |
$host_field = MARC::Field->new( 773, '0', ' ', %sfd ); |
3021 |
#date of publication |
3020 |
return $host_field; |
3022 |
if ( $field = $host->field('210') ) { |
3021 |
} |
3023 |
my $s = $field->as_string('d'); |
3022 |
elsif ( $marcflavour eq 'UNIMARC' ) { |
3024 |
if ($s) { |
3023 |
#author |
3025 |
$sfd{d} = $s; |
3024 |
if ( $field = $host->field('700') || $host->field('710') || $host->field('720') ) { |
|
|
3025 |
my $s = $field->as_string('ab'); |
3026 |
if ($s) { |
3027 |
$sfd{a} = $s; |
3028 |
} |
3026 |
} |
3029 |
} |
3027 |
} |
3030 |
#title |
3028 |
#edition statement |
3031 |
if ( $field = $host->field('200') ) { |
3029 |
if ( $field = $host->field('205') ) { |
3032 |
my $s = $field->as_string('a'); |
3030 |
my $s = $field->as_string(); |
3033 |
if ($s) { |
3031 |
if ($s) { |
3034 |
$sfd{t} = $s; |
3032 |
$sfd{e} = $s; |
3035 |
} |
3033 |
} |
3036 |
} |
3034 |
} |
3037 |
#place of publicaton |
3035 |
#URL |
3038 |
if ( $field = $host->field('210') ) { |
3036 |
if ( $field = $host->field('856') ) { |
3039 |
my $s = $field->as_string('a'); |
3037 |
my $s = $field->as_string('u'); |
3040 |
if ($s) { |
3038 |
if ($s) { |
3041 |
$sfd{c} = $s; |
3039 |
$sfd{u} = $s; |
3042 |
} |
3040 |
} |
3043 |
} |
3041 |
} |
3044 |
#date of publication |
3042 |
#ISSN |
3045 |
if ( $field = $host->field('210') ) { |
3043 |
if ( $field = $host->field('011') ) { |
3046 |
my $s = $field->as_string('d'); |
3044 |
my $s = $field->as_string('a'); |
3047 |
if ($s) { |
3045 |
if ($s) { |
3048 |
$sfd{d} = $s; |
3046 |
$sfd{x} = $s; |
3049 |
} |
3047 |
} |
3050 |
} |
3048 |
} |
3051 |
#edition statement |
3049 |
#ISBN |
3052 |
if ( $field = $host->field('205') ) { |
3050 |
if ( $field = $host->field('010') ) { |
3053 |
my $s = $field->as_string(); |
3051 |
my $s = $field->as_string('a'); |
3054 |
if ($s) { |
3052 |
if ($s) { |
3055 |
$sfd{e} = $s; |
3053 |
$sfd{y} = $s; |
3056 |
} |
3054 |
} |
3057 |
} |
|
|
3058 |
#URL |
3059 |
if ( $field = $host->field('856') ) { |
3060 |
my $s = $field->as_string('u'); |
3061 |
if ($s) { |
3062 |
$sfd{u} = $s; |
3063 |
} |
3064 |
} |
3065 |
#ISSN |
3066 |
if ( $field = $host->field('011') ) { |
3067 |
my $s = $field->as_string('a'); |
3068 |
if ($s) { |
3069 |
$sfd{x} = $s; |
3070 |
} |
3071 |
} |
3072 |
#ISBN |
3073 |
if ( $field = $host->field('010') ) { |
3074 |
my $s = $field->as_string('a'); |
3075 |
if ($s) { |
3076 |
$sfd{y} = $s; |
3077 |
} |
3078 |
} |
3079 |
if ( $field = $host->field('001') ) { |
3080 |
$sfd{0} = $field->data(),; |
3081 |
} |
3082 |
$host_field = MARC::Field->new( 461, '0', ' ', %sfd ); |
3083 |
return $host_field; |
3055 |
} |
3084 |
} |
3056 |
if ( $field = $host->field('001') ) { |
|
|
3057 |
$sfd{0} = $field->data(),; |
3058 |
} |
3059 |
$host_field = MARC::Field->new( 461, '0', ' ', %sfd ); |
3060 |
return $host_field; |
3061 |
} |
3085 |
} |
3062 |
return; |
3086 |
return; |
3063 |
} |
3087 |
} |