Jump to content

Finding users by not roles


Manaus
 Share

Recommended Posts

Hello,

I have a list where users can have two or more roles: guest+utente, guest+utente+superuser, guest

I need to find all users having 'utente' as role, but not admin, nor guest.

Tried this

$u = $users->find("roles*=utente");
$u = $users->find("roles=utente")->not("roles=superuser")->not("roles=guest");
$u = $users->find("roles!=superuser")->find("roles=utente");

But without success..

Thanks for any suggestion

Link to comment
Share on other sites

Thanks Soma and Pierre-Luc,

The query roles=utente, roles!=superuser|guest returns an empty array, I need to keep users having guest+utente, and exclude users who have utente+admin role (I don't think changing the password to a guest bears consequences, does it?)

Link to comment
Share on other sites

Pierre already gave you an answer. What you want is an AND (,) condition not an OR (|) in your selector. So....

$u = $users->find("roles=utente, roles=guest");

should give you what you want...That means, find users who have utente AND guest role. 

Both types of selectors are documented in the docs OR  AND

Edit: Clarification...

See Pierre's post below. Above example is just for illustration and is somewhat redundant. All you need to search for is "utente" since everybody has a guest role....

Edited by kongondo
Link to comment
Share on other sites

  • 3 years later...

The suggestions above dont work in my case (PW 3.0.71).

I am using the following code to exclude all users which have the role "facebook-login".

$users->find("roles!=login-facebook");

But this shows all users, even users with the role "login-facebook", so it seems that "!=" (not) will not be accepted. Just to mention: my users have sometimes more than 1 role.

Does anyone know how to define a "not" in a find method.

Best regards Jürgen

Link to comment
Share on other sites

Hello maxf5,

yep that was a copy/paste mistake in the previous post, but on my site I have used the right role name and it doesnt work at all. So its not the wrong order of the words. :-(

Screenshot_2.jpg.ba4c3909f2a873b0d66ee920d6460f58.jpg

In opposition "roles=login-facebook" works.

Link to comment
Share on other sites

hey guys, try:

// replace 38 with the id of the user role, here 38 = superuser
$items = $users->find("roles!=38"); 
foreach ($items as $i) {
	// returns guest, superuser excluded
	echo $i->name; 
}

you will find the role-id in the url when you edit Admin > Access > Roles > guest, superuser, login-facebook,...

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...