Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I updated my site to drupal 7 and now I'm testing the modules.
I see that the userpoints role modules is not working as it should.
When users get enough points to get a new role nothing happens.
Any help?
Comment | File | Size | Author |
---|---|---|---|
#7 | RuleScreen.JPG | 84.85 KB | qsurti |
Comments
Comment #1
qsurti CreditAttribution: qsurti commentedIs anyone looking in this issue? I also do not see any role change on achieving required points for a user.
Is there any other alternative to this issue?
Comment #2
andrenoronha CreditAttribution: andrenoronha commentedThere's another issue here: http://drupal.org/node/544764
It seems the module has no one to work on it, but I came up with a solution using rules at #8.
Give it a try.
Comment #3
qsurti CreditAttribution: qsurti commentedI am a bit naive in programming. Can you please explain what the terms 'roles[x]' and '$level' stand for? Also if you can simplify it for only one change, say from 'authenticated user' to 'editor'. Many thanks.
Comment #4
andrenoronha CreditAttribution: andrenoronha commentedEach role has its unique ID. Go to you roles page and check the role id by mouse hovering the 'edit role' link. You'll got: /admin/people/permissions/roles/edit/X. Where X is the role id.
My roles are based upon levels. You won't need this.
here you go:
- Replace x for your role id.
- Replace 100 (at $loaded_points > 100) with the right amount of points required for the user to become an editor.
- Check if the name of your role is really "Editor" as I have written in the code.
I guess that's it.
Comment #5
qsurti CreditAttribution: qsurti commentedFollowing is the complete rules script I exported based on your above suggestions;
{ "rules_star_role_is_added" : {
"LABEL" : "Award Star Role to User with php script",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "userpoints_rules", "rules", "php" ],
"ON" : [ "userpoints_event_points_awarded_after" ],
"DO" : [
{ "userpoints_rules_get_current_points" : {
"USING" : { "user" : [ "userpoints-transaction:user" ], "tid" : "all" },
"PROVIDE" : { "loaded_points" : { "loaded_points" : "Number of points in the specified category." } }
}
},
{ "php_eval" : { "code" : "\/\/Get variables and load user\r\n$uid = [userpoints-transaction:user:uid];\r\n$account = user_load($uid);\r\n\r\n\/\/Check if the user is already a Star Member\r\nif ($account-\u003eroles[5]) $level = TRUE;\r\n\r\n\/\/If the user has points enough and it's not an editor yet, give them the role\r\nif ($loaded_points \u003e 6 \u0026\u0026 $level == FALSE) {\r\n if ($role = user_role_load_by_name('Star Member')) { user_multiple_role_edit(array($uid), 'add_role', $role-\u003erid); }\r\n $msg = 'Now you're a new Star Member.';\r\n}\r\n\r\n\/\/Show message\r\ndrupal_set_message($msg);" } }
]
}
}
I have set the $load_points > 6.
I later edited one of the authenticated users userpoints by resubmitting the same points showing 2 points. His has total points=7 in two transactions of 2 and 5 points. I then checked if his role has changed to 'Star Member'. Nothing has happened.
Is something missing in my actions?
Comment #6
andrenoronha CreditAttribution: andrenoronha commentedgive me a print of the rule screen, it's easier.
Comment #7
qsurti CreditAttribution: qsurti commentedIs this what you want to see?
Comment #8
qsurti CreditAttribution: qsurti commentedThe php code in above is follows;
//Get variables and load user
$uid = [userpoints-transaction:user:uid];
$account = user_load($uid);
//Check if the user is already a Star Member
if ($account->roles[4]) $level = TRUE;
//If the user has points enough and it's not an editor yet, give them the role
if ($loaded_points > 6 && $level == FALSE) {
if ($role = user_role_load_by_name('Star Member')) { user_multiple_role_edit(array($uid), 'add_role', $role->rid); }
$msg = 'Now you're a new Star Member.';
}
//Show message
drupal_set_message($msg);
Comment #9
qsurti CreditAttribution: qsurti commentedHi a.luiz.n,
I have succeeded in getting the script working by deleting the last $msg part from the php script. The entire script looks like follows;
//Get variables and load user
$uid = [userpoints-transaction:user:uid];
$account = user_load($uid);
//Check if the user is already a Star Member
if ($account->roles[4]) $level1 = TRUE;
//If the user has points enough and it's not an editor yet, give them the role
if ($loaded_points > 6 && $level1 == FALSE) {
if ($role = user_role_load_by_name('Star Member')) { user_multiple_role_edit(array($uid), 'add_role', $role->rid); }
}
However, I receive following Notices when I edit the userpoints through admin panel.
Notice: Undefined offset: 4 in eval() (line 6 of E:\web\drupal\sites\all\modules\rules\modules\php.eval.inc(146) : eval()'d code).
Notice: Undefined variable: level1 in eval() (line 9 of E:\web\drupal\sites\all\modules\rules\modules\php.eval.inc(146) : eval()'d code).
Do they pose any serious problem or shall I leave them unattended or is there a way to get them eliminated?
Thanks for all your assistance till date.
Comment #10
andrenoronha CreditAttribution: andrenoronha commentedTry this:
Comment #11
qsurti CreditAttribution: qsurti commentedThanks a lot. Everything is working fine now without showing errors.
Will the code also work in reverse if the user's points drop and he loose the Star Member role and drops down to authenticated user with the following code.
I tried but could not succeed.
Comment #12
andrenoronha CreditAttribution: andrenoronha commentedYou can't give the role "authenticated user" to a user cause it's not really a common role. All the users have it.
You have to remove the Star member role, changing the oparation of the function 'user_multiple_role_edit' from 'add role' to 'remove_role'. Try this:
Comment #13
qsurti CreditAttribution: qsurti commentedThanks a.luiz.n, I tried and it works.
Do you know anyone who can port EMF Interspire module from Drupal6 to D7? Please have a look at the issue at;
http://drupal.org/node/1331062
Comment #14
BerdirThe bug is fixed in #443196: All roles are granted when a user earns points