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 |
|
1791 |
# A hashref giving for each Koha field its MARC tag/letter |
1792 |
my $db_to_marc; |
1793 |
|
1789 |
sub TransformKohaToMarc { |
1794 |
sub TransformKohaToMarc { |
1790 |
my ($hash) = @_; |
1795 |
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(); |
1796 |
my $record = MARC::Record->new(); |
1793 |
SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") ); |
1797 |
SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") ); |
1794 |
foreach ( keys %{$hash} ) { |
1798 |
unless ($db_to_marc) { |
1795 |
&TransformKohaToMarcOneField( $sth, $record, $_, $hash->{$_}, '' ); |
1799 |
my $dbh = C4::Context->dbh; |
|
|
1800 |
my $sth = $dbh->prepare( |
1801 |
"SELECT kohafield, tagfield, tagsubfield |
1802 |
FROM marc_subfield_structure |
1803 |
WHERE kohafield <> '' AND frameworkcode = ''" ); |
1804 |
$sth->execute(); |
1805 |
$db_to_marc = {}; |
1806 |
while ( my ($name, $tag, $letter) = $sth->fetchrow ) { |
1807 |
$db_to_marc->{$name} = [$tag, $letter]; |
1808 |
} |
1809 |
} |
1810 |
while ( my ($name, $value) = each %$hash ) { |
1811 |
next unless my $dtm = $db_to_marc->{$name}; |
1812 |
my ($tag, $letter) = @$dtm; |
1813 |
foreach my $value ( split(/\s?\|\s?/, $value, -1) ) { |
1814 |
if ( my $field = $record->field($tag) ) { |
1815 |
$field->add_subfields( $letter => $value ); |
1816 |
} |
1817 |
else { |
1818 |
$record->insert_fields_ordered( MARC::Field->new( |
1819 |
$tag, " ", " ", $letter => $value ) ); |
1820 |
} |
1821 |
} |
1822 |
|
1796 |
} |
1823 |
} |
1797 |
return $record; |
1824 |
return $record; |
1798 |
} |
1825 |
} |
Lines 1803-1836
sub TransformKohaToMarc {
Link Here
|
1803 |
|
1830 |
|
1804 |
=cut |
1831 |
=cut |
1805 |
|
1832 |
|
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 |
|
1833 |
|
1835 |
=head2 TransformHtmlToXml |
1834 |
=head2 TransformHtmlToXml |
1836 |
|
1835 |
|