0

I have hundreds of registered users. Those are grouped in different user groups:

See screenshot below (I changed this a little bit to protect my customers site):

  • Registered -> Teachers
  • Registered -> Students

How can I show a list of 'Teachers' online? I want to list up all those teachers in a table or list, so that other teachers see this information.

Thank you. Any information is welcome.

enter image description here

Dimitri Dewaele
  • 10,311
  • 21
  • 80
  • 127

2 Answers2

1

You can use the following for to get the usernames from a specific user group:

$teachers = JAccess::getUsersByGroup(2); //change number in the brackets
$students = JAccess::getUsersByGroup(8); //change number in the brackets
foreach($teachers as $user_id) {
    $user = JFactory::getUser($user_id);
    echo $user->name;
}
foreach($students as $user_id) {
    $user = JFactory::getUser($user_id);
    echo $user->name;
}

Change "2" and "8" to the ID's of the Teachers and Students user groups.

Hope this helps

Lodder
  • 19,758
  • 10
  • 59
  • 100
  • This answer fits my needs the most. I use the Module "Flexi Custom Code" to insert the code in a module. This module is then inserted with {loadposition xx} into an article. I also needed custom fields in my results. For this I use: $profile = JUserHelper::getProfile($user->id); echo $profile->profile['address1']; – Dimitri Dewaele Dec 23 '13 at 16:56
1

Personally, I think the best way to do that is to create a contact category teachers and then link each teacher to a contact record.

You can make a list of users in a group (there's even a method JAccess::getUsersByGroup() but I don't think it's that useful for this purpose. http://officialjoomlabook.com/school25/staff-directory is an example of where I did what I am suggesting.

Elin
  • 6,507
  • 3
  • 25
  • 47
  • I like this answer, especially together with the Joomla plugin: "User Contact Creator". This automatically creates a Contact when a user is created. But I prefer the other answer in my case, since my users have also custom fields, which don't get delivered to the contact. But this is offcourse another story. Good answer. – Dimitri Dewaele Dec 23 '13 at 16:53
  • 1
    Well actually, if you look at the contact for that user, you'll see she's displaying the results from the profile plugin plus a list of all her articles, both of which are options in com_contact display. And yes contact Creator is great for this, the only thing is that it doesn't work automatically on your old users, just on newly created ones. – Elin Dec 23 '13 at 17:06