|
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($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG); |
36 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG); |
|
Lines 71-76
BEGIN {
Link Here
|
| 71 |
&GetVariationsOfISBN |
72 |
&GetVariationsOfISBN |
| 72 |
&GetVariationsOfISBNs |
73 |
&GetVariationsOfISBNs |
| 73 |
&NormalizeISBN |
74 |
&NormalizeISBN |
|
|
75 |
&GetVariationsOfISSN |
| 76 |
&GetVariationsOfISSNs |
| 77 |
&NormalizeISSN |
| 74 |
|
78 |
|
| 75 |
$DEBUG |
79 |
$DEBUG |
| 76 |
); |
80 |
); |
|
Lines 1637-1642
sub GetVariationsOfISBNs {
Link Here
|
| 1637 |
return wantarray ? @isbns : join( " | ", @isbns ); |
1641 |
return wantarray ? @isbns : join( " | ", @isbns ); |
| 1638 |
} |
1642 |
} |
| 1639 |
|
1643 |
|
|
|
1644 |
=head2 NormalizedISSN |
| 1645 |
|
| 1646 |
my $issns = NormalizedISSN({ |
| 1647 |
issn => $issn, |
| 1648 |
strip_hyphen => [0,1] |
| 1649 |
}); |
| 1650 |
|
| 1651 |
Returns an issn validated by Business::ISSN. |
| 1652 |
Optionally strips hyphen. |
| 1653 |
|
| 1654 |
If the string cannot be validated as an issn, |
| 1655 |
it returns nothing. |
| 1656 |
|
| 1657 |
=cut |
| 1658 |
|
| 1659 |
sub NormalizeISSN { |
| 1660 |
my ($params) = @_; |
| 1661 |
|
| 1662 |
my $string = $params->{issn}; |
| 1663 |
my $strip_hyphen = $params->{strip_hyphen}; |
| 1664 |
|
| 1665 |
my $issn = Business::ISSN->new($string); |
| 1666 |
|
| 1667 |
if ( $issn && $issn->is_valid ){ |
| 1668 |
|
| 1669 |
if ($strip_hyphen) { |
| 1670 |
$string = $issn->_issn; |
| 1671 |
} |
| 1672 |
else { |
| 1673 |
$string = $issn->as_string; |
| 1674 |
} |
| 1675 |
return $string; |
| 1676 |
} |
| 1677 |
|
| 1678 |
} |
| 1679 |
|
| 1680 |
=head2 GetVariationsOfISSN |
| 1681 |
|
| 1682 |
my @issns = GetVariationsOfISSN( $issn ); |
| 1683 |
|
| 1684 |
Returns a list of variations of the given issn in |
| 1685 |
with and without a hyphen. |
| 1686 |
|
| 1687 |
In a scalar context, the issns are returned as a |
| 1688 |
string delimited by ' | '. |
| 1689 |
|
| 1690 |
=cut |
| 1691 |
|
| 1692 |
sub GetVariationsOfISSN { |
| 1693 |
my ($issn) = @_; |
| 1694 |
|
| 1695 |
return unless $issn; |
| 1696 |
|
| 1697 |
my @issns; |
| 1698 |
|
| 1699 |
push( @issns, NormalizeISSN({ issn => $issn }) ); |
| 1700 |
push( @issns, NormalizeISSN({ issn => $issn, strip_hyphen => 1 }) ); |
| 1701 |
|
| 1702 |
# Strip out any "empty" strings from the array |
| 1703 |
@issns = grep { defined($_) && $_ =~ /\S/ } @issns; |
| 1704 |
|
| 1705 |
return wantarray ? @issns : join( " | ", @issns ); |
| 1706 |
} |
| 1707 |
|
| 1708 |
=head2 GetVariationsOfISSNs |
| 1709 |
|
| 1710 |
my @issns = GetVariationsOfISSNs( @issns ); |
| 1711 |
|
| 1712 |
Returns a list of variations of the given issns in |
| 1713 |
with and without a hyphen. |
| 1714 |
|
| 1715 |
In a scalar context, the issns are returned as a |
| 1716 |
string delimited by ' | '. |
| 1717 |
|
| 1718 |
=cut |
| 1719 |
|
| 1720 |
sub GetVariationsOfISSNs { |
| 1721 |
my (@issns) = @_; |
| 1722 |
|
| 1723 |
@issns = map { GetVariationsOfISSN( $_ ) } @issns; |
| 1724 |
|
| 1725 |
return wantarray ? @issns : join( " | ", @issns ); |
| 1726 |
} |
| 1727 |
|
| 1728 |
|
| 1640 |
=head2 IsKohaFieldLinked |
1729 |
=head2 IsKohaFieldLinked |
| 1641 |
|
1730 |
|
| 1642 |
my $is_linked = IsKohaFieldLinked({ |
1731 |
my $is_linked = IsKohaFieldLinked({ |