You are here

function user_badges_remove_badge_action in User Badges 6.2

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

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

File

./user_badges.module, line 1220
@brief User Badges module file

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);
    }
  }
}