Commit ab48ca13 authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan
Browse files

group owners no longer appear for moderator selection

parent 8fa70227
......@@ -88,6 +88,7 @@ class PluginInteractionForum extends PluginInteraction {
'description' => get_string('moderatorsdescription', 'interaction.forum'),
'defaultvalue' => isset($moderators) ? $moderators : null,
'group' => $group->id,
'owner' => false,
'filter' => false,
'lefttitle' => get_string('potentialmoderators', 'interaction.forum'),
'righttitle' => get_string('currentmoderators', 'interaction.forum')
......
......@@ -43,11 +43,10 @@ $limit = param_integer('limit', 20);
$offset = param_integer('offset', 0);
$allfields = param_boolean('allfields');
$group = param_integer('group', 0);
$owner = param_boolean('owner', true);
if ($group) {
$data = array(
'group' => $group
);
$data = array('group' => $group, 'owner' => $owner);
$data = search_user($query, $limit, $offset, $data);
}
else {
......
......@@ -71,6 +71,7 @@ function pieform_element_userlist(Pieform $form, $element) {
if (!empty($element['group'])) {
$smarty->assign('group', $element['group']);
$smarty->assign('owner', !isset($element['owner']) || $element['owner'] ? 1 : 0);
}
return $smarty->fetch('form/userlist.tpl');
......
......@@ -40,6 +40,10 @@ class PluginSearchInternal extends PluginSearch {
* @param string The query string
* @param integer How many results to return
* @param integer What result to start at (0 == first result)
* @param data Filters the users searched by
* can contain:
* 'group' => integer, // only users in this group
* 'owner' => boolean // include the group ownwer (only if group is set)
* @return array A data structure containing results looking like ...
* $results = array(
* count => integer, // total number of results
......@@ -78,7 +82,7 @@ class PluginSearchInternal extends PluginSearch {
return self::search_user_pg($query_string, $limit, $offset, $data, $publicfields);
}
else if (is_mysql()) {
return self::search_user_my($query_string, $limit, $offset, $publicfields);
return self::search_user_my($query_string, $limit, $offset, $data, $publicfields);
}
else {
throw new SQLException('search_user() is not implemented for your database engine (' . get_config('dbtype') . ')');
......@@ -87,18 +91,21 @@ class PluginSearchInternal extends PluginSearch {
public static function search_user_pg($query_string, $limit, $offset, $data, $publicfields) {
$fieldlist = "('" . join("','", $publicfields) . "')";
$group = isset($data['group'])
? 'INNER JOIN {group_member} g ON g.group = ' . (int)$data['group'] . ' AND g.member = u.id'
: '';
$count = get_field_sql('
SELECT
$sql = 'SELECT
COUNT(DISTINCT u.id)
FROM
{usr} u
LEFT JOIN {artefact} a ON u.id=a.owner
' . $group . '
WHERE
';
if (isset($data['group'])) {
$sql .= 'INNER JOIN {group_member} gm ON (gm.member = u.id AND gm.group = ' . (int)$data['group'] . ')
';
if (isset($data['owner']) && !$data['owner']) {
$sql .= 'INNER JOIN {group} g ON (g.id = gm.group AND g.owner != u.id)
';
}
}
$sql .= 'WHERE
u.id <> 0 AND u.active = 1
AND ((
u.preferredname ILIKE \'%\' || ? || \'%\'
......@@ -115,18 +122,24 @@ class PluginSearchInternal extends PluginSearch {
AND ( a.title ILIKE \'%\' || ? || \'%\')
)
)
',
array($query_string, $query_string, $query_string, $query_string)
);
';
$count = get_field_sql($sql, array($query_string, $query_string, $query_string, $query_string));
if ($count > 0) {
$data = get_records_sql_array('
SELECT DISTINCT ON (u.firstname, u.lastname, u.id)
$sql = 'SELECT DISTINCT ON (u.firstname, u.lastname, u.id)
u.id, u.username, u.institution, u.firstname, u.lastname, u.preferredname, u.email, u.staff
FROM {artefact} a
INNER JOIN {usr} u ON u.id = a.owner
' . $group . '
WHERE
';
if (isset($data['group'])) {
$sql .= 'INNER JOIN {group_member} gm ON (gm.member = u.id AND gm.group = ' . (int)$data['group'] . ')
';
if (isset($data['owner']) && !$data['owner']) {
$sql .= 'INNER JOIN {group} g ON (g.id = gm.group AND g.owner != u.id)
';
}
}
$sql .= 'WHERE
u.id <> 0 AND u.active = 1
AND ((
u.preferredname ILIKE \'%\' || ? || \'%\'
......@@ -143,7 +156,8 @@ class PluginSearchInternal extends PluginSearch {
AND ( a.title ILIKE \'%\' || ? || \'%\')
)
)
ORDER BY u.firstname, u.lastname, u.id',
ORDER BY u.firstname, u.lastname, u.id';
$data = get_records_sql_array($sql,
array($query_string, $query_string, $query_string, $query_string),
$offset,
$limit);
......@@ -169,19 +183,21 @@ class PluginSearchInternal extends PluginSearch {
public static function search_user_my($query_string, $limit, $offset, $data, $publicfields) {
$fieldlist = "('" . join("','", $publicfields) . "')";
$group = isset($data['group'])
? 'INNER JOIN {group_member} g ON g.group = ' . (int)$data['group'] . ' AND g.member = u.id'
: '';
$count = get_field_sql('
SELECT
$sql = 'SELECT
COUNT(DISTINCT owner)
FROM
{usr} u
LEFT JOIN {artefact} a ON u.id=a.owner
' . $group . '
WHERE
';
if (isset($data['group'])) {
$sql .= 'INNER JOIN {group_member} gm ON (gm.member = u.id AND gm.group = ' . (int)$data['group'] . ')
';
if (isset($data['owner']) && !$data['owner']) {
$sql .= 'INNER JOIN {group} g ON (g.id = gm.group AND g.owner != u.id)
';
}
}
$sql .= 'WHERE
u.id <> 0 AND u.active = 1
AND ((
u.preferredname IS NULL
......@@ -195,9 +211,8 @@ class PluginSearchInternal extends PluginSearch {
AND ( a.title LIKE \'%\' || ? || \'%\')
)
)
',
array($query_string, $query_string, $query_string)
);
';
$count = get_field_sql($sql, array($query_string, $query_string, $query_string));
if ($count > 0) {
// @todo This is quite possibly not correct. See the postgres
......@@ -205,13 +220,20 @@ class PluginSearchInternal extends PluginSearch {
// postgres query. There is a workaround by using SELECT * followed
// by GROUP BY 1, 2, 3, but it's not really valid SQL. The other
// way is to rewrite the query using a self join on the usr table.
$data = get_records_sql_array('
SELECT DISTINCT
$sql = 'SELECT DISTINCT
u.id, u.username, u.institution, u.firstname, u.lastname, u.preferredname, u.email, u.staff
FROM {artefact} a
INNER JOIN {usr} u ON u.id = a.owner
' . $group . '
WHERE
';
if (isset($data['group'])) {
$sql .= 'INNER JOIN {group_member} gm ON (gm.member = u.id AND gm.group = ' . (int)$data['group'] . ')
';
if (isset($data['owner']) && !$data['owner']) {
$sql .= 'INNER JOIN {group} g ON (g.id = gm.group AND g.owner != u.id)
';
}
}
$sql .= 'WHERE
u.id <> 0 AND u.active = 1
AND ((
u.preferredname IS NULL
......@@ -225,8 +247,8 @@ class PluginSearchInternal extends PluginSearch {
AND ( a.title LIKE \'%\' || ? || \'%\')
)
)
ORDER BY u.firstname, u.lastname, u.id',
array($query_string, $query_string, $query_string),
ORDER BY u.firstname, u.lastname, u.id';
get_records_sql_array($sql, array($query_string, $query_string, $query_string),
$offset,
$limit);
......
......@@ -5,7 +5,7 @@
replaceChildNodes('{{$name}}_messages');
sendjsonrequest('{{$WWWROOT}}json/usersearch.php', {'query':q, 'limit': 100 {{if $group}}, 'group': {{$group}}{{/if}}}, 'GET',
sendjsonrequest('{{$WWWROOT}}json/usersearch.php', {'query':q, 'limit': 100 {{if $group}}, 'group': {{$group}} , 'owner': {{$owner}} {{/if}}}, 'GET',
function (users) {
var members = {};
var counter = 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