Skip to content

Instantly share code, notes, and snippets.

@chdemko
Created December 17, 2011 02:09
Show Gist options
  • Save chdemko/1488872 to your computer and use it in GitHub Desktop.
Save chdemko/1488872 to your computer and use it in GitHub Desktop.
protected static function _getUserGroups()
{
// Get a database object.
$db = JFactory::getDBO();
// Get the user groups from the database.
$db->setQuery(
'SELECT a.id AS value, a.title AS text, b.id as parent'
. ' FROM #__usergroups AS a' . ' LEFT JOIN #__usergroups AS b ON a.lft >= b.lft AND a.rgt <= b.rgt'
. ' ORDER BY a.lft ASC, b.lft ASC'
);
$result = $db->loadObjectList();
$options = array();
// Pre-compute additional values.
foreach ($result as $option)
{
$end = end($options);
if ($end === false || $end->value != $option->value)
{
$end = $option;
$end->level = 0;
$options[] = $end;
}
else
{
$end->level++;
}
$end->identities[] = $option->parent;
}
return $options;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment