summaryrefslogtreecommitdiffstats
path: root/core/ajax
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2014-01-15 13:26:08 +0100
committerArthur Schiwon <blizzz@owncloud.com>2014-02-11 10:49:22 +0100
commit71e4d965a1d468ac01b404f233397def3b580ab2 (patch)
treecffb123c5572f262d5ae1e9b3243f45bb6fa8db5 /core/ajax
parentbea80ffe2060407e5d849a86f71fae2eed80b08e (diff)
downloadnextcloud-server-71e4d965a1d468ac01b404f233397def3b580ab2.tar.gz
nextcloud-server-71e4d965a1d468ac01b404f233397def3b580ab2.zip
on filtering the share box users and groups whose name begins with the search term shall appear on top, fixes #6430
Diffstat (limited to 'core/ajax')
-rw-r--r--core/ajax/share.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/core/ajax/share.php b/core/ajax/share.php
index 8b48effb458..784b2528f40 100644
--- a/core/ajax/share.php
+++ b/core/ajax/share.php
@@ -354,8 +354,32 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
break;
}
}
+ usort($shareWith, 'sortSearchFirst');
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;
+ } else if ($i === 0) {
+ return -1;
+ } else {
+ return 1;
+ }
+}