• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

コミットメタ情報

リビジョンa76e00b0f945172a478896999db1d2d77f8bdb06 (tree)
日時2015-01-12 02:57:41
作者umorigu <umorigu@gmai...>
コミッターumorigu

ログメッセージ

BugTrack/359, BugTrack/360 Fix Tracker list sort

* BugTrack/359 Use 'usort' to sort track items instead of 'array_multisort'
* BugTrack/360 Use natucal sort via 'strnatcmp' function

変更サマリ

差分

--- a/plugin/tracker.inc.php
+++ b/plugin/tracker.inc.php
@@ -654,6 +654,7 @@ class Tracker_list
654654 var $pattern_fields;
655655 var $rows;
656656 var $order;
657+ var $sort_keys;
657658
658659 function Tracker_list($page,$refer,&$config,$list)
659660 {
@@ -738,6 +739,22 @@ class Tracker_list
738739 }
739740 }
740741 }
742+ function compare($a, $b)
743+ {
744+ foreach ($this->sort_keys as $sort_key)
745+ {
746+ $field = $sort_key['field'];
747+ $dir = $sort_key['dir'];
748+ $f = $this->fields[$field];
749+ $sort_type = $f->sort_type;
750+ $aVal = isset($a[$field]) ? $f->get_value($a[$field]) : '';
751+ $bVal = isset($b[$field]) ? $f->get_value($b[$field]) : '';
752+ $c = strnatcmp($aVal, $bVal) * ($dir === SORT_ASC ? 1 : -1);
753+ if ($c === 0) continue;
754+ return $c;
755+ }
756+ return 0;
757+ }
741758 function sort($order)
742759 {
743760 if ($order == '')
@@ -770,26 +787,17 @@ class Tracker_list
770787 }
771788 $this->order[$key] = $dir;
772789 }
773- $keys = array();
774- $params = array();
790+ $sort_keys = array();
775791 foreach ($this->order as $field=>$order)
776792 {
777793 if (!array_key_exists($field,$names))
778794 {
779795 continue;
780796 }
781- foreach ($this->rows as $row)
782- {
783- $keys[$field][] = isset($row[$field])? $this->fields[$field]->get_value($row[$field]) : '';
784- }
785- $params[] = $keys[$field];
786- $params[] = $this->fields[$field]->sort_type;
787- $params[] = $order;
788-
797+ $sort_keys[] = array('field' => $field, 'dir' => $order);
789798 }
790- $params[] = &$this->rows;
791-
792- call_user_func_array('array_multisort',$params);
799+ $this->sort_keys = $sort_keys;
800+ usort(&$this->rows, array($this, 'compare'));
793801 }
794802 function replace_item($arr)
795803 {