(bug #3370) export function and fix return

this add GetRecordValue in exported functions, and made it to return a ref.
This commit is contained in:
Nahuel ANGELINETTI 2009-08-28 23:47:46 +02:00 committed by Henri-Damien LAURENT
parent 1b5e2e83ed
commit 8262082fa2

View file

@ -57,6 +57,11 @@ BEGIN {
&GetBiblioItemByBiblioNumber
&GetBiblioFromItemNumber
&GetRecordValue
&GetFieldMapping
&SetFieldMapping
&DeleteFieldMapping
&GetISBDView
&GetMarcNotes
@ -492,6 +497,115 @@ sub LinkBibHeadingsToAuthorities {
return $num_headings_changed;
}
=head2 GetRecordValue
=over 4
my $values = GetRecordValue($field, $record, $frameworkcode);
=back
Get MARC fields from a keyword defined in fieldmapping table.
=cut
sub GetRecordValue {
my ($field, $record, $frameworkcode) = @_;
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare('SELECT fieldcode, subfieldcode FROM fieldmapping WHERE frameworkcode = ? AND field = ?');
$sth->execute($frameworkcode, $field);
my @result = ();
while(my $row = $sth->fetchrow_hashref){
foreach my $field ($record->field($row->{fieldcode})){
if( ($row->{subfieldcode} ne "" && $field->subfield($row->{subfieldcode}))){
foreach my $subfield ($field->subfield($row->{subfieldcode})){
push @result, { 'subfield' => $subfield };
}
}elsif($row->{subfieldcode} eq "") {
push @result, {'subfield' => $field->as_string()};
}
}
}
return \@result;
}
=head2 SetFieldMapping
=over 4
SetFieldMapping($framework, $field, $fieldcode, $subfieldcode);
=back
Set a Field to MARC mapping value, if it already exists we don't add a new one.
=cut
sub SetFieldMapping {
my ($framework, $field, $fieldcode, $subfieldcode) = @_;
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare('SELECT * FROM fieldmapping WHERE fieldcode = ? AND subfieldcode = ? AND frameworkcode = ? AND field = ?');
$sth->execute($fieldcode, $subfieldcode, $framework, $field);
if(not $sth->fetchrow_hashref){
my @args;
$sth = $dbh->prepare('INSERT INTO fieldmapping (fieldcode, subfieldcode, frameworkcode, field) VALUES(?,?,?,?)');
$sth->execute($fieldcode, $subfieldcode, $framework, $field);
}
}
=head2 DeleteFieldMapping
=over 4
DeleteFieldMapping($id);
=back
Delete a field mapping from an $id.
=cut
sub DeleteFieldMapping{
my ($id) = @_;
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare('DELETE FROM fieldmapping WHERE id = ?');
$sth->execute($id);
}
=head2 GetFieldMapping
=over 4
GetFieldMapping($frameworkcode);
=back
Get all field mappings for a specified frameworkcode
=cut
sub GetFieldMapping {
my ($framework) = @_;
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare('SELECT * FROM fieldmapping where frameworkcode = ?');
$sth->execute($framework);
my @return;
while(my $row = $sth->fetchrow_hashref){
push @return, $row;
}
return \@return;
}
=head2 GetBiblioData
=over 4