function user_badges_get_roles in User Badges 7.3
Same name and namespace in other branches
- 5 user_badges.module \user_badges_get_roles()
- 6.2 user_badges.module \user_badges_get_roles()
- 6 user_badges.module \user_badges_get_roles()
- 7.4 user_badges.module \user_badges_get_roles()
- 7 user_badges.module \user_badges_get_roles()
- 7.2 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.
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_update in ./
user_badges.module - Implementation of hook_user_update(). Will save the roles for a particular user each time that user is updated.
File
- ./
user_badges.module, line 1030 - @brief User Badges module file
Code
function user_badges_get_roles($rids = 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 (count($rids)) {
$query
->condition('ubr.rid', array_keys($rids), 'IN');
}
$records = $query
->execute();
foreach ($records as $row) {
if ($options['returnbadges']) {
$roles[$row->rid] = $row;
}
else {
$roles[$row->rid] = $row->bid;
}
}
return $roles;
}