]> BookStack Code Mirror - bookstack/blobdiff - app/Sorting/SortSetOperationComparisons.php
Sort Rules: Updated name comparison to not ignore non-ascii chars
[bookstack] / app / Sorting / SortSetOperationComparisons.php
index e1c3e625f9fb84956df078145416897a22d4c8ea..cb20e1860f76f1a337e7ccc884b1bfee8b068ed7 100644 (file)
@@ -2,24 +2,24 @@
 
 namespace BookStack\Sorting;
 
+use voku\helper\ASCII;
 use BookStack\Entities\Models\Chapter;
 use BookStack\Entities\Models\Entity;
 
 /**
  * Sort comparison function for each of the possible SortSetOperation values.
  * Method names should be camelCase names for the SortSetOperation enum value.
- * TODO - Test to cover each SortSetOperation enum value is covered.
  */
 class SortSetOperationComparisons
 {
     public static function nameAsc(Entity $a, Entity $b): int
     {
-        return $a->name <=> $b->name;
+        return strtolower(ASCII::to_transliterate($a->name, null)) <=> strtolower(ASCII::to_transliterate($b->name, null));
     }
 
     public static function nameDesc(Entity $a, Entity $b): int
     {
-        return $b->name <=> $a->name;
+        return strtolower(ASCII::to_transliterate($b->name, null)) <=> strtolower(ASCII::to_transliterate($a->name, null));
     }
 
     public static function nameNumericAsc(Entity $a, Entity $b): int
@@ -27,9 +27,12 @@ class SortSetOperationComparisons
         $numRegex = '/^\d+(\.\d+)?/';
         $aMatches = [];
         $bMatches = [];
-        preg_match($numRegex, $a, $aMatches);
-        preg_match($numRegex, $b, $bMatches);
-        return ($aMatches[0] ?? 0) <=> ($bMatches[0] ?? 0);
+        preg_match($numRegex, $a->name, $aMatches);
+        preg_match($numRegex, $b->name, $bMatches);
+        $aVal = floatval(($aMatches[0] ?? 0));
+        $bVal = floatval(($bMatches[0] ?? 0));
+
+        return $aVal <=> $bVal;
     }
 
     public static function nameNumericDesc(Entity $a, Entity $b): int