Lines 30-35
use Koha::DateUtils qw(dt_from_string);
Link Here
|
30 |
use Koha::Libraries; |
30 |
use Koha::Libraries; |
31 |
use DateTime::Format::MySQL; |
31 |
use DateTime::Format::MySQL; |
32 |
use Business::ISBN; |
32 |
use Business::ISBN; |
|
|
33 |
use Business::ISSN; |
33 |
use autouse 'Data::cselectall_arrayref' => qw(Dumper); |
34 |
use autouse 'Data::cselectall_arrayref' => qw(Dumper); |
34 |
use DBI qw(:sql_types); |
35 |
use DBI qw(:sql_types); |
35 |
use vars qw(@ISA @EXPORT @EXPORT_OK $DEBUG); |
36 |
use vars qw(@ISA @EXPORT @EXPORT_OK $DEBUG); |
Lines 69-74
BEGIN {
Link Here
|
69 |
&GetVariationsOfISBN |
70 |
&GetVariationsOfISBN |
70 |
&GetVariationsOfISBNs |
71 |
&GetVariationsOfISBNs |
71 |
&NormalizeISBN |
72 |
&NormalizeISBN |
|
|
73 |
&GetVariationsOfISSN |
74 |
&GetVariationsOfISSNs |
75 |
&NormalizeISSN |
72 |
|
76 |
|
73 |
$DEBUG |
77 |
$DEBUG |
74 |
); |
78 |
); |
Lines 1604-1609
sub GetVariationsOfISBNs {
Link Here
|
1604 |
return wantarray ? @isbns : join( " | ", @isbns ); |
1608 |
return wantarray ? @isbns : join( " | ", @isbns ); |
1605 |
} |
1609 |
} |
1606 |
|
1610 |
|
|
|
1611 |
=head2 NormalizedISSN |
1612 |
|
1613 |
my $issns = NormalizedISSN({ |
1614 |
issn => $issn, |
1615 |
strip_hyphen => [0,1] |
1616 |
}); |
1617 |
|
1618 |
Returns an issn validated by Business::ISSN. |
1619 |
Optionally strips hyphen. |
1620 |
|
1621 |
If the string cannot be validated as an issn, |
1622 |
it returns nothing. |
1623 |
|
1624 |
=cut |
1625 |
|
1626 |
sub NormalizeISSN { |
1627 |
my ($params) = @_; |
1628 |
|
1629 |
my $string = $params->{issn}; |
1630 |
my $strip_hyphen = $params->{strip_hyphen}; |
1631 |
|
1632 |
my $issn = Business::ISSN->new($string); |
1633 |
|
1634 |
if ( $issn && $issn->is_valid ){ |
1635 |
|
1636 |
if ($strip_hyphen) { |
1637 |
$string = $issn->_issn; |
1638 |
} |
1639 |
else { |
1640 |
$string = $issn->as_string; |
1641 |
} |
1642 |
return $string; |
1643 |
} |
1644 |
|
1645 |
} |
1646 |
|
1647 |
=head2 GetVariationsOfISSN |
1648 |
|
1649 |
my @issns = GetVariationsOfISSN( $issn ); |
1650 |
|
1651 |
Returns a list of variations of the given issn in |
1652 |
with and without a hyphen. |
1653 |
|
1654 |
In a scalar context, the issns are returned as a |
1655 |
string delimited by ' | '. |
1656 |
|
1657 |
=cut |
1658 |
|
1659 |
sub GetVariationsOfISSN { |
1660 |
my ($issn) = @_; |
1661 |
|
1662 |
return unless $issn; |
1663 |
|
1664 |
my @issns; |
1665 |
|
1666 |
push( @issns, NormalizeISSN({ issn => $issn }) ); |
1667 |
push( @issns, NormalizeISSN({ issn => $issn, strip_hyphen => 1 }) ); |
1668 |
|
1669 |
# Strip out any "empty" strings from the array |
1670 |
@issns = grep { defined($_) && $_ =~ /\S/ } @issns; |
1671 |
|
1672 |
return wantarray ? @issns : join( " | ", @issns ); |
1673 |
} |
1674 |
|
1675 |
=head2 GetVariationsOfISSNs |
1676 |
|
1677 |
my @issns = GetVariationsOfISSNs( @issns ); |
1678 |
|
1679 |
Returns a list of variations of the given issns in |
1680 |
with and without a hyphen. |
1681 |
|
1682 |
In a scalar context, the issns are returned as a |
1683 |
string delimited by ' | '. |
1684 |
|
1685 |
=cut |
1686 |
|
1687 |
sub GetVariationsOfISSNs { |
1688 |
my (@issns) = @_; |
1689 |
|
1690 |
@issns = map { GetVariationsOfISSN( $_ ) } @issns; |
1691 |
|
1692 |
return wantarray ? @issns : join( " | ", @issns ); |
1693 |
} |
1694 |
|
1695 |
|
1607 |
=head2 IsKohaFieldLinked |
1696 |
=head2 IsKohaFieldLinked |
1608 |
|
1697 |
|
1609 |
my $is_linked = IsKohaFieldLinked({ |
1698 |
my $is_linked = IsKohaFieldLinked({ |