use id instead of title
authorNiko Bochan <bochan@systopia.de>
Mon, 1 Dec 2014 11:29:20 +0000 (12:29 +0100)
committerNiko Bochan <bochan@systopia.de>
Mon, 1 Dec 2014 11:29:20 +0000 (12:29 +0100)
CRM/Utils/Sort.php

index 36c61abd21ab8b87f364b1c03f09c7b60035fa0e..789c5855876f0e338f11e921def13b7056ad3333 100644 (file)
@@ -275,17 +275,23 @@ class CRM_Utils_Sort {
   }
 
   /**
-   * Universal callback function for sorting by weight
+   * Universal callback function for sorting by weight or id
    *
    * @param $a
    * @param $b
    *
-   * @return array of items sorted by weight
+   * @return array of items sorted by weight (or id if weights are the same)
    * @access public
    */
   static function cmpFunc($a, $b) {
     if($a['weight'] == $b['weight']) {
-      return strcmp($a['title'], $b['title']);
+      $result = strcmp($a['id'], $b['id']);
+      // return -1 for equal ids to keep the behavior
+      // of the original function for equal weights
+      if ($result == 0) {
+        return -1;
+      }
+      return $result;
     }
     return ($a['weight'] <= $b['weight']) ? -1 : 1;
   }