Changeset 3105:5411dc9bea4a for inc/core/class.dc.rs.extensions.php
- Timestamp:
- 09/29/15 17:22:58 (10 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.rs.extensions.php
r2566 r3105 846 846 class rsExtUser 847 847 { 848 private static $sortfield; 849 private static $sortsign; 848 850 /** 849 851 Returns a user option. … … 877 879 return array(); 878 880 } 881 882 /** 883 Converts this record to a {@link extStaticRecord} instance. 884 885 @param rs Invisible parameter 886 */ 887 public static function toExtStatic($rs) 888 { 889 if ($rs instanceof extStaticRecord) { 890 return $rs; 891 } 892 return new extStaticRecord($rs); 893 } 879 894 } 895 896 class extStaticRecord extends staticRecord 897 { 898 private $sortfield; 899 private $sortsign; 900 901 public function __construct($rs) 902 { 903 parent::__construct($rs->__data,$rs->__info); 904 } 905 906 /** 907 Lexically sort. 908 909 @param field <b>string<b> sort field 910 @param order <b>string<b> sort order 911 */ 912 public function lexicalSort($field,$order='asc') 913 { 914 $this->sortfield = $field; 915 $this->sortsign = strtolower($order) == 'asc' ? 1 : -1; 916 917 usort($this->__data,array($this,'lexicalSortCallback')); 918 919 $this->sortfield = null; 920 $this->sortsign = null; 921 } 922 private function lexicalSortCallback($a,$b) 923 { 924 $a = $a[$this->sortfield]; 925 $b = $b[$this->sortfield]; 926 927 # Integer values 928 if ($a == (string) (integer) $a && $b == (string) (integer) $b) { 929 $a = (integer) $a; 930 $b = (integer) $b; 931 return ($a - $b) * $this->sortsign; 932 } 933 934 return strcoll(strtolower(dcUtils::removeDiacritics($a)),strtolower(dcUtils::removeDiacritics($b))) * $this->sortsign; 935 } 936 }
Note: See TracChangeset
for help on using the changeset viewer.