View | Details | Raw Unified | Return to bug 22439
Collapse All | Expand All

(-)a/C4/Biblio.pm (-78 lines)
Lines 49-55 BEGIN { Link Here
49
        GetMarcSubfieldStructureFromKohaField
49
        GetMarcSubfieldStructureFromKohaField
50
        GetFrameworkCode
50
        GetFrameworkCode
51
        TransformKohaToMarc
51
        TransformKohaToMarc
52
        PrepHostMarcField
53
        CountItemsIssued
52
        CountItemsIssued
54
        ModBiblio
53
        ModBiblio
55
        ModZebra
54
        ModZebra
Lines 1999-2081 sub _check_split { Link Here
1999
    return;
1998
    return;
2000
}
1999
}
2001
2000
2002
=head2 PrepHostMarcField
2003
2004
    $hostfield = PrepHostMarcField ( $hostbiblionumber,$hostitemnumber,$marcflavour )
2005
2006
This function returns a host field populated with data from the host record, the field can then be added to an analytical record
2007
2008
=cut
2009
2010
sub PrepHostMarcField {
2011
    my ( $hostbiblionumber, $hostitemnumber, $marcflavour ) = @_;
2012
    $marcflavour ||= "MARC21";
2013
2014
    my $biblio     = Koha::Biblios->find($hostbiblionumber);
2015
    my $hostrecord = $biblio->metadata->record;
2016
    my $item       = Koha::Items->find($hostitemnumber);
2017
2018
    my $hostmarcfield;
2019
    if ( $marcflavour eq "MARC21" ) {
2020
2021
        #main entry
2022
        my $mainentry;
2023
        if ( $hostrecord->subfield( '100', 'a' ) ) {
2024
            $mainentry = $hostrecord->subfield( '100', 'a' );
2025
        } elsif ( $hostrecord->subfield( '110', 'a' ) ) {
2026
            $mainentry = $hostrecord->subfield( '110', 'a' );
2027
        } else {
2028
            $mainentry = $hostrecord->subfield( '111', 'a' );
2029
        }
2030
2031
        # qualification info
2032
        my $qualinfo;
2033
        if ( my $field260 = $hostrecord->field('260') ) {
2034
            $qualinfo = $field260->as_string('abc');
2035
        }
2036
2037
        #other fields
2038
        my $ed      = $hostrecord->subfield( '250', 'a' );
2039
        my $barcode = $item->barcode;
2040
        my $title   = $hostrecord->subfield( '245', 'a' );
2041
2042
        # record control number, 001 with 003 and prefix
2043
        my $recctrlno;
2044
        if ( $hostrecord->field('001') ) {
2045
            $recctrlno = $hostrecord->field('001')->data();
2046
            if ( $hostrecord->field('003') ) {
2047
                $recctrlno = '(' . $hostrecord->field('003')->data() . ')' . $recctrlno;
2048
            }
2049
        }
2050
2051
        # issn/isbn
2052
        my $issn = $hostrecord->subfield( '022', 'a' );
2053
        my $isbn = $hostrecord->subfield( '020', 'a' );
2054
2055
        $hostmarcfield = MARC::Field->new(
2056
            773, '0', '',
2057
            '0' => $hostbiblionumber,
2058
            '9' => $hostitemnumber,
2059
            'a' => $mainentry,
2060
            'b' => $ed,
2061
            'd' => $qualinfo,
2062
            'o' => $barcode,
2063
            't' => $title,
2064
            'w' => $recctrlno,
2065
            'x' => $issn,
2066
            'z' => $isbn
2067
        );
2068
    } elsif ( $marcflavour eq "UNIMARC" ) {
2069
        $hostmarcfield = MARC::Field->new(
2070
            461, '', '',
2071
            '0' => $hostbiblionumber,
2072
            't' => $hostrecord->subfield( '200', 'a' ),
2073
            '9' => $hostitemnumber
2074
        );
2075
    }
2076
2077
    return $hostmarcfield;
2078
}
2079
2001
2080
=head2 TransformHtmlToXml
2002
=head2 TransformHtmlToXml
2081
2003
(-)a/Koha/Biblio.pm (-7 / +35 lines)
Lines 1905-1923 sub get_marc_hostinfo_only { Link Here
1905
=head3 generate_marc_host_field
1905
=head3 generate_marc_host_field
1906
1906
1907
  my $link_field = $biblio->generate_marc_host_field;
1907
  my $link_field = $biblio->generate_marc_host_field;
1908
  my $link_field = $biblio->generate_marc_host_field( { item => $item } );
1908
  $child->link_marc_host( $link_field );
1909
  $child->link_marc_host( $link_field );
1909
1910
1910
This method generates a MARC link field from the host record that can be added to child
1911
This method generates a MARC link field from the host record that can be added to child
1911
records to link them to the host record.
1912
records to link them to the host record.
1912
1913
1913
NOTE: This replicates and partially enhances C4::Biblio::prepare_marc_host(). We should merge
1914
When an item is passed and EasyAnalyticalRecords is enabled, item-specific data (barcode and
1914
functionality from C4::Biblio::PrepareMarcHost() too and then replace all calls to those methods
1915
itemnumber) will be included in the host field. This is non-standard MARC and should only be
1915
with this one and remove those alternatives from the codebase.
1916
used when the easy analytics workflow is specifically enabled.
1917
1918
NOTE: This replaces C4::Biblio::PrepHostMarcField() which has been removed to eliminate
1919
code duplication.
1916
1920
1917
=cut
1921
=cut
1918
1922
1919
sub generate_marc_host_field {
1923
sub generate_marc_host_field {
1920
    my ($self) = @_;
1924
    my ( $self, $params ) = @_;
1925
    $params //= {};
1926
    
1927
    my $item = $params->{item};
1921
1928
1922
    my $marcflavour = C4::Context->preference('marcflavour');
1929
    my $marcflavour = C4::Context->preference('marcflavour');
1923
    my $marc_host   = $self->metadata->record;
1930
    my $marc_host   = $self->metadata->record;
Lines 2050-2055 sub generate_marc_host_field { Link Here
2050
            }
2057
            }
2051
        }
2058
        }
