|
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 76-81
BEGIN {
Link Here
|
| 76 |
&GetVariationsOfISBN |
77 |
&GetVariationsOfISBN |
| 77 |
&GetVariationsOfISBNs |
78 |
&GetVariationsOfISBNs |
| 78 |
&NormalizeISBN |
79 |
&NormalizeISBN |
|
|
80 |
&GetVariationsOfISSN |
| 81 |
&GetVariationsOfISSNs |
| 82 |
&NormalizeISSN |
| 79 |
|
83 |
|
| 80 |
$DEBUG |
84 |
$DEBUG |
| 81 |
); |
85 |
); |
|
Lines 1809-1814
sub GetVariationsOfISBNs {
Link Here
|
| 1809 |
return wantarray ? @isbns : join( " | ", @isbns ); |
1813 |
return wantarray ? @isbns : join( " | ", @isbns ); |
| 1810 |
} |
1814 |
} |
| 1811 |
|
1815 |
|
|
|
1816 |
=head2 NormalizedISSN |
| 1817 |
|
| 1818 |
my $issns = NormalizedISSN({ |
| 1819 |
issn => $issn, |
| 1820 |
strip_hyphen => [0,1] |
| 1821 |
}); |
| 1822 |
|
| 1823 |
Returns an issn validated by Business::ISSN. |
| 1824 |
Optionally strips hyphen. |
| 1825 |
|
| 1826 |
If the string cannot be validated as an issn, |
| 1827 |
it returns nothing. |
| 1828 |
|
| 1829 |
=cut |
| 1830 |
|
| 1831 |
sub NormalizeISSN { |
| 1832 |
my ($params) = @_; |
| 1833 |
|
| 1834 |
my $string = $params->{issn}; |
| 1835 |
my $strip_hyphen = $params->{strip_hyphen}; |
| 1836 |
|
| 1837 |
my $issn = Business::ISSN->new($string); |
| 1838 |
|
| 1839 |
if ( $issn && $issn->is_valid ){ |
| 1840 |
|
| 1841 |
if ($strip_hyphen) { |
| 1842 |
$string = $issn->_issn; |
| 1843 |
} |
| 1844 |
else { |
| 1845 |
$string = $issn->as_string; |
| 1846 |
} |
| 1847 |
return $string; |
| 1848 |
} |
| 1849 |
|
| 1850 |
} |
| 1851 |
|
| 1852 |
=head2 GetVariationsOfISSN |
| 1853 |
|
| 1854 |
my @issns = GetVariationsOfISSN( $issn ); |
| 1855 |
|
| 1856 |
Returns a list of variations of the given issn in |
| 1857 |
with and without a hyphen. |
| 1858 |
|
| 1859 |
In a scalar context, the issns are returned as a |
| 1860 |
string delimited by ' | '. |
| 1861 |
|
| 1862 |
=cut |
| 1863 |
|
| 1864 |
sub GetVariationsOfISSN { |
| 1865 |
my ($issn) = @_; |
| 1866 |
|
| 1867 |
return unless $issn; |
| 1868 |
|
| 1869 |
my @issns; |
| 1870 |
|
| 1871 |
push( @issns, NormalizeISSN({ issn => $issn }) ); |
| 1872 |
push( @issns, NormalizeISSN({ issn => $issn, strip_hyphen => 1 }) ); |
| 1873 |
|
| 1874 |
# Strip out any "empty" strings from the array |
| 1875 |
@issns = grep { defined($_) && $_ =~ /\S/ } @issns; |
| 1876 |
|
| 1877 |
return wantarray ? @issns : join( " | ", @issns ); |
| 1878 |
} |
| 1879 |
|
| 1880 |
=head2 GetVariationsOfISSNs |
| 1881 |
|
| 1882 |
my @issns = GetVariationsOfISSNs( @issns ); |
| 1883 |
|
| 1884 |
Returns a list of variations of the given issns in |
| 1885 |
with and without a hyphen. |
| 1886 |
|
| 1887 |
In a scalar context, the issns are returned as a |
| 1888 |
string delimited by ' | '. |
| 1889 |
|
| 1890 |
=cut |
| 1891 |
|
| 1892 |
sub GetVariationsOfISSNs { |
| 1893 |
my (@issns) = @_; |
| 1894 |
|
| 1895 |
@issns = map { GetVariationsOfISSN( $_ ) } @issns; |
| 1896 |
|
| 1897 |
return wantarray ? @issns : join( " | ", @issns ); |
| 1898 |
} |
| 1899 |
|
| 1900 |
|
| 1812 |
=head2 IsKohaFieldLinked |
1901 |
=head2 IsKohaFieldLinked |
| 1813 |
|
1902 |
|
| 1814 |
my $is_linked = IsKohaFieldLinked({ |
1903 |
my $is_linked = IsKohaFieldLinked({ |