リビジョン | 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
@@ -654,6 +654,7 @@ class Tracker_list | ||
654 | 654 | var $pattern_fields; |
655 | 655 | var $rows; |
656 | 656 | var $order; |
657 | + var $sort_keys; | |
657 | 658 | |
658 | 659 | function Tracker_list($page,$refer,&$config,$list) |
659 | 660 | { |
@@ -738,6 +739,22 @@ class Tracker_list | ||
738 | 739 | } |
739 | 740 | } |
740 | 741 | } |
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 | + } | |
741 | 758 | function sort($order) |
742 | 759 | { |
743 | 760 | if ($order == '') |
@@ -770,26 +787,17 @@ class Tracker_list | ||
770 | 787 | } |
771 | 788 | $this->order[$key] = $dir; |
772 | 789 | } |
773 | - $keys = array(); | |
774 | - $params = array(); | |
790 | + $sort_keys = array(); | |
775 | 791 | foreach ($this->order as $field=>$order) |
776 | 792 | { |
777 | 793 | if (!array_key_exists($field,$names)) |
778 | 794 | { |
779 | 795 | continue; |
780 | 796 | } |
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); | |
789 | 798 | } |
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')); | |
793 | 801 | } |
794 | 802 | function replace_item($arr) |
795 | 803 | { |