2052
2059
2060
        # Item-specific subfields (only when EasyAnalyticalRecords is enabled)
2061
        if ( $item && C4::Context->preference('EasyAnalyticalRecords') ) {
2062
            # Subfield 0 - host biblionumber
2063
            push @sfd, ( '0' => $self->biblionumber );
2064
            
2065
            # Subfield 9 - host itemnumber
2066
            push @sfd, ( '9' => $item->itemnumber );
2067
            
2068
            # Subfield o - barcode
2069
            push @sfd, ( 'o' => $item->barcode ) if $item->barcode;
2070
        }
2071
2053
        # Construct 773 link field
2072
        # Construct 773 link field
2054
        $link_field = MARC::Field->new( 773, '0', ' ', @sfd );
2073
        $link_field = MARC::Field->new( 773, '0', ' ', @sfd );
2055
2074
Lines 2103-2111 sub generate_marc_host_field { Link Here
2103
            push @sfd, ( y => $s ) if ($s);
2122
            push @sfd, ( y => $s ) if ($s);
2104
        }
2123
        }
2105
2124
2106
        # Control number (001)
2125
        # Item-specific subfields (only when EasyAnalyticalRecords is enabled)
2107
        if ( $host_field = $marc_host->field('001') ) {
2126
        if ( $item && C4::Context->preference('EasyAnalyticalRecords') ) {
2108
            push @sfd, ( 0 => $host_field->data() );
2127
            # Subfield 0 - host biblionumber (takes precedence over control number)
2128
            push @sfd, ( 0 => $self->biblionumber );
2129
            
2130
            # Subfield 9 - host itemnumber  
2131
            push @sfd, ( 9 => $item->itemnumber );
2132
        } else {
2133
            # Control number (001) - only when not using item-specific data
2134
            if ( $host_field = $marc_host->field('001') ) {
2135
                push @sfd, ( 0 => $host_field->data() );
2136
            }
2109
        }
2137
        }
