Commit e8dab9af authored by Pierre Spring's avatar Pierre Spring
Browse files

Added optional random ordering for group member search


Signed-off-by: default avatarPierre Spring <pierre.spring@caillou.ch>
parent 33a264cd
......@@ -333,14 +333,15 @@ function admin_user_search($queries, $constraints, $offset, $limit, $sortfield,
*
* The search term is applied against first and last names of the users in the group
*
* @param int $group The group to build results for
* @param string $query A search string to filter by
* @param int $offset What result to start showing paginated results from
* @param int $limit How many results to show
* @param array $extra User membershiptype
* @param int $group The group to build results for
* @param string $query A search string to filter by
* @param int $offset What result to start showing paginated results from
* @param int $limit How many results to show
* @param array $membershiptype User membershiptype
* @param bool $random Set to true if you want the result to be ordered by random, default false
*
*/
function get_group_user_search_results($group, $query, $offset, $limit, $membershiptype) {
function get_group_user_search_results($group, $query, $offset, $limit, $membershiptype, $random = false) {
$queries = array();
$constraints = array();
if (!empty($query)) {
......@@ -363,7 +364,7 @@ function get_group_user_search_results($group, $query, $offset, $limit, $members
}
}
$results = group_user_search($group, $queries, $constraints, $offset, $limit, $membershiptype);
$results = group_user_search($group, $queries, $constraints, $offset, $limit, $membershiptype, $random);
if ($results['count']) {
$userids = array_map(create_function('$a', 'return $a["id"];'), $results['data']);
$introductions = get_records_sql_assoc("SELECT \"owner\", title
......@@ -383,7 +384,7 @@ function get_group_user_search_results($group, $query, $offset, $limit, $members
}
function group_user_search($group, $queries, $constraints, $offset, $limit, $membershiptype) {
function group_user_search($group, $queries, $constraints, $offset, $limit, $membershiptype, $random = false) {
$plugin = get_config('searchplugin');
safe_require('search', $plugin);
return call_static_method(generate_class_name('search', $plugin), 'group_search_user',
......
......@@ -352,7 +352,7 @@ class PluginSearchInternal extends PluginSearch {
}
public static function group_search_user($group, $queries, $constraints, $offset, $limit, $membershiptype) {
public static function group_search_user($group, $queries, $constraints, $offset, $limit, $membershiptype, $random = false) {
// Only handle OR/AND expressions at the top level. Eventually we may need subexpressions.
$searchsql = '';
$values = array();
......@@ -429,6 +429,10 @@ class PluginSearchInternal extends PluginSearch {
$orderby = "gm.role = 'admin' DESC, gm.ctime, u.firstname, u.lastname, u.id";
}
if ($random) {
$orderby = db_random();
}
$count = get_field_sql('SELECT COUNT(*)' . $from, $values);
if ($count > 0) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment