function user_badges_save_roles_for_uid in User Badges 7.3
Save information about a particular user's roles for user_badges (in settings)
Parameters
$roles: An array in the format rid => bid for each role/badge relationship.
1 call to user_badges_save_roles_for_uid()
- user_badges_user_update in ./
user_badges.module - Implementation of hook_user_update(). Will save the roles for a particular user each time that user is updated.
File
- ./
user_badges.module, line 1065 - @brief User Badges module file
Code
function user_badges_save_roles_for_uid($uid, $roles) {
if (is_array($roles) && isset($uid)) {
// We have to clear out all role badges first.
db_query("DELETE FROM {user_badges_user} WHERE type='role' AND uid = :uid", array(
':uid' => $uid,
));
// Now we loop through the roles and their badges, and assign them to
// the user accordingly.
foreach ($roles as $rid => $bid) {
if ($bid) {
//Insert the role for this user into the user badges user table
db_query("\n INSERT INTO {user_badges_user} (uid, bid, type)\n VALUES (:uid, :bid, 'role')", array(
':uid' => $uid,
':bid' => $bid,
));
}
}
}
}