|
Lines 27-32
use C4::AuthoritiesMarc::UNIMARC;
Link Here
|
| 27 |
use C4::Charset; |
27 |
use C4::Charset; |
| 28 |
use C4::Log; |
28 |
use C4::Log; |
| 29 |
use Koha::MetadataRecord::Authority; |
29 |
use Koha::MetadataRecord::Authority; |
|
|
30 |
use Koha::Authorities; |
| 30 |
use Koha::Authority::Types; |
31 |
use Koha::Authority::Types; |
| 31 |
|
32 |
|
| 32 |
use vars qw($VERSION @ISA @EXPORT); |
33 |
use vars qw($VERSION @ISA @EXPORT); |
|
Lines 39-46
BEGIN {
Link Here
|
| 39 |
@ISA = qw(Exporter); |
40 |
@ISA = qw(Exporter); |
| 40 |
@EXPORT = qw( |
41 |
@EXPORT = qw( |
| 41 |
&GetTagsLabels |
42 |
&GetTagsLabels |
| 42 |
&GetAuthType |
|
|
| 43 |
&GetAuthTypeCode |
| 44 |
&GetAuthMARCFromKohaField |
43 |
&GetAuthMARCFromKohaField |
| 45 |
|
44 |
|
| 46 |
&AddAuthority |
45 |
&AddAuthority |
|
Lines 300-315
sub SearchAuthorities {
Link Here
|
| 300 |
$reported_tag .= '$' . $_->[0] . $_->[1]; |
299 |
$reported_tag .= '$' . $_->[0] . $_->[1]; |
| 301 |
} |
300 |
} |
| 302 |
} |
301 |
} |
| 303 |
my $thisauthtypecode = GetAuthTypeCode($authid); |
302 |
|
| 304 |
my $thisauthtype = GetAuthType($thisauthtypecode); |
303 |
my $thisauthtypecode = Koha::Authorities->find($authid)->authtypecode; |
|
|
304 |
my $thisauthtype = Koha::Authority::Types->find($thisauthtypecode); |
| 305 |
unless (defined $thisauthtype) { |
305 |
unless (defined $thisauthtype) { |
| 306 |
$thisauthtypecode = $authtypecode; |
306 |
$thisauthtypecode = $authtypecode; |
| 307 |
$thisauthtype = GetAuthType($authtypecode); |
307 |
$thisauthtype = Koha::Authority::Types->find($thisauthtypecode); |
| 308 |
} |
308 |
} |
| 309 |
my $summary = BuildSummary( $authrecord, $authid, $thisauthtypecode ); |
309 |
my $summary = BuildSummary( $authrecord, $authid, $thisauthtypecode ); |
| 310 |
|
310 |
|
| 311 |
$newline{authtype} = defined($thisauthtype) ? |
311 |
$newline{authtype} = defined($thisauthtype) ? |
| 312 |
$thisauthtype->{'authtypetext'} : ''; |
312 |
$thisauthtype->authtypetext : ''; |
| 313 |
$newline{summary} = $summary; |
313 |
$newline{summary} = $summary; |
| 314 |
$newline{even} = $counter % 2; |
314 |
$newline{even} = $counter % 2; |
| 315 |
$newline{reported_tag} = $reported_tag; |
315 |
$newline{reported_tag} = $reported_tag; |
|
Lines 367-390
sub CountUsageChildren {
Link Here
|
| 367 |
my ($authid) = @_; |
367 |
my ($authid) = @_; |
| 368 |
} |
368 |
} |
| 369 |
|
369 |
|
| 370 |
=head2 GetAuthTypeCode |
|
|
| 371 |
|
| 372 |
$authtypecode= &GetAuthTypeCode($authid) |
| 373 |
|
| 374 |
returns authtypecode of an authid |
| 375 |
|
| 376 |
=cut |
| 377 |
|
| 378 |
sub GetAuthTypeCode { |
| 379 |
#AUTHfind_authtypecode |
| 380 |
my ($authid) = @_; |
| 381 |
my $dbh=C4::Context->dbh; |
| 382 |
my $sth = $dbh->prepare("select authtypecode from auth_header where authid=?"); |
| 383 |
$sth->execute($authid); |
| 384 |
my $authtypecode = $sth->fetchrow; |
| 385 |
return $authtypecode; |
| 386 |
} |
| 387 |
|
| 388 |
=head2 GuessAuthTypeCode |
370 |
=head2 GuessAuthTypeCode |
| 389 |
|
371 |
|
| 390 |
my $authtypecode = GuessAuthTypeCode($record); |
372 |
my $authtypecode = GuessAuthTypeCode($record); |
|
Lines 803-834
sub GetAuthority {
Link Here
|
| 803 |
return ($authority->record); |
785 |
return ($authority->record); |
| 804 |
} |
786 |
} |
| 805 |
|
787 |
|
| 806 |
=head2 GetAuthType |
|
|
| 807 |
|
| 808 |
$result = &GetAuthType($authtypecode) |
| 809 |
|
| 810 |
If the authority type specified by C<$authtypecode> exists, |
| 811 |
returns a hashref of the type's fields. If the type |
| 812 |
does not exist, returns undef. |
| 813 |
|
| 814 |
=cut |
| 815 |
|
| 816 |
sub GetAuthType { |
| 817 |
my ($authtypecode) = @_; |
| 818 |
my $dbh=C4::Context->dbh; |
| 819 |
my $sth; |
| 820 |
if (defined $authtypecode){ # NOTE - in MARC21 framework, '' is a valid authority |
| 821 |
# type (FIXME but why?) |
| 822 |
$sth=$dbh->prepare("select * from auth_types where authtypecode=?"); |
| 823 |
$sth->execute($authtypecode); |
| 824 |
if (my $res = $sth->fetchrow_hashref) { |
| 825 |
return $res; |
| 826 |
} |
| 827 |
} |
| 828 |
return; |
| 829 |
} |
| 830 |
|
| 831 |
|
| 832 |
=head2 FindDuplicateAuthority |
788 |
=head2 FindDuplicateAuthority |
| 833 |
|
789 |
|
| 834 |
$record= &FindDuplicateAuthority( $record, $authtypecode) |
790 |
$record= &FindDuplicateAuthority( $record, $authtypecode) |
|
Lines 896-911
sub BuildSummary {
Link Here
|
| 896 |
my $summary_template; |
852 |
my $summary_template; |
| 897 |
# handle $authtypecode is NULL or eq "" |
853 |
# handle $authtypecode is NULL or eq "" |
| 898 |
if ($authtypecode) { |
854 |
if ($authtypecode) { |
| 899 |
my $authref = GetAuthType($authtypecode); |
855 |
my $authref = Koha::Authority::Types->find($authtypecode); |
| 900 |
$summary{authtypecode} = $authref->{authtypecode}; |
856 |
$summary{authtypecode} = $authref->authtypecode; |
| 901 |
$summary{type} = $authref->{authtypetext}; |
857 |
$summary{type} = $authref->authtypetext; |
| 902 |
$summary_template = $authref->{summary}; |
858 |
$summary_template = $authref->summary; |
| 903 |
# for MARC21, the authority type summary displays a label meant for |
859 |
# for MARC21, the authority type summary displays a label meant for |
| 904 |
# display |
860 |
# display |
| 905 |
if (C4::Context->preference('marcflavour') ne 'UNIMARC') { |
861 |
if (C4::Context->preference('marcflavour') ne 'UNIMARC') { |
| 906 |
$summary{label} = $authref->{summary}; |
862 |
$summary{label} = $authref->summary; |
| 907 |
} else { |
863 |
} else { |
| 908 |
$summary{summary} = $authref->{summary}; |
864 |
$summary{summary} = $authref->summary; |
| 909 |
} |
865 |
} |
| 910 |
} |
866 |
} |
| 911 |
my $marc21subfields = 'abcdfghjklmnopqrstuvxyz68'; |
867 |
my $marc21subfields = 'abcdfghjklmnopqrstuvxyz68'; |
|
Lines 1443-1457
sub merge {
Link Here
|
| 1443 |
my ($mergefrom,$MARCfrom,$mergeto,$MARCto) = @_; |
1399 |
my ($mergefrom,$MARCfrom,$mergeto,$MARCto) = @_; |
| 1444 |
my ($counteditedbiblio,$countunmodifiedbiblio,$counterrors)=(0,0,0); |
1400 |
my ($counteditedbiblio,$countunmodifiedbiblio,$counterrors)=(0,0,0); |
| 1445 |
my $dbh=C4::Context->dbh; |
1401 |
my $dbh=C4::Context->dbh; |
| 1446 |
my $authtypecodefrom = GetAuthTypeCode($mergefrom); |
1402 |
my $authtypefrom = Koha::Authority::Types->find($mergefrom); |
| 1447 |
my $authtypecodeto = GetAuthTypeCode($mergeto); |
1403 |
my $authtypeto = Koha::Authority::Types->find($mergeto); |
| 1448 |
# warn "mergefrom : $authtypecodefrom $mergefrom mergeto : $authtypecodeto $mergeto "; |
1404 |
|
| 1449 |
# return if authority does not exist |
|
|
| 1450 |
return "error MARCFROM not a marcrecord ".Data::Dumper::Dumper($MARCfrom) if scalar($MARCfrom->fields()) == 0; |
1405 |
return "error MARCFROM not a marcrecord ".Data::Dumper::Dumper($MARCfrom) if scalar($MARCfrom->fields()) == 0; |
| 1451 |
return "error MARCTO not a marcrecord".Data::Dumper::Dumper($MARCto) if scalar($MARCto->fields()) == 0; |
1406 |
return "error MARCTO not a marcrecord".Data::Dumper::Dumper($MARCto) if scalar($MARCto->fields()) == 0; |
| 1452 |
# search the tag to report |
1407 |
# search the tag to report |
| 1453 |
my $auth_tag_to_report_from = Koha::Authority::Types->find($authtypecodefrom)->auth_tag_to_report; |
1408 |
my $auth_tag_to_report_from = $authtypefrom->auth_tag_to_report; |
| 1454 |
my $auth_tag_to_report_to = Koha::Authority::Types->find($authtypecodeto)->auth_tag_to_report; |
1409 |
my $auth_tag_to_report_to = $authtypeto->auth_tag_to_report; |
| 1455 |
|
1410 |
|
| 1456 |
my @record_to; |
1411 |
my @record_to; |
| 1457 |
@record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $MARCto->field($auth_tag_to_report_to); |
1412 |
@record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $MARCto->field($auth_tag_to_report_to); |
|
Lines 1491-1505
sub merge {
Link Here
|
| 1491 |
# Get All candidate Tags for the change |
1446 |
# Get All candidate Tags for the change |
| 1492 |
# (This will reduce the search scope in marc records). |
1447 |
# (This will reduce the search scope in marc records). |
| 1493 |
my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?"); |
1448 |
my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?"); |
| 1494 |
$sth->execute($authtypecodefrom); |
1449 |
$sth->execute($authtypefrom->authtypecode); |
| 1495 |
my @tags_using_authtype; |
1450 |
my @tags_using_authtype; |
| 1496 |
while (my ($tagfield) = $sth->fetchrow) { |
1451 |
while (my ($tagfield) = $sth->fetchrow) { |
| 1497 |
push @tags_using_authtype,$tagfield ; |
1452 |
push @tags_using_authtype,$tagfield ; |
| 1498 |
} |
1453 |
} |
| 1499 |
my $tag_to=0; |
1454 |
my $tag_to=0; |
| 1500 |
if ($authtypecodeto ne $authtypecodefrom){ |
1455 |
if ($authtypeto->authtypecode ne $authtypefrom->authtypecode){ |
| 1501 |
# If many tags, take the first |
1456 |
# If many tags, take the first |
| 1502 |
$sth->execute($authtypecodeto); |
1457 |
$sth->execute($authtypeto->authtypecode); |
| 1503 |
$tag_to=$sth->fetchrow; |
1458 |
$tag_to=$sth->fetchrow; |
| 1504 |
#warn $tag_to; |
1459 |
#warn $tag_to; |
| 1505 |
} |
1460 |
} |