[Pkg-owncloud-commits] [owncloud] 83/145: on filtering the share box users and groups whose name begins with the search term shall appear on top, fixes #6430

David Prévot taffit at moszumanska.debian.org
Wed Feb 26 16:27:44 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit 8227bc41cddc4ce5437c568573f4c6e8a8f14e03
Author: Arthur Schiwon <blizzz at owncloud.com>
Date:   Wed Jan 15 13:26:08 2014 +0100

    on filtering the share box users and groups whose name begins with the search term shall appear on top, fixes #6430
---
 core/ajax/share.php | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/core/ajax/share.php b/core/ajax/share.php
index 8b48eff..784b252 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;
+	}
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list