=over 4
-$result= &GetAuthType( $authtypecode)
-If $authtypecode is not "" then
- Returns hashref to authtypecode information
-else
- returns ref to array of hashref information of all Authtypes
+$result = &GetAuthType($authtypecode)
=back
+If the authority type specified by C<$authtypecode> exists,
+returns a hashref of the type's fields. If the type
+does not exist, returns undef.
+
=cut
sub GetAuthType {
my $dbh=C4::Context->dbh;
my $sth;
if (defined $authtypecode){ # NOTE - in MARC21 framework, '' is a valid authority
- # type
- $sth=$dbh->prepare("select * from auth_types where authtypecode=?");
- $sth->execute($authtypecode);
- } else {
- $sth=$dbh->prepare("select * from auth_types");
- $sth->execute;
- }
- my $res=$sth->fetchall_arrayref({});
- if (scalar(@$res)==1){
- return $res->[0];
- } else {
- return $res;
+ # type (FIXME but why?)
+ $sth=$dbh->prepare("select * from auth_types where authtypecode=?");
+ $sth->execute($authtypecode);
+ if (my $res = $sth->fetchrow_hashref) {
+ return $res;
+ }
}
+ return;
}
###NOTICE : This is only valid if a subfield is linked to one and only one authtypecode
###NOTICE : This can be a problem. We should also look into other types and rejected forms.
my $authtypedata=GetAuthType($data->{authtypecode});
+ next unless $authtypedata;
my $marcrecordauth=MARC::Record->new();
my $authfield=MARC::Field->new($authtypedata->{auth_tag_to_report},'','',"a"=>"".$field->subfield('a'));
map { $authfield->add_subfields($_->[0]=>$_->[1]) if ($_->[0]=~/[A-z]/ && $_->[0] ne "a" )} $field->subfields();