Manaus Posted March 4, 2014 Share Posted March 4, 2014 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 More sharing options...
Soma Posted March 4, 2014 Share Posted March 4, 2014 How about $u = $users->find("roles=utente, roles!=superuser|guest"); Link to comment Share on other sites More sharing options...
Pierre-Luc Posted March 4, 2014 Share Posted March 4, 2014 I confirm, trying with the Selector test modules, this is working : template=user, roles!=affiliate, roles=editor Commas are the AND selector. 1 Link to comment Share on other sites More sharing options...
Manaus Posted March 4, 2014 Author Share Posted March 4, 2014 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 More sharing options...
kongondo Posted March 4, 2014 Share Posted March 4, 2014 (edited) 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 March 4, 2014 by kongondo Link to comment Share on other sites More sharing options...
Pierre-Luc Posted March 4, 2014 Share Posted March 4, 2014 Guest is a mandatory role for every users. Excluding guest will exclude all users. TLDR, never use !=guest. Link to comment Share on other sites More sharing options...
Manaus Posted March 5, 2014 Author Share Posted March 5, 2014 Thanks guys, sorry, late night, slow thinking Link to comment Share on other sites More sharing options...
Juergen Posted August 16, 2017 Share Posted August 16, 2017 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 More sharing options...
maxf5 Posted August 16, 2017 Share Posted August 16, 2017 exclude all users which have the role "facebook-login". $users->find("roles!=login-facebook"); transposed digits (Zahlendreher) Link to comment Share on other sites More sharing options...
Juergen Posted August 16, 2017 Share Posted August 16, 2017 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. :-( In opposition "roles=login-facebook" works. Link to comment Share on other sites More sharing options...
abdus Posted August 16, 2017 Share Posted August 16, 2017 I can confirm that I have the same issue. Not selector doesn't seem to have an effect. 1 Link to comment Share on other sites More sharing options...
Juergen Posted August 16, 2017 Share Posted August 16, 2017 Thanks @abdus, I will wait for a while if someone posts another solution. Otherwise I will open a new Issue on Github. Best regards Link to comment Share on other sites More sharing options...
maxf5 Posted August 16, 2017 Share Posted August 16, 2017 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,... 1 Link to comment Share on other sites More sharing options...
Juergen Posted August 16, 2017 Share Posted August 16, 2017 Yes, the id of the role works, but I think this is not usual behavior that the name of the role works with "=" and not with "!=". Anyway, thanks for the tipp!!!!!!! Link to comment Share on other sites More sharing options...
Juergen Posted August 16, 2017 Share Posted August 16, 2017 Only as an information: I have opened a new github issue at https://github.com/processwire/processwire-issues/issues/344 2 Link to comment Share on other sites More sharing options...
Juergen Posted August 22, 2017 Share Posted August 22, 2017 Issue will be fixed by Ryan in the next update https://github.com/processwire/processwire-issues/issues/344#issuecomment-324061230 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now