You are here

function user_badges_get_roles in User Badges 6.2

Same name and namespace in other branches
  1. 5 user_badges.module \user_badges_get_roles()
  2. 6 user_badges.module \user_badges_get_roles()
  3. 7.4 user_badges.module \user_badges_get_roles()
  4. 7 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/user/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

2 calls to user_badges_get_roles()
user_badges_roles_form in ./user_badges.admin.inc
form to associated badges with roles
user_badges_user in ./user_badges.module
Implements hook_user().

File

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

Code

function user_badges_get_roles($rid = NULL, $options = array()) {
  $roles = array();
  $options = array_merge(array(
    'returnbadges' => FALSE,
  ), $options);
  if ($rid) {
    $sql = db_query('SELECT ubr.rid, ubr.bid, ubb.name, ubb.image, ubb.weight, ubb.href, ubb.tid FROM {user_badges_roles} ubr INNER JOIN {user_badges_badges} ubb ON ubb.bid=ubr.bid WHERE ubr.rid = %d', $rid);
  }
  else {
    $sql = db_query('SELECT ubr.rid, ubr.bid, ubb.name, ubb.image, ubb.weight, ubb.href, ubb.tid FROM {user_badges_roles} ubr INNER JOIN {user_badges_badges} ubb ON ubb.bid=ubr.bid', $rid);
  }
  while ($row = db_fetch_object($sql)) {
    if ($options['returnbadges']) {
      $row->image = _user_badges_build_image($row);
      $roles[$row->rid] = $row;
    }
    else {
      $roles[$row->rid] = $row->bid;
    }
  }
  return $roles;
}