|
Lines 31-36
use Koha::Libraries;
Link Here
|
| 31 |
use Koha::MarcSubfieldStructures; |
31 |
use Koha::MarcSubfieldStructures; |
| 32 |
use DateTime::Format::MySQL; |
32 |
use DateTime::Format::MySQL; |
| 33 |
use Business::ISBN; |
33 |
use Business::ISBN; |
|
|
34 |
use Business::ISSN; |
| 34 |
use autouse 'Data::cselectall_arrayref' => qw(Dumper); |
35 |
use autouse 'Data::cselectall_arrayref' => qw(Dumper); |
| 35 |
use DBI qw(:sql_types); |
36 |
use DBI qw(:sql_types); |
| 36 |
use vars qw(@ISA @EXPORT @EXPORT_OK $DEBUG); |
37 |
use vars qw(@ISA @EXPORT @EXPORT_OK $DEBUG); |
|
Lines 63-68
BEGIN {
Link Here
|
| 63 |
&GetVariationsOfISBN |
64 |
&GetVariationsOfISBN |
| 64 |
&GetVariationsOfISBNs |
65 |
&GetVariationsOfISBNs |
| 65 |
&NormalizeISBN |
66 |
&NormalizeISBN |
|
|
67 |
&GetVariationsOfISSN |
| 68 |
&GetVariationsOfISSNs |
| 69 |
&NormalizeISSN |
| 66 |
|
70 |
|
| 67 |
$DEBUG |
71 |
$DEBUG |
| 68 |
); |
72 |
); |
|
Lines 1337-1342
sub GetVariationsOfISBNs {
Link Here
|
| 1337 |
return wantarray ? @isbns : join( " | ", @isbns ); |
1341 |
return wantarray ? @isbns : join( " | ", @isbns ); |
| 1338 |
} |
1342 |
} |
| 1339 |
|
1343 |
|
|
|
1344 |
=head2 NormalizedISSN |
| 1345 |
|
| 1346 |
my $issns = NormalizedISSN({ |
| 1347 |
issn => $issn, |
| 1348 |
strip_hyphen => [0,1] |
| 1349 |
}); |
| 1350 |
|
| 1351 |
Returns an issn validated by Business::ISSN. |
| 1352 |
Optionally strips hyphen. |
| 1353 |
|
| 1354 |
If the string cannot be validated as an issn, |
| 1355 |
it returns nothing. |
| 1356 |
|
| 1357 |
=cut |
| 1358 |
|
| 1359 |
sub NormalizeISSN { |
| 1360 |
my ($params) = @_; |
| 1361 |
|
| 1362 |
my $string = $params->{issn}; |
| 1363 |
my $strip_hyphen = $params->{strip_hyphen}; |
| 1364 |
|
| 1365 |
my $issn = Business::ISSN->new($string); |
| 1366 |
|
| 1367 |
if ( $issn && $issn->is_valid ){ |
| 1368 |
|
| 1369 |
if ($strip_hyphen) { |
| 1370 |
$string = $issn->_issn; |
| 1371 |
} |
| 1372 |
else { |
| 1373 |
$string = $issn->as_string; |
| 1374 |
} |
| 1375 |
return $string; |
| 1376 |
} |
| 1377 |
|
| 1378 |
} |
| 1379 |
|
| 1380 |
=head2 GetVariationsOfISSN |
| 1381 |
|
| 1382 |
my @issns = GetVariationsOfISSN( $issn ); |
| 1383 |
|
| 1384 |
Returns a list of variations of the given issn in |
| 1385 |
with and without a hyphen. |
| 1386 |
|
| 1387 |
In a scalar context, the issns are returned as a |
| 1388 |
string delimited by ' | '. |
| 1389 |
|
| 1390 |
=cut |
| 1391 |
|
| 1392 |
sub GetVariationsOfISSN { |
| 1393 |
my ($issn) = @_; |
| 1394 |
|
| 1395 |
return unless $issn; |
| 1396 |
|
| 1397 |
my @issns; |
| 1398 |
|
| 1399 |
push( @issns, NormalizeISSN({ issn => $issn }) ); |
| 1400 |
push( @issns, NormalizeISSN({ issn => $issn, strip_hyphen => 1 }) ); |
| 1401 |
|
| 1402 |
# Strip out any "empty" strings from the array |
| 1403 |
@issns = grep { defined($_) && $_ =~ /\S/ } @issns; |
| 1404 |
|
| 1405 |
return wantarray ? @issns : join( " | ", @issns ); |
| 1406 |
} |
| 1407 |
|
| 1408 |
=head2 GetVariationsOfISSNs |
| 1409 |
|
| 1410 |
my @issns = GetVariationsOfISSNs( @issns ); |
| 1411 |
|
| 1412 |
Returns a list of variations of the given issns in |
| 1413 |
with and without a hyphen. |
| 1414 |
|
| 1415 |
In a scalar context, the issns are returned as a |
| 1416 |
string delimited by ' | '. |
| 1417 |
|
| 1418 |
=cut |
| 1419 |
|
| 1420 |
sub GetVariationsOfISSNs { |
| 1421 |
my (@issns) = @_; |
| 1422 |
|
| 1423 |
@issns = map { GetVariationsOfISSN( $_ ) } @issns; |
| 1424 |
|
| 1425 |
return wantarray ? @issns : join( " | ", @issns ); |
| 1426 |
} |
| 1427 |
|
| 1428 |
|
| 1340 |
=head2 IsKohaFieldLinked |
1429 |
=head2 IsKohaFieldLinked |
| 1341 |
|
1430 |
|
| 1342 |
my $is_linked = IsKohaFieldLinked({ |
1431 |
my $is_linked = IsKohaFieldLinked({ |