You are here

function user_badges_get_roles in User Badges 7

Same name and namespace in other branches
  1. 5 user_badges.module \user_badges_get_roles()
  2. 6.2 user_badges.module \user_badges_get_roles()
  3. 6 user_badges.module \user_badges_get_roles()
  4. 7.4 user_badges.module \user_badges_get_roles()
  5. 7.2 user_badges.module \user_badges_get_roles()
  6. 7.3 user_badges.module \user_badges_get_roles()

Returns an array where keys are role ids (rid) and values are the badge ids (bid) associated with that role These values are assigned on admin/people/user_badges/roles

Parameters

$rid - if set, return only values for this role:

$options - array of options: $options['returnbadges'] - if TRUE, return badge objects, not just bids

Return value

a list of roles pt the whole badge object.

4 calls to user_badges_get_roles()
user_badges_for_uid in ./user_badges.module
Returns HTML representation of user badges for given uid
user_badges_roles_form in ./user_badges.admin.inc
Form to associated badges with roles.
user_badges_user_insert in ./user_badges.module
Implements hook_user_insert().
user_badges_user_presave in ./user_badges.module
Implements hook_user_presave().

File

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

Code

function user_badges_get_roles($rid = NULL, $options = array()) {
  $roles = array();
  $options = array_merge(array(
    'returnbadges' => FALSE,
  ), $options);
  $query = db_select('user_badges_roles', 'ubr');
  $query
    ->join('user_badges_badges', 'ubb', 'ubb.bid = ubr.bid');
  $query
    ->fields('ubr', array(
    'rid',
  ))
    ->fields('ubb');
  if ($rid) {
    $query
      ->condition('ubr.rid', $rid);
  }
  $records = $query
    ->execute();
  foreach ($records as $row) {
    if ($options['returnbadges']) {
      $roles[$row->rid] = $row;
    }
    else {
      $roles[$row->rid] = $row->bid;
    }
  }
  return $roles;
}