You are here

function user_badges_add_role_based_badge in User Badges 7.4

Selects all users to remove role-based badges from.

Parameters

int $bid The badge id we are adding to.:

int $rid The role id we are adding the corresponding badge to.:

int $blocked The id of the blocked user bid. If included, we will: ignore the rid.

Return value

null.

2 calls to user_badges_add_role_based_badge()
user_badges_cron in ./user_badges.module
Implements hook_cron().
user_badges_roles_form_add_badges_submit in includes/user_badges.admin.inc
Submit for add badges to corresponding users.

File

./user_badges.module, line 1115
Hooks and other stuff related to user badge.

Code

function user_badges_add_role_based_badge($bid, $rid = FALSE, $blocked = FALSE) {
  $user_badge = user_badge_load($bid);
  if ($rid == 2) {
    $query = db_select('users', 'u')
      ->condition('u.status', 1, '=');
  }
  elseif ($blocked) {
    $query = db_select('users', 'u')
      ->condition('status', 0, '=')
      ->condition('uid', 1, '>');
  }
  else {
    $query = db_select('users_roles', 'u')
      ->condition('u.rid', $rid, '=');
  }
  $sub_query = db_select('user_badges_assignment', 'ub')
    ->fields('ub', array(
    'uid',
  ))
    ->condition('bid', $bid, '=');
  $results = $query
    ->fields('u', array(
    'uid',
  ))
    ->condition('uid', $sub_query, 'NOT IN')
    ->execute()
    ->fetchCol();
  foreach ($results as $uid) {
    $retun = user_badges_user_add_badge($uid, $bid, 2, $user_badge->weight, 0);
  }
}