Follow-up Bug 5634: Ordering branches should be case independent
authorNadia Nicolaides <nanunic@gmail.com>
Wed, 19 Dec 2012 18:52:34 +0000 (15:52 -0300)
committerJared Camins-Esakov <jcamins@cpbibliography.com>
Fri, 21 Dec 2012 12:42:18 +0000 (07:42 -0500)
This patch fix the order of branches in the log-in page,
on Branch.pm we added the variable branchcode to the
hash returned by GetBranchesLoop, and this function is used
on Auth.pm to get a list of branches ordered by branchname

To test
1) Use an installation with some branches
2) On login screen the branches are ordered by branchcode
3) apply the patch
4) On login screen the branches are now ordered by branchname

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
This patch works as expected. Before applying the patch the branches
with lower case was at the end of the list. Now they are well ordered.
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
C4/Auth.pm
C4/Branch.pm

index 4ea03c0..b32136a 100644 (file)
@@ -934,17 +934,11 @@ sub checkauth {
         my $value = $query->param($name);
         push @inputs, { name => $name, value => $value };
     }
-    # get the branchloop, which we need for authentication
-    my $branches = GetBranches();
-    my @branch_loop;
-    for my $branch_hash (sort keys %$branches) {
-               push @branch_loop, {branchcode => "$branch_hash", branchname => $branches->{$branch_hash}->{'branchname'}, };
-    }
 
     my $template_name = ( $type eq 'opac' ) ? 'opac-auth.tmpl' : 'auth.tmpl';
     my $template = C4::Templates::gettemplate($template_name, $type, $query );
     $template->param(
-        branchloop           => \@branch_loop,
+        branchloop           => GetBranchesLoop(),
         opaccolorstylesheet  => C4::Context->preference("opaccolorstylesheet"),
         opaclayoutstylesheet => C4::Context->preference("opaclayoutstylesheet"),
         login                => 1,
index d765c99..fe67e0c 100644 (file)
@@ -160,11 +160,12 @@ sub GetBranchesLoop {  # since this is what most pages want anyway
     my $onlymine = @_ ? shift : onlymine();
     my $branches = GetBranches($onlymine);
     my @loop;
-    foreach ( sort { uc($branches->{$a}->{branchname}) cmp uc($branches->{$b}->{branchname}) } keys %$branches ) {
+    foreach my $branchcode ( sort { uc($branches->{$a}->{branchname}) cmp uc($branches->{$b}->{branchname}) } keys %$branches ) {
         push @loop, {
-            value => $_,
-            selected => ($_ eq $branch) ? 1 : 0, 
-            branchname => $branches->{$_}->{branchname},
+            value      => $branchcode,
+            branchcode => $branchcode,
+            selected   => ($branchcode eq $branch) ? 1 : 0,
+            branchname => $branches->{$branchcode}->{branchname},
         };
     }
     return \@loop;