Commit 8341c92b authored by Ruslan Kabalin's avatar Ruslan Kabalin Committed by Francois Marier
Browse files

Refactoring of group search functions


Signed-off-by: default avatarRuslan Kabalin <ruslan.kabalin@luns.net.uk>
Signed-off-by: default avatarFrancois Marier <francois@catalyst.net.nz>
parent ca0ca2de
......@@ -531,17 +531,18 @@ class PluginSearchInternal extends PluginSearch {
public static function search_group_pg($query_string, $limit, $offset, $type) {
global $USER;
$data = array();
$sql = "
SELECT
id, name, description, grouptype, jointype, ctime, mtime
FROM
{group}
WHERE (
name ILIKE '%' || ? || '%'
OR description ILIKE '%' || ? || '%'
) AND deleted = ? ";
$values = array($query_string, $query_string, 0);
if ($type == 'member') {
name ILIKE '%' || ? || '%'
OR description ILIKE '%' || ? || '%'
) AND deleted = 0 ";
$values = array($query_string, $query_string);
if ($type == 'member') {
$sql .= 'AND (
id IN (
SELECT "group" FROM {group_member} WHERE member = ?
......@@ -557,35 +558,13 @@ class PluginSearchInternal extends PluginSearch {
)';
$values[] = $USER->get('id');
}
$sql .= 'ORDER BY name';
$data = get_records_sql_array($sql, $values, $offset, $limit);
$sql = "
SELECT
COUNT(*)
FROM
{group} u
WHERE (
name ILIKE '%' || ? || '%'
OR description ILIKE '%' || ? || '%'
) AND deleted = ? ";
if ($type == 'member') {
$sql .= 'AND (
id IN (
SELECT "group" FROM {group_member} WHERE member = ?
)
)
';
}
else if ($type == 'notmember') {
$sql .= 'AND (
id NOT IN (
SELECT "group" FROM {group_member} WHERE member = ?
)
)
';
$count = get_field_sql('SELECT COUNT(*) '.$sql, $values);
if ($count > 0) {
$sql = 'SELECT id, name, description, grouptype, jointype, ctime, mtime ' . $sql . 'ORDER BY name';
$data = get_records_sql_array($sql, $values, $offset, $limit);
}
$count = get_field_sql($sql, $values);
return array(
'count' => $count,
......@@ -597,61 +576,40 @@ class PluginSearchInternal extends PluginSearch {
public static function search_group_my($query_string, $limit, $offset, $type) {
global $USER;
$data = array();
$sql = "
SELECT
id, name, description, grouptype, jointype, ctime, mtime
FROM
{group}
WHERE (
name LIKE '%' || ? || '%'
OR description LIKE '%' || ? || '%'
) AND deleted = ? ";
$values = array($query_string, $query_string, 0);
if ($type == 'member') {
name LIKE '%' || ? || '%'
OR description LIKE '%' || ? || '%'
) AND deleted = 0 ";
$values = array($query_string, $query_string);
if ($type == 'member') {
$sql .= 'AND (
id IN (
SELECT gm.group FROM {group_member} gm WHERE gm.member = ?
SELECT "group" FROM {group_member} WHERE member = ?
)
)';
$values[] = $USER->get('id');
}
else if ($type == 'notmember') {
$sql .= "AND (
$sql .= 'AND (
id NOT IN (
SELECT gm.group FROM {group_member} gm WHERE gm.member = ?
SELECT "group" FROM {group_member} WHERE member = ?
)
)";
)';
$values[] = $USER->get('id');
}
$sql .= 'ORDER BY name';
$data = get_records_sql_array($sql, $values, $offset, $limit);
$sql = "
SELECT
COUNT(*)
FROM
{group} u
WHERE (
name LIKE '%' || ? || '%'
OR description LIKE '%' || ? || '%'
) AND deleted = ? ";
if ($type == 'member') {
$sql .= 'AND (
id IN (
SELECT gm.group FROM {group_member} gm WHERE gm.member = ?
)
)
';
}
else if ($type == 'notmember') {
$sql .= "AND (
id NOT IN (
SELECT gm.group FROM {group_member} gm WHERE gm.member = ?
)
)
";
$count = get_field_sql('SELECT COUNT(*) '.$sql, $values);
if ($count > 0) {
$sql = 'SELECT id, name, description, grouptype, jointype, ctime, mtime ' . $sql . 'ORDER BY name';
$data = get_records_sql_array($sql, $values, $offset, $limit);
}
$count = get_field_sql($sql, $values);
return array(
'count' => $count,
......
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