Lines 29-34
use Koha::Cache;
Link Here
|
29 |
use Koha::DateUtils qw(dt_from_string); |
29 |
use Koha::DateUtils qw(dt_from_string); |
30 |
use DateTime::Format::MySQL; |
30 |
use DateTime::Format::MySQL; |
31 |
use Business::ISBN; |
31 |
use Business::ISBN; |
|
|
32 |
use Business::ISSN; |
32 |
use autouse 'Data::cselectall_arrayref' => qw(Dumper); |
33 |
use autouse 'Data::cselectall_arrayref' => qw(Dumper); |
33 |
use DBI qw(:sql_types); |
34 |
use DBI qw(:sql_types); |
34 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG); |
35 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG); |
Lines 77-82
BEGIN {
Link Here
|
77 |
&GetVariationsOfISBN |
78 |
&GetVariationsOfISBN |
78 |
&GetVariationsOfISBNs |
79 |
&GetVariationsOfISBNs |
79 |
&NormalizeISBN |
80 |
&NormalizeISBN |
|
|
81 |
&GetVariationsOfISSN |
82 |
&GetVariationsOfISSNs |
83 |
&NormalizeISSN |
80 |
|
84 |
|
81 |
$DEBUG |
85 |
$DEBUG |
82 |
); |
86 |
); |
Lines 1872-1877
sub GetVariationsOfISBNs {
Link Here
|
1872 |
return wantarray ? @isbns : join( " | ", @isbns ); |
1876 |
return wantarray ? @isbns : join( " | ", @isbns ); |
1873 |
} |
1877 |
} |
1874 |
|
1878 |
|
|
|
1879 |
=head2 NormalizedISSN |
1880 |
|
1881 |
my $issns = NormalizedISSN({ |
1882 |
issn => $issn, |
1883 |
strip_hyphen => [0,1] |
1884 |
}); |
1885 |
|
1886 |
Returns an issn validated by Business::ISSN. |
1887 |
Optionally strips hyphen. |
1888 |
|
1889 |
If the string cannot be validated as an issn, |
1890 |
it returns nothing. |
1891 |
|
1892 |
=cut |
1893 |
|
1894 |
sub NormalizeISSN { |
1895 |
my ($params) = @_; |
1896 |
|
1897 |
my $string = $params->{issn}; |
1898 |
my $strip_hyphen = $params->{strip_hyphen}; |
1899 |
|
1900 |
my $issn = Business::ISSN->new($string); |
1901 |
|
1902 |
if ( $issn && $issn->is_valid ){ |
1903 |
|
1904 |
if ($strip_hyphen) { |
1905 |
$string = $issn->_issn; |
1906 |
} |
1907 |
else { |
1908 |
$string = $issn->as_string; |
1909 |
} |
1910 |
return $string; |
1911 |
} |
1912 |
|
1913 |
} |
1914 |
|
1915 |
=head2 GetVariationsOfISSN |
1916 |
|
1917 |
my @issns = GetVariationsOfISSN( $issn ); |
1918 |
|
1919 |
Returns a list of variations of the given issn in |
1920 |
with and without a hyphen. |
1921 |
|
1922 |
In a scalar context, the issns are returned as a |
1923 |
string delimited by ' | '. |
1924 |
|
1925 |
=cut |
1926 |
|
1927 |
sub GetVariationsOfISSN { |
1928 |
my ($issn) = @_; |
1929 |
|
1930 |
return unless $issn; |
1931 |
|
1932 |
my @issns; |
1933 |
|
1934 |
push( @issns, NormalizeISSN({ issn => $issn }) ); |
1935 |
push( @issns, NormalizeISSN({ issn => $issn, strip_hyphen => 1 }) ); |
1936 |
|
1937 |
# Strip out any "empty" strings from the array |
1938 |
@issns = grep { defined($_) && $_ =~ /\S/ } @issns; |
1939 |
|
1940 |
return wantarray ? @issns : join( " | ", @issns ); |
1941 |
} |
1942 |
|
1943 |
=head2 GetVariationsOfISSNs |
1944 |
|
1945 |
my @issns = GetVariationsOfISSNs( @issns ); |
1946 |
|
1947 |
Returns a list of variations of the given issns in |
1948 |
with and without a hyphen. |
1949 |
|
1950 |
In a scalar context, the issns are returned as a |
1951 |
string delimited by ' | '. |
1952 |
|
1953 |
=cut |
1954 |
|
1955 |
sub GetVariationsOfISSNs { |
1956 |
my (@issns) = @_; |
1957 |
|
1958 |
@issns = map { GetVariationsOfISSN( $_ ) } @issns; |
1959 |
|
1960 |
return wantarray ? @issns : join( " | ", @issns ); |
1961 |
} |
1962 |
|
1963 |
|
1875 |
=head2 IsKohaFieldLinked |
1964 |
=head2 IsKohaFieldLinked |
1876 |
|
1965 |
|
1877 |
my $is_linked = IsKohaFieldLinked({ |
1966 |
my $is_linked = IsKohaFieldLinked({ |