• XEN DEVELOPMENT is a developer's resource for new developers wanting to build XenForo 2 add-ons. Experienced developers are also welcome to share their experienes and knowledge. This site is not affiliated with XenForo or a replacement for the official XenForo developer forums.

Unsolved Showing users that are a part of a specific usergroup?

Arks

New member
#1
Self Reported Skill Level
2.00 star(s)
I must admit, I'm new to this. With XenForo 1 I generally could get pages made/database information on pages/forms successfully submitted to relevant table, but with XenForo 2 I've been thrown for a loop and there isn't enough threads on simple things such as showing information from a table on a page, anyway - I'll stop ranting.

My current little project for XenForo 2 is to have a custom page that lists all members of specific usergroups with user information (avatar, name, join date, last active etc)

I've tried analyzing the code used to list all members/search in XenForo ACP for specific usergroups, but ultimately I couldn't get anywhere with it.

Do you know how to do this? I'm hoping to get this working and then move onto actually displaying custom table data onto other pages, the XF2 developer documentation wasn't that helpful as it was already pulling data from a XenForo default table and everything I've seen, custom addons and their tables approach this differently.

Sorry for bothering you, but I'm struggling since there is so little practical help threads around my needs.
 

LPH

Flight Director
Staff member
Lifetime License
#2
If you are pulling information from the xf_user table then it seems like you’d begin with $finder.

PHP:
$finder = \XF::finder('XF:User');
$users = $finder->limit(10)->fetch();
Next, dump the $users variable to see the information returned.

PHP:
\XF::dump($users);
Or

PHP:
\XF::dumpSimple($users);
Once you see what is returned then you can use information in a where to start filtering the users being returned.

A return statement might look like the following:

PHP:
return \XF::app()->templater()->fn( 'bb_code', [ $user['about'], $user, 'escaped'] );
 
Last edited:

Arks

New member
#3
Thank you dude!

Progress has been made! It is working however there is a minor issue.

PHP:
        $admins = $finderAdmins->where('secondary_group_ids', '3,4')->fetch();
As you can see, in that line it is looking for group ID of 3 & 4, this is problematic since I only want it to find users who have the ID of 3 but since its the secondary group column, it has more than one ID inside it for users. (Registered is primary group) Having just the ID of 3 in there, wasn't working since my user account has other secondary groups.



 

LPH

Flight Director
Staff member
Lifetime License
#4
Did you try fetchOne()instead of fetch()?
 

Arks

New member
#5
Did you try fetchOne()instead of fetch()?
Thanks for the response! I tried it but it didn't look to do anything. I've created several more user accounts and given them the Administrator usergroup for testing and if it has another secondary group, they vanish from the page.

The potential fix for this is to just make their primary group their actual role and make 'Registered' a secondary, but it would be a rather hackjob solution.

Here's the code at the moment -

PHP:
$hiddenAdmins = $this->options()->hiddenAdmins;

        $finderAdmins = \XF::finder('XF:User');
        $admins = $finderAdmins->where('secondary_group_ids', '3')->where('user_id', '!=', $hiddenAdmins)->fetchOne();
(The admincp exclusion thing only looks to want to exclude the first user ID in the field, but that's another issue for later.)
 

Jack

New member
Lifetime License
#6
Well you should look in the code of xenforo , you will have your solution their

Look in file src/XF/Searcher/User.php

Probably in this file you have your required code available.
 
Top