function mass_contact_role_user_edit in Mass Contact 7
Creates a list of categories the user is part of.
Parameters
object $user: The user object of the user for which the available categories are sought.
Return value
array The form snippet.
1 string reference to 'mass_contact_role_user_edit'
- mass_contact_role.inc in plugins/
mass_contact_role.inc
File
- plugins/
mass_contact_role.inc, line 207
Code
function mass_contact_role_user_edit($user) {
// Get all the roles for which this user is a member.
$user_roles = db_select('users_roles', 'ur')
->fields('ur', array(
'rid',
))
->condition('uid', $user->uid)
->execute();
// Put the role IDs into an array for later use.
$users_roles = array();
// Start with the 'authenticated user' role, as it's not in the database.
$users_roles[] = 2;
foreach ($user_roles as $user_role) {
$users_roles[] = $user_role->rid;
}
// Get all the Mass Contact categories.
$categories = db_select('mass_contact', 'mc')
->fields('mc', array(
'cid',
'category',
'recipients',
))
->execute();
// Collect all the categories which contain roles the user is in.
$included_categories = array();
// Iterate through each category.
foreach ($categories as $category) {
// Pull out the roles that are a part of this category.
$recipients = unserialize($category->recipients);
foreach ($recipients['mass_contact_role'] as $role_id) {
// If the category's role is one the user is in, include the category.
if (in_array($role_id, $users_roles)) {
$included_categories[$category->cid] = check_plain($category->category);
}
}
}
return $included_categories;
}