Select group search filter working on groups' child

This commit is contained in:
Calvo 2021-11-18 11:33:34 +01:00
parent a5cfe3869c
commit 283dadc72d
1 changed files with 11 additions and 7 deletions

View File

@ -301,6 +301,7 @@ function users_get_groups(
$search=''
) {
static $group_cache = [];
$filter = '';
// Added users_group_cache to avoid unnecessary proccess on massive calls...
@ -342,13 +343,6 @@ function users_get_groups(
$query = 'SELECT * FROM tgrupo ORDER BY nombre';
$raw_groups = db_get_all_rows_sql($query);
if (empty($search) === false) {
$filter = sprintf(
' AND lower(tgrupo.nombre) like lower("%%%s%%")',
$search
);
}
$query = sprintf(
"SELECT tgrupo.*, tperfil.*, tusuario_perfil.tags, tusuario_perfil.no_hierarchy FROM tgrupo, tusuario_perfil, tperfil
WHERE (tgrupo.id_grupo = tusuario_perfil.id_grupo OR tusuario_perfil.id_grupo = 0)
@ -451,6 +445,16 @@ function users_get_groups(
}
}
// Search filter.
if (empty($search) === false) {
$user_groups = array_filter(
$user_groups,
function ($group) use ($search) {
return (bool) preg_match('/'.$search.'/i', $group['nombre']);
}
);
}
$users_group_cache[$users_group_cache_key] = $user_groups;
return $user_groups;