The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Apr 06, 2012 7:54 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Sun Aug 21, 2005 5:16 am
Posts: 453
Location: San Jose, CA
How can I make a list of all users (names) who belong to a specific group?

Specifically, I want to create a select form field with all users of a group listed - and I'm thinking it might make sense to have the names listed, but the values be the userid.

_________________
http://www.tapintu.com ~ http://www.jogyourrightbrain.com


Top
 Profile  
 
PostPosted: Fri Apr 06, 2012 8:48 pm 
Joomla! Master
Joomla! Master

Joined: Mon Oct 27, 2008 9:27 pm
Posts: 17451
Location: Akershus, Norway
http://api.joomla.org/Joomla-Platform/User/JUser.html#getAuthorisedGroups


Top
 Profile  
 
PostPosted: Fri Apr 06, 2012 9:01 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Sun Aug 21, 2005 5:16 am
Posts: 453
Location: San Jose, CA
Thanks... but I don't think that's quite what I'm looking for - it looks to me like the link you provided deals with getting all the groups of a specific user, whereas I need to know how to get all the users for a specific group.

I did figure out that I can get the list I need this way:
Code:
jimport( 'joomla.access.access' );
$coaches = JAccess::getUsersByGroup(9);


But, I don't know how to go from that to getting a list of names of those users (it seems to just get the ids)... and then to be able to list the names as select field options (with ids as the field values).

_________________
http://www.tapintu.com ~ http://www.jogyourrightbrain.com


Top
 Profile  
 
PostPosted: Fri Apr 06, 2012 9:21 pm 
Joomla! Master
Joomla! Master

Joined: Mon Oct 27, 2008 9:27 pm
Posts: 17451
Location: Akershus, Norway
http://api.joomla.org/Joomla-Platform/User/JUser.html#load

Use load in a loop.


Top
 Profile  
 
PostPosted: Fri Apr 06, 2012 11:09 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Sun Aug 21, 2005 5:16 am
Posts: 453
Location: San Jose, CA
Okay, thanks... so, when I tried 'load' I got an error (it appears to be because I'm doing this as php and javascript files loaded into Joomla pages via the Jumi component, but I'm not sure)... but that lead me to this:

Code:
jimport( 'joomla.access.access' );
$coaches = JAccess::getUsersByGroup(9);
jimport( 'joomla.user.user' );
foreach($coaches as $coaches){
$coach[$coaches] =& JFactory::getUser($coaches);
}


...and then...

Code:
<label>Coach:</label>
<select name="coachId">
<?php foreach($coach as $coach){ ?>
<option value="<?php echo $coach->id; ?>"><?php echo $coach->name; ?></option>
<?php } ?>
</select>


It appears to be working! (Well, at least I've got the select pulldown... we'll see if I can take it the next step to get the data I want from this later in the process of my 'app'.)

Thanks for your help!

_________________
http://www.tapintu.com ~ http://www.jogyourrightbrain.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 



Who is online

Users browsing this forum: jackrabbit and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group