I'm trying to find out what the highest role a user has, by points. The userpoints_role_highest_role() function fetches the current points for a given user, fetches all of the roles and points for those roles, and then builds an associative array of point value => role name of all the roles for the user. It then returns the output of max() on this array.

However, MAX() doesn't work that way. When passed an array, it sorts the values and returns the highest value. In my case, the role "wizard" is getting returned incorrectly, simply because that's what MAX() returns as the highest. Here's what the module needs to do instead:

return $roles_within[max(array_keys($roles_within))];

CommentFileSizeAuthor
#1 1365354-userpoints_role.module.patch627 bytesebeyrent
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ebeyrent’s picture

Here's a patch....

Berdir’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 1365354-userpoints_role.module.patch, failed testing.