How to get usergroups list?

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
User avatar
nag_sunny
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 157
Joined: Sat Mar 28, 2009 6:29 am
Contact:

How to get usergroups list?

Post by nag_sunny » Sun Mar 13, 2011 1:50 pm

Hi All,

Could anyone guide me how to obtain the usergroups list in a list box or a table?

I was using below code in Joomla 1.5 but it seems to changed in 1.6

Code: Select all

$acl	=& JFactory::getACL();
$gtree	= $acl->get_group_children_tree( null, 'USERS', false );
Thanks in advance.
http://www.corejoomla.com
CjForum, CjFit, Community Surveys, Community Quiz, Community Answers, Community Polls, GPS Tools, Community Quotes, Crosswords, CjBlog

User avatar
Bakual
Joomla! Guru
Joomla! Guru
Posts: 845
Joined: Sun Dec 13, 2009 9:00 pm
Location: Switzerland
Contact:

Re: How to get usergroups list?

Post by Bakual » Mon Mar 14, 2011 11:28 am

Maybe look at the parameter type usergroup: http://docs.joomla.org/Usergroup_parameter_type
This can be easily used in forms made with JForm.

If you want to use it elsewhere, you could look at how they did in the formfield itself:
/libraries/joomla/form/fields/usergroup.php

User avatar
nag_sunny
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 157
Joined: Sat Mar 28, 2009 6:29 am
Contact:

Re: How to get usergroups list?

Post by nag_sunny » Mon Mar 14, 2011 6:33 pm

Thanks for the reply. I wanted to use group list in my custom component and found nowhere the alternate to get_group_children_tree. So I wrote a custom function for myself.

Code: Select all

    	$db = JFactory::getDbo();
    	$query = 'SELECT CONCAT( REPEAT(\'..\', COUNT(parent.id) - 1), node.title) as text, node.id as value'
    		. ' FROM #__usergroups AS node, #__usergroups AS parent'
    		. ' WHERE node.lft BETWEEN parent.lft AND parent.rgt'
    		. ' GROUP BY node.id'
    		. ' ORDER BY node.lft';
    	
    	$db->setQuery($query);
    	$groups = $db->loadObjectList();
        $attribs	= ' ';
        $attribs	.= 'size="'.count($groups).'"';
        $attribs	.= 'class="inputbox"';
        $attribs	.= 'multiple="multiple"';
        
        return JHTML::_('select.genericlist', $groups, $name, $attribs, 'value', 'text', $value, $id );
http://www.corejoomla.com
CjForum, CjFit, Community Surveys, Community Quiz, Community Answers, Community Polls, GPS Tools, Community Quotes, Crosswords, CjBlog


Locked

Return to “Joomla! 2.5 Coding”