|
Lines 1921-2069
sub generate_marc_host_field {
Link Here
|
| 1921 |
|
1921 |
|
| 1922 |
my $marcflavour = C4::Context->preference('marcflavour'); |
1922 |
my $marcflavour = C4::Context->preference('marcflavour'); |
| 1923 |
my $marc_host = $self->metadata->record; |
1923 |
my $marc_host = $self->metadata->record; |
| 1924 |
my %sfd; |
1924 |
|
|
|
1925 |
my @sfd; # array of subfields to preserve order |
| 1925 |
my $host_field; |
1926 |
my $host_field; |
| 1926 |
my $link_field; |
1927 |
my $link_field; |
| 1927 |
|
1928 |
|
| 1928 |
if ( $marcflavour eq 'MARC21' ) { |
1929 |
if ( $marcflavour eq 'MARC21' ) { |
| 1929 |
|
1930 |
|
| 1930 |
# Author |
1931 |
# Attempt to clone the main entry (100, 110, or 111) |
| 1931 |
if ( $host_field = $marc_host->field('100') || $marc_host->field('110') || $marc_host->field('111') ) { |
1932 |
my $main_entry = $marc_host->field('100') || $marc_host->field('110') || $marc_host->field('111'); |
| 1932 |
my $s = $host_field->as_string('ab'); |
1933 |
$main_entry = $main_entry ? $main_entry->clone : undef; |
| 1933 |
if ($s) { |
1934 |
|
| 1934 |
$sfd{a} = $s; |
1935 |
# Clean unwanted subfields based on tag type |
|
|
1936 |
if ($main_entry) { |
| 1937 |
if ( $main_entry->tag eq '111' ) { |
| 1938 |
$main_entry->delete_subfield( code => qr/[94j]/ ); |
| 1939 |
} else { |
| 1940 |
$main_entry->delete_subfield( code => qr/[94e]/ ); |
| 1935 |
} |
1941 |
} |
| 1936 |
} |
1942 |
} |
| 1937 |
|
1943 |
|
| 1938 |
# Edition |
1944 |
# Construct subfield 7 from leader and main entry tag |
| 1939 |
if ( $host_field = $marc_host->field('250') ) { |
1945 |
my $s7 = "nn" . substr( $marc_host->leader, 6, 2 ); |
| 1940 |
my $s = $host_field->as_string('ab'); |
1946 |
if ($main_entry) { |
| 1941 |
if ($s) { |
1947 |
my $c1 = 'n'; |
| 1942 |
$sfd{b} = $s; |
1948 |
if ( $main_entry->tag =~ /^1[01]/ ) { |
|
|
1949 |
$c1 = $main_entry->indicator('1'); |
| 1950 |
$c1 = $main_entry->tag eq '100' ? 1 : 2 unless $c1 =~ /\d/; |
| 1943 |
} |
1951 |
} |
|
|
1952 |
my $c0 = |
| 1953 |
( $main_entry->tag eq '100' ) ? 'p' |
| 1954 |
: ( $main_entry->tag eq '110' ) ? 'c' |
| 1955 |
: ( $main_entry->tag eq '111' ) ? 'm' |
| 1956 |
: 'u'; |
| 1957 |
substr( $s7, 0, 2, $c0 . $c1 ); |
| 1944 |
} |
1958 |
} |
|
|
1959 |
push @sfd, '7' => $s7; |
| 1945 |
|
1960 |
|
| 1946 |
# Publication |
1961 |
# Subfield a - cleaned main entry string |
| 1947 |
if ( $host_field = $marc_host->field('260') ) { |
1962 |
if ($main_entry) { |
| 1948 |
my $s = $host_field->as_string('abc'); |
1963 |
my $a = $main_entry->as_string; |
| 1949 |
if ($s) { |
1964 |
$a =~ s/\.$// unless $a =~ /\b[a-z]{1,2}\.$/i; |
| 1950 |
$sfd{d} = $s; |
1965 |
push @sfd, 'a' => $a; |
| 1951 |
} |
|
|
| 1952 |
} |
1966 |
} |
| 1953 |
|
1967 |
|
| 1954 |
# Uniform title |
1968 |
# Subfield t - title from 245, cleaned |
| 1955 |
if ( $host_field = $marc_host->field('240') ) { |
1969 |
if ( my $f245 = $marc_host->field('245') ) { |
| 1956 |
my $s = $host_field->as_string('a'); |
1970 |
my $f245c = $f245->clone; |
| 1957 |
if ($s) { |
1971 |
$f245c->delete_subfield( code => 'c' ); |
| 1958 |
$sfd{s} = $s; |
1972 |
my $t = $f245c->as_string; |
| 1959 |
} |
1973 |
$t =~ s/(\s*\/\s*|\.)$//; |
|
|
1974 |
$t = ucfirst substr( $t, $f245c->indicator('2') ); |
| 1975 |
push @sfd, 't' => $t; |
| 1960 |
} |
1976 |
} |
| 1961 |
|
1977 |
|
| 1962 |
# Title |
1978 |
# Subfield b - edition from 250 |
| 1963 |
if ( $host_field = $marc_host->field('245') ) { |
1979 |
if ( my $f250 = $marc_host->field('250') ) { |
| 1964 |
my $s = $host_field->as_string('ab'); |
1980 |
my $b = $f250->as_string; |
| 1965 |
if ($s) { |
1981 |
$b =~ s/\.$//; |
| 1966 |
$sfd{t} = $s; |
1982 |
push @sfd, 'b' => $b; |
| 1967 |
} |
|
|
| 1968 |
} |
1983 |
} |
| 1969 |
|
1984 |
|
| 1970 |
# ISSN |
1985 |
# Subfield d - publication info from 260 |
| 1971 |
if ( $host_field = $marc_host->field('022') ) { |
1986 |
if ( my $f260 = $marc_host->field('260') ) { |
| 1972 |
my $s = $host_field->as_string('a'); |
1987 |
my $d = $f260->as_string('abc'); |
| 1973 |
if ($s) { |
1988 |
$d =~ s/\.$//; |
| 1974 |
$sfd{x} = $s; |
1989 |
push @sfd, 'd' => $d; |
| 1975 |
} |
|
|
| 1976 |
} |
1990 |
} |
| 1977 |
|
1991 |
|
| 1978 |
# ISBN |
1992 |
# Subfield k - host info from 800-830 fields |
| 1979 |
if ( $host_field = $marc_host->field('020') ) { |
1993 |
for my $f ( $marc_host->field('8[013][01]') ) { |
| 1980 |
my $s = $host_field->as_string('a'); |
1994 |
my $k = $f->as_string('abcdnjltnp'); |
| 1981 |
if ($s) { |
1995 |
$k .= ', ISSN ' . $f->subfield('x') if $f->subfield('x'); |
| 1982 |
$sfd{z} = $s; |
1996 |
$k .= ' ; ' . $f->subfield('v') if $f->subfield('v'); |
| 1983 |
} |
1997 |
push @sfd, 'k' => $k; |
| 1984 |
} |
1998 |
} |
| 1985 |
if ( C4::Context->preference('UseControlNumber') ) { |
|
|
| 1986 |
|
1999 |
|
| 1987 |
# Control number |
2000 |
# Subfield x - ISSN from 022 |
| 1988 |
if ( $host_field = $marc_host->field('001') ) { |
2001 |
for my $f ( $marc_host->field('022') ) { |
| 1989 |
$sfd{w} = $host_field->data(); |
2002 |
push @sfd, 'x' => $f->subfield('a') if $f->subfield('a'); |
| 1990 |
} |
2003 |
} |
|
|
2004 |
|
| 2005 |
# Subfield z - ISBN from 020 |
| 2006 |
for my $f ( $marc_host->field('020') ) { |
| 2007 |
push @sfd, 'z' => $f->subfield('a') if $f->subfield('a'); |
| 2008 |
} |
| 1991 |
|
2009 |
|
| 1992 |
# Control number identifier |
2010 |
# Subfield w - control number (001 and optionally 003) |
| 1993 |
if ( $host_field = $marc_host->field('003') ) { |
2011 |
if ( C4::Context->preference('UseControlNumber') ) { |
| 1994 |
$sfd{w} = '(' . $host_field->data() . ')' . $sfd{w}; |
2012 |
if ( my $f001 = $marc_host->field('001') ) { |
|
|
2013 |
my $w = $f001->data; |
| 2014 |
if ( my $f003 = $marc_host->field('003') ) { |
| 2015 |
$w = '(' . $f003->data . ')' . $w; |
| 2016 |
} |
| 2017 |
push @sfd, 'w' => $w; |
| 1995 |
} |
2018 |
} |
| 1996 |
} |
2019 |
} |
| 1997 |
$link_field = MARC::Field->new( 773, '0', ' ', %sfd ); |
2020 |
|
|
|
2021 |
# Construct 773 link field |
| 2022 |
$link_field = MARC::Field->new( 773, '0', ' ', @sfd ); |
| 2023 |
|
| 1998 |
} elsif ( $marcflavour eq 'UNIMARC' ) { |
2024 |
} elsif ( $marcflavour eq 'UNIMARC' ) { |
| 1999 |
|
2025 |
|
| 2000 |
# Author |
2026 |
# Author (700/710/720) |
| 2001 |
if ( $host_field = $marc_host->field('700') || $marc_host->field('710') || $marc_host->field('720') ) { |
2027 |
if ( $host_field = $marc_host->field('700') || $marc_host->field('710') || $marc_host->field('720') ) { |
| 2002 |
my $s = $host_field->as_string('ab'); |
2028 |
my $s = $host_field->as_string('ab'); |
| 2003 |
if ($s) { |
2029 |
push @sfd, 'a' => $s if $s; |
| 2004 |
$sfd{a} = $s; |
2030 |
} |
| 2005 |
} |
2031 |
|
|
|
2032 |
# Title (200) |
| 2033 |
if ( $host_field = $marc_host->field('200') ) { |
| 2034 |
my $s = $host_field->as_string('a'); |
| 2035 |
push @sfd, 't' => $s if $s; |
| 2006 |
} |
2036 |
} |
| 2007 |
|
2037 |
|
| 2008 |
# Place of publication |
2038 |
# Place of publication (210$a) |
| 2009 |
if ( $host_field = $marc_host->field('210') ) { |
2039 |
if ( $host_field = $marc_host->field('210') ) { |
| 2010 |
my $s = $host_field->as_string('a'); |
2040 |
my $s = $host_field->as_string('a'); |
| 2011 |
if ($s) { |
2041 |
push @sfd, 'c' => $s if $s; |
| 2012 |
$sfd{c} = $s; |
|
|
| 2013 |
} |
| 2014 |
} |
2042 |
} |
| 2015 |
|
2043 |
|
| 2016 |
# Date of publication |
2044 |
# Date of publication (210$d) |
| 2017 |
if ( $host_field = $marc_host->field('210') ) { |
2045 |
if ( $host_field = $marc_host->field('210') ) { |
| 2018 |
my $s = $host_field->as_string('d'); |
2046 |
my $s = $host_field->as_string('d'); |
| 2019 |
if ($s) { |
2047 |
push @sfd, 'd' => $s if $s; |
| 2020 |
$sfd{d} = $s; |
|
|
| 2021 |
} |
| 2022 |
} |
2048 |
} |
| 2023 |
|
2049 |
|
| 2024 |
# Edition statement |
2050 |
# Edition statement (205) |
| 2025 |
if ( $host_field = $marc_host->field('205') ) { |
2051 |
if ( $host_field = $marc_host->field('205') ) { |
| 2026 |
my $s = $host_field->as_string(); |
2052 |
my $s = $host_field->as_string; |
| 2027 |
if ($s) { |
2053 |
push @sfd, 'e' => $s if $s; |
| 2028 |
$sfd{e} = $s; |
|
|
| 2029 |
} |
| 2030 |
} |
2054 |
} |
| 2031 |
|
2055 |
|
| 2032 |
# Title |
2056 |
# URL (856$u) |
| 2033 |
if ( $host_field = $marc_host->field('200') ) { |
|
|
| 2034 |
my $s = $host_field->as_string('a'); |
| 2035 |
if ($s) { |
| 2036 |
$sfd{t} = $s; |
| 2037 |
} |
| 2038 |
} |
| 2039 |
|
| 2040 |
#URL |
| 2041 |
if ( $host_field = $marc_host->field('856') ) { |
2057 |
if ( $host_field = $marc_host->field('856') ) { |
| 2042 |
my $s = $host_field->as_string('u'); |
2058 |
my $s = $host_field->as_string('u'); |
| 2043 |
if ($s) { |
2059 |
push @sfd, 'u' => $s if $s; |
| 2044 |
$sfd{u} = $s; |
|
|
| 2045 |
} |
| 2046 |
} |
2060 |
} |
| 2047 |
|
2061 |
|
| 2048 |
# ISSN |
2062 |
# ISSN (011$a) |
| 2049 |
if ( $host_field = $marc_host->field('011') ) { |
2063 |
if ( $host_field = $marc_host->field('011') ) { |
| 2050 |
my $s = $host_field->as_string('a'); |
2064 |
my $s = $host_field->as_string('a'); |
| 2051 |
if ($s) { |
2065 |
push @sfd, 'x' => $s if $s; |
| 2052 |
$sfd{x} = $s; |
|
|
| 2053 |
} |
| 2054 |
} |
2066 |
} |
| 2055 |
|
2067 |
|
| 2056 |
# ISBN |
2068 |
# ISBN (010$a) |
| 2057 |
if ( $host_field = $marc_host->field('010') ) { |
2069 |
if ( $host_field = $marc_host->field('010') ) { |
| 2058 |
my $s = $host_field->as_string('a'); |
2070 |
my $s = $host_field->as_string('a'); |
| 2059 |
if ($s) { |
2071 |
push @sfd, 'y' => $s if $s; |
| 2060 |
$sfd{y} = $s; |
|
|
| 2061 |
} |
| 2062 |
} |
2072 |
} |
|
|
2073 |
|
| 2074 |
# Control number (001) |
| 2063 |
if ( $host_field = $marc_host->field('001') ) { |
2075 |
if ( $host_field = $marc_host->field('001') ) { |
| 2064 |
$sfd{0} = $host_field->data(); |
2076 |
push @sfd, '0' => $host_field->data(); |
| 2065 |
} |
2077 |
} |
| 2066 |
$link_field = MARC::Field->new( 461, '0', ' ', %sfd ); |
2078 |
|
|
|
2079 |
# Construct 461 link field |
| 2080 |
$link_field = MARC::Field->new( 461, '0', ' ', @sfd ); |
| 2067 |
} |
2081 |
} |
| 2068 |
|
2082 |
|
| 2069 |
return $link_field; |
2083 |
return $link_field; |
| 2070 |
- |
|
|