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

(-)a/C4/Biblio.pm (-34 / +18 lines)
Lines 1782-1798 sub GetFrameworkCode { Link Here
1782
This function builds partial MARC::Record from a hash
1782
This function builds partial MARC::Record from a hash
1783
Hash entries can be from biblio or biblioitems.
1783
Hash entries can be from biblio or biblioitems.
1784
1784
1785
This function is called in acquisition module, to create a basic catalogue entry from user entry
1785
This function is called in acquisition module, to create a basic catalogue
1786
entry from user entry
1786
1787
1787
=cut
1788
=cut
1788
1789
1790
1789
sub TransformKohaToMarc {
1791
sub TransformKohaToMarc {
1790
    my ($hash) = @_;
1792
    my $hash = shift;
1791
    my $sth    = C4::Context->dbh->prepare( "SELECT tagfield,tagsubfield FROM marc_subfield_structure WHERE frameworkcode=? AND kohafield=?" );
1792
    my $record = MARC::Record->new();
1793
    my $record = MARC::Record->new();
1793
    SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") );
1794
    SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") );
1794
    foreach ( keys %{$hash} ) {
1795
    my $db_to_marc = C4::Context->marcfromkohafield;
1795
        &TransformKohaToMarcOneField( $sth, $record, $_, $hash->{$_}, '' );
1796
    while ( my ($name, $value) = each %$hash ) {
1797
        next unless my $dtm = $db_to_marc->{''}->{$name};
1798
        my ($tag, $letter) = @$dtm;
1799
        foreach my $value ( split(/\s?\|\s?/, $value, -1) ) {
1800
            if ( my $field = $record->field($tag) ) {
1801
                $field->add_subfields( $letter => $value );
1802
            }
1803
            else {
1804
                $record->insert_fields_ordered( MARC::Field->new(
1805
                    $tag, " ", " ", $letter => $value ) );
1806
            }
1807
        }
1808
1796
    }
1809
    }
1797
    return $record;
1810
    return $record;
1798
}
1811
}
Lines 1803-1836 sub TransformKohaToMarc { Link Here
1803
1816
1804
=cut
1817
=cut
1805
1818
1806
sub TransformKohaToMarcOneField {
1807
    my ( $sth, $record, $kohafieldname, $value, $frameworkcode ) = @_;
1808
    $frameworkcode = '' unless $frameworkcode;
1809
    my $tagfield;
1810
    my $tagsubfield;
1811
1812
    if ( !defined $sth ) {
1813
        my $dbh = C4::Context->dbh;
1814
        $sth = $dbh->prepare( "SELECT tagfield,tagsubfield FROM marc_subfield_structure WHERE frameworkcode=? AND kohafield=?" );
1815
    }
1816
    $sth->execute( $frameworkcode, $kohafieldname );
1817
    if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
1818
        my @values = split(/\s?\|\s?/, $value, -1);
1819
        
1820
        foreach my $itemvalue (@values){
1821
        my $tag = $record->field($tagfield);
1822
        if ($tag) {
1823
                $tag->add_subfields( $tagsubfield => $itemvalue );
1824
            $record->delete_field($tag);
1825
            $record->insert_fields_ordered($tag);
1826
            }
1827
            else {
1828
                $record->add_fields( $tagfield, " ", " ", $tagsubfield => $itemvalue );
1829
            }
1830
        }
1831
    }
1832
    return $record;
1833
}
1834
1819
1835
=head2 TransformHtmlToXml
1820
=head2 TransformHtmlToXml
1836
1821
1837
- 

Return to bug 6990