Hi i did a
front-end search for Users and it retrieve all modx Users.. but it list Manager Users too.
I only want to list "members" (group) in the front-end.
I use the RTFM
http://rtfm.modx.com/extras/revo/simplesearch/simplesearch.simplesearch/simplesearch.faceted-search-through-posthooks to build this but i fail restricting the search to a specific group.
in the PeopleFacetHook snippet i feel i should add some criteria here :
$c->where(array(
// add code here to search only to 'member' group
'username:LIKE' => '%'.$search.'%',
'OR:Profile.fullname:LIKE' => '%'.$search.'%',
'OR:Profile.email:LIKE' => '%'.$search.'%',
));
but i don't know how to write this little piece of code because user structure db is a bit too criptic for me.
Any Idea ?
CTRL+SHIFT+U - Clear Cache
CTRL+SHIFT+H - Hiding Heft Panel
CTRL+SHIFT+N - Fast Create Resource
CTRL+ALT+P - Preview Recource (in edit resorce window)
CTRL+ALT+S - Save
Quote from: absent42 at Oct 17, 2014, 12:41 PMUse pdoUser (part of pdoTools) with &groups.
http://docs.modx.pro/en/components/pdotools/snippets/pdousers
I would but do you know if pdoUsers can be used for a dynamic search form ? Because actually i use a postHook like that :
[[!SimpleSearch?
&tpl=`search-results-item`
&toPlaceholder=`sisea.results`
&perPage=`10`
&postHooks=`PeopleFacetHook` <----- THERE !
&facetLimit=`5`
]]
CTRL+SHIFT+U - Clear Cache
CTRL+SHIFT+H - Hiding Heft Panel
CTRL+SHIFT+N - Fast Create Resource
CTRL+ALT+P - Preview Recource (in edit resorce window)
CTRL+ALT+S - Save
Quote from: gissirob at Oct 17, 2014, 04:49 PMYou could try:
$c->where(array('primary_group:!=' => 1));
This should work if all your admin users belong to the default Admin group. If you have more than one group, use NOT IN.
Thanx for your suggestion but i get all the users, same.
Following your directions I tried all sort of mix based on this (
http://rtfm.modx.com/xpdo/2.x/class-reference/xpdoquery/xpdoquery.where) for the query and it looks like the result of "primary_group" is weirdo.
For reference i output
$user->get('primary_group'),
to see the result.
Web user is created on frontend with
Register ?... &usergroups=`Members`
but 'primary_group' shows 0
maybe this is related :
- If i edit the user in manager, it can see usergroup is correct ( "members"...)
- If i just open the user and save from the manager it shows now : primary_group = 2 ?!!!?
i don't understand what's happening
maybe
primary_group is not what is seems to be ?
CTRL+SHIFT+U - Clear Cache
CTRL+SHIFT+H - Hiding Heft Panel
CTRL+SHIFT+N - Fast Create Resource
CTRL+ALT+P - Preview Recource (in edit resorce window)
CTRL+ALT+S - Save
I've had issues with primary_group also. If I understand correctly, it based on the user's rank: "The User Group that has a rank of 0 will be declared the User's Primary Group". This should mean that every user that is a member of at least one group should have a non-zero primary group. This is not always the case.
I'm assuming you only have a few users that are members of the Administrator group (group id of 1). These users should have primary_group set to 1, but this doesn't always happen (look in the users table via PhpMyAdmin or similar to check).
If they are not you could try this:
- Create a new group called 'dummy' with no privs.
- make your admin users members of that group (so now they are members of the Administrator and dummy groups).
- rank the groups so that the Administrator group has a rank of 0 (do this in the Access Permissions tab).
- save changes and check to ensure your admin users now have a primary_group of 1.
The where clause above should then work.
Thank you very much for your ideas. I did what you suggest to be sure Administrators where in the primary_group = 1 and all make senses now. Nothing was changing in the front-end so i try to split the query and.. it works. As the site is intended to have a lot of members users (>1000) i hope this is optimised enough.
my final query is :
$c->where(array(
'primary_group:!=' => 1
));
$c->where(array(
'username:LIKE' => '%'.$search.'%',
'OR:Profile.fullname:LIKE' => '%'.$search.'%',
'OR:Profile.email:LIKE' => '%'.$search.'%'
));
CTRL+SHIFT+U - Clear Cache
CTRL+SHIFT+H - Hiding Heft Panel
CTRL+SHIFT+N - Fast Create Resource
CTRL+ALT+P - Preview Recource (in edit resorce window)
CTRL+ALT+S - Save