From 95cb6e670e819f6495c3bd80bb7e13406e029247 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Sat, 21 May 2016 21:36:57 -0500
Subject: [PATCH] queue: Localize and sort the searchable field listing

---
 include/class.queue.php                        | 17 +++++++++++++++--
 include/staff/templates/queue-tickets.tmpl.php |  3 ++-
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/include/class.queue.php b/include/class.queue.php
index ac8fd3381..49005516d 100644
--- a/include/class.queue.php
+++ b/include/class.queue.php
@@ -298,7 +298,7 @@ class CustomQueue extends VerySimpleModel {
                 list($label, $field) = $F;
             }
             else {
-                $label = $F->get('label');
+                $label = $F->getLocal('label');
                 $field = $F;
             }
             $fields[$path] = array($label, $field);
@@ -318,7 +318,7 @@ class CustomQueue extends VerySimpleModel {
             foreach ($otherFields as $id=>$F) {
                 list($form, $field) = $F;
                 $label = sprintf("%s / %s",
-                    $form->getTitle(), $field->get('label'));
+                    $form->getTitle(), $field->getLocal('label'));
                 $fields["entries__answers!{$id}__value"] = array(
                     $label, $field);
             }
@@ -341,6 +341,19 @@ class CustomQueue extends VerySimpleModel {
             }
         }
 
+        // Sort the field listing by the (localized) label name
+        if (function_exists('collator_create')) {
+            $coll = Collator::create(Internationalization::getCurrentLanguage());
+            $keys = array_map(function($a) use ($coll) {
+                return $coll->getSortKey($a[0]);
+            }, $fields);
+        }
+        else {
+            // Fall back to 8-bit string sorting
+            $keys = array_map(function($a) { return $a[0]; }, $fields);
+        }
+        array_multisort($keys, $fields);
+
         return $fields;
     }
 
diff --git a/include/staff/templates/queue-tickets.tmpl.php b/include/staff/templates/queue-tickets.tmpl.php
index 22475ec6f..69189caf3 100644
--- a/include/staff/templates/queue-tickets.tmpl.php
+++ b/include/staff/templates/queue-tickets.tmpl.php
@@ -104,7 +104,8 @@ $pageNav->setURL('tickets.php', $args);
     <span class="valign-helper"></span>
     <?php
     require 'queue-quickfilter.tmpl.php';
-    require 'queue-sort.tmpl.php';
+    if (count($queue->sorts))
+        require 'queue-sort.tmpl.php';
     ?>
   </div>
     <form action="tickets.php" method="get" onsubmit="javascript:
-- 
GitLab