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

(-)a/C4/Biblio.pm (-34 / +18 lines)
Lines 1827-1843 sub GetFrameworkCode { Link Here
1827
This function builds partial MARC::Record from a hash
1827
This function builds partial MARC::Record from a hash
1828
Hash entries can be from biblio or biblioitems.
1828
Hash entries can be from biblio or biblioitems.
1829
1829
1830
This function is called in acquisition module, to create a basic catalogue entry from user entry
1830
This function is called in acquisition module, to create a basic catalogue
1831
entry from user entry
1831
1832
1832
=cut
1833
=cut
1833
1834
1835
1834
sub TransformKohaToMarc {
1836
sub TransformKohaToMarc {
1835
    my ($hash) = @_;
1837
    my $hash = shift;
1836
    my $sth    = C4::Context->dbh->prepare( "SELECT tagfield,tagsubfield FROM marc_subfield_structure WHERE frameworkcode=? AND kohafield=?" );
1837
    my $record = MARC::Record->new();
1838
    my $record = MARC::Record->new();
1838
    SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") );
1839
    SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") );
1839
    foreach ( keys %{$hash} ) {
1840
    my $db_to_marc = C4::Context->marcfromkohafield;
1840
        &TransformKohaToMarcOneField( $sth, $record, $_, $hash->{$_}, '' );
1841
    while ( my ($name, $value) = each %$hash ) {
1842
        next unless my $dtm = $db_to_marc->{''}->{$name};
1843
        my ($tag, $letter) = @$dtm;
1844
        foreach my $value ( split(/\s?\|\s?/, $value, -1) ) {
1845
            if ( my $field = $record->field($tag) ) {
1846
                $field->add_subfields( $letter => $value );
1847
            }
1848
            else {
1849
                $record->insert_fields_ordered( MARC::Field->new(
1850
                    $tag, " ", " ", $letter => $value ) );
1851
            }
1852
        }
1853
1841
    }
1854
    }
1842
    return $record;
1855
    return $record;
1843
}
1856
}
Lines 1928-1961 sub PrepHostMarcField { Link Here
1928
1941
1929
=cut
1942
=cut
1930
1943
1931
sub TransformKohaToMarcOneField {
1932
    my ( $sth, $record, $kohafieldname, $value, $frameworkcode ) = @_;
1933
    $frameworkcode = '' unless $frameworkcode;
1934
    my $tagfield;
1935
    my $tagsubfield;
1936
1937
    if ( !defined $sth ) {
1938
        my $dbh = C4::Context->dbh;
1939
        $sth = $dbh->prepare( "SELECT tagfield,tagsubfield FROM marc_subfield_structure WHERE frameworkcode=? AND kohafield=?" );
1940
    }
1941
    $sth->execute( $frameworkcode, $kohafieldname );
1942
    if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
1943
        my @values = split(/\s?\|\s?/, $value, -1);
1944
        
1945
        foreach my $itemvalue (@values){
1946
        my $tag = $record->field($tagfield);
1947
        if ($tag) {
1948
                $tag->add_subfields( $tagsubfield => $itemvalue );
1949
            $record->delete_field($tag);
1950
            $record->insert_fields_ordered($tag);
1951
            }
1952
            else {
1953
                $record->add_fields( $tagfield, " ", " ", $tagsubfield => $itemvalue );
1954
            }
1955
        }
1956
    }
1957
    return $record;
1958
}
1959
1944
1960
=head2 TransformHtmlToXml
1945
=head2 TransformHtmlToXml
1961
1946
1962
- 

Return to bug 6990