#
# This file is part of Koha.
#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
use strict;
use warnings;
-use vars qw($VERSION);
-# set the version for version checking
-$VERSION = 3.07.00.049;
=head1 NAME
=head1 SYNOPSIS
-use C4::ClassSortRoutine;
+use C4::ClassSortRoutine qw( GetClassSortKey );
my $cn_sort = GetClassSortKey('Dewey', $cn_class, $cn_item);
my $init = uc "$cn_class $cn_item";
$init =~ s/^\s+//;
$init =~ s/\s+$//;
+ $init =~ s/\// /g;
$init =~ s!/!!g;
$init =~ s/^([\p{IsAlpha}]+)/$1 /;
my @tokens = split /\.|\s+/, $init;
my $digit_group_count = 0;
+ my $first_digit_group_idx;
for (my $i = 0; $i <= $#tokens; $i++) {
if ($tokens[$i] =~ /^\d+$/) {
$digit_group_count++;
+ if (1 == $digit_group_count) {
+ $first_digit_group_idx = $i;
+ }
if (2 == $digit_group_count) {
- $tokens[$i] = sprintf("%-15.15s", $tokens[$i]);
- $tokens[$i] =~ tr/ /0/;
+ if ($i - $first_digit_group_idx == 1) {
+ $tokens[$i] = sprintf("%-15.15s", $tokens[$i]);
+ $tokens[$i] =~ tr/ /0/;
+ } else {
+ $tokens[$first_digit_group_idx] .= '_000000000000000'
+ }
}
}
}
# Pad the first digit_group if there was only one
if (1 == $digit_group_count) {
- $tokens[0] .= '_000000000000000'
+ $tokens[$first_digit_group_idx] .= '_000000000000000'
}
my $key = join("_", @tokens);
$key =~ s/[^\p{IsAlnum}_]//g;