You are here

function user_badges_remove_badge_action in User Badges 7.3

Same name and namespace in other branches
  1. 6.2 user_badges.module \user_badges_remove_badge_action()
  2. 6 user_badges.module \user_badges_remove_badge_action()
  3. 7.4 user_badges.actions.inc \user_badges_remove_badge_action()
  4. 7 user_badges.actions.inc \user_badges_remove_badge_action()
  5. 7.2 user_badges.actions.inc \user_badges_remove_badge_action()

Implementsa Drupal action. Removes a badge to the current user.

File

./user_badges.actions.inc, line 100
Actions for User Badges module.

Code

function user_badges_remove_badge_action(&$account, $context = array()) {
  if (isset($account->uid)) {
    $uid = $account->uid;
    $user_name = $account->name;
  }
  elseif (isset($context['uid'])) {
    $uid = $context['uid'];
    $user_name = $context['uid']->name;
  }
  else {
    global $user;
    $uid = $user->uid;
    $user_name = $user->name;
  }
  $success = TRUE;
  $badges = user_badges_get_badges('all');
  foreach ($context['badges'] as $bid) {
    $success = (bool) user_badges_user_remove_badge($uid, $bid, 'user');
    if ($success) {
      watchdog('action', 'Removed user badge %badge to user %name.', array(
        '%name' => check_plain($user_name),
        '%badge' => check_plain($badges[$bid]->name),
      ));
    }
    else {
      watchdog('action', 'Unable to remove user badge %badge to user %name.', array(
        '%name' => check_plain($user_name),
        '%badge' => check_plain($badges[$bid]->name),
      ), WATCHDOG_WARNING);
    }
  }
}