2110
2138
2111
        # Construct 461 link field
2139
        # Construct 461 link field
(-)a/cataloguing/addbiblio.pl (-4 / +7 lines)
Lines 33-39 use C4::Biblio qw( Link Here
33
    GetMarcStructure
33
    GetMarcStructure
34
    GetUsedMarcStructure
34
    GetUsedMarcStructure
35
    ModBiblio
35
    ModBiblio
36
    PrepHostMarcField
37
    TransformHtmlToMarc
36
    TransformHtmlToMarc
38
    ApplyMarcOverlayRules
37
    ApplyMarcOverlayRules
39
);
38
);
Lines 49-54 use Koha::DateUtils qw( dt_from_string ); Link Here
49
48
50
use Koha::Acquisition::Orders;
49
use Koha::Acquisition::Orders;
51
use Koha::Biblios;
50
use Koha::Biblios;
51
use Koha::Items;
52
use Koha::ItemTypes;
52
use Koha::ItemTypes;
53
use Koha::Libraries;
53
use Koha::Libraries;
54
54
Lines 633-643 if ( $record && $op eq 'duplicate' ) { Link Here
633
633
634
#populate hostfield if hostbiblionumber is available
634
#populate hostfield if hostbiblionumber is available
635
if ($hostbiblionumber) {
635
if ($hostbiblionumber) {
636
    my $marcflavour = C4::Context->preference("marcflavour");
637
    $record = MARC::Record->new();
636
    $record = MARC::Record->new();
638
    $record->leader('');
637
    $record->leader('');
639
    my $field = PrepHostMarcField( $hostbiblionumber, $hostitemnumber, $marcflavour );
638
    my $host_biblio = Koha::Biblios->find($hostbiblionumber);
640
    $record->append_fields($field);
639
    if ($host_biblio) {
640
        my $item = $hostitemnumber ? Koha::Items->find($hostitemnumber) : undef;
641
        my $field = $host_biblio->generate_marc_host_field({ item => $item });
642
        $record->append_fields($field) if $field;
643
    }
641
}
644
}
642
645
643
# This is  a child record
646
# This is  a child record
(-)a/cataloguing/linkitem.pl (-3 / +2 lines)
Lines 24-30 use Modern::Perl; Link Here
24
use CGI        qw ( -utf8 );
24
use CGI        qw ( -utf8 );
25
use C4::Auth   qw( get_template_and_user );
25
use C4::Auth   qw( get_template_and_user );
26
use C4::Output qw( output_html_with_http_headers );
26
use C4::Output qw( output_html_with_http_headers );
27
use C4::Biblio qw( ModBiblio PrepHostMarcField );
27
use C4::Biblio qw( ModBiblio );
28
use C4::Context;
28
use C4::Context;
29
use Koha::Biblios;
29
use Koha::Biblios;
30
30
Lines 59-65 if ( $op eq 'cud-linkitem' && $barcode && $biblionumber ) { Link Here
59
    my $item = Koha::Items->find( { barcode => $barcode } );
59
    my $item = Koha::Items->find( { barcode => $barcode } );
60
60
61
    if ($item) {
61
    if ($item) {
62
        my $field = PrepHostMarcField( $item->biblio->biblionumber, $item->itemnumber, $marcflavour );
62
        my $field = $item->biblio->generate_marc_host_field({ item => $item });
63
        $record->append_fields($field);
63
        $record->append_fields($field);
64
64
65
        my $modresult = ModBiblio( $record, $biblionumber, '' );
65
        my $modresult = ModBiblio( $record, $biblionumber, '' );
66
- 

Return to bug 22439