diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2014-01-15 20:55:05 +0400 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2014-02-10 17:53:58 +0400 |
commit | f8620704d492287d5acb18bdc60b3a1303c01ad1 (patch) | |
tree | 39d6e0bd7ac544867cb8d148adffe4292e6f7e6a /core | |
parent | c6687e159b522d5a6879d5eb9c4930f6bc847c7d (diff) |
move sorter into a class
Diffstat (limited to 'core')
-rw-r--r-- | core/ajax/share.php | 27 |
1 files changed, 3 insertions, 24 deletions
diff --git a/core/ajax/share.php b/core/ajax/share.php index 5c2dbc6654d..21e320a4732 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -354,32 +354,11 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo break; } } - usort($shareWith, 'sortSearchFirst'); + $sorter = new \OC\Share\SearchResultSorter($_GET['search'], + 'label'); + usort($shareWith, array($sorter, 'sort')); OC_JSON::success(array('data' => $shareWith)); } break; } } - - -/** - * User and Group names matching the search term at the beginning shall appear - * on top of the share dialog. - * Callback function for usort. http://php.net/usort - */ -function sortSearchFirst($a, $b) { - $enc = 'UTF-8'; - $nameA = mb_strtolower($a['label'], $enc); - $nameB = mb_strtolower($b['label'], $enc); - $term = mb_strtolower($_GET['search'], $enc); - $i = mb_strpos($nameA, $term, 0, 'UTF-8'); - $j = mb_strpos($nameB, $term, 0, 'UTF-8'); - - if($i === $j) { - return 0; - } elseif ($i === 0) { - return -1; - } else { - return 1; - } -} |