function user_badges_add_badge_action in User Badges 6
Same name and namespace in other branches
- 6.2 user_badges.module \user_badges_add_badge_action()
- 7.4 user_badges.actions.inc \user_badges_add_badge_action()
- 7 user_badges.actions.inc \user_badges_add_badge_action()
- 7.2 user_badges.actions.inc \user_badges_add_badge_action()
- 7.3 user_badges.actions.inc \user_badges_add_badge_action()
Implementsa Drupal action. Adds a badge to the current user.
File
- ./
user_badges.module, line 1159 - @brief User Badges module file
Code
function user_badges_add_badge_action(&$account, $context = array()) {
if (isset($account->uid)) {
$uid = $account->uid;
}
elseif (isset($context['uid'])) {
$uid = $context['uid'];
}
else {
global $user;
$uid = $user->uid;
}
$success = TRUE;
$badges = user_badges_get_badges('all');
foreach ($context['badges'] as $bid) {
$success = (bool) user_badges_user_add_badge($uid, $bid, 'uid');
if ($success) {
watchdog('action', 'Added user badge %badge to user %name.', array(
'%name' => check_plain($user->name),
'%badge' => check_plain($badges[$bid]->name),
));
}
else {
watchdog('action', 'Unable to add user badge %badge to user %name.', array(
'%name' => check_plain($user->name),
'%badge' => check_plain($badges[$bid]->name),
), WATCHDOG_WARNING);
}
}
}