function og_subscribe_user in Organic groups 6.2
Same name and namespace in other branches
- 5.8 og.module \og_subscribe_user()
- 5 og.module \og_subscribe_user()
- 5.2 og.module \og_subscribe_user()
- 5.3 og.module \og_subscribe_user()
- 5.7 og.module \og_subscribe_user()
- 6 og.module \og_subscribe_user()
Create a new membership for a given user to given group.
Edits to membership should go through og_save_subscription(). No access control since this is an API function.
Parameters
$gid: Node ID of a group.
$account: User object.
$request: (Optional) Text explaining a user's reasoning to join a moderated group.
Return value
string 'approval', 'subscribed' or 'rejected' depending on the group configuration.
3 calls to og_subscribe_user()
- og_confirm_subscribe_submit in ./
og.pages.inc - Confirm og membership submit handler
- og_user in ./
og.module - Implementation of hook_user().
- og_xmlrpc_subscribe_user in includes/
og.xmlrpc.inc
File
- ./
og.module, line 1003 - Code for the Organic Groups module.
Code
function og_subscribe_user($gid, $account, $request = NULL) {
if ($account->uid == 0) {
// Silly admins can do this. Maybe code can too when an account gets deleted. See http://drupal.org/node/434632.
$return_value = array(
'type' => 'rejected',
'message' => t('Membership request to the %group group was rejected; the anonymous user may not join a group.', array(
'%group' => $node->title,
)),
);
}
else {
// Moderated groups must approve all members (selective=1).
$node = node_load($gid);
switch ($node->og_selective) {
case OG_MODERATED:
$admins = array();
og_save_subscription($gid, $account->uid, array(
'is_active' => 0,
));
$sql = og_list_users_sql(1, 1, NULL);
$res = db_query($sql, $node->nid);
$admins = array();
while ($row = db_fetch_object($res)) {
$admins[] = $row->uid;
}
if (!empty($admins)) {
$variables = array(
'@group' => $node->title,
'@username' => strip_tags(theme('username', $account)),
'!approve_url' => url("og/approve/{$node->nid}/{$account->uid}", array(
'absolute' => TRUE,
)),
'!group_url' => url("og/users/{$node->nid}", array(
'absolute' => TRUE,
)),
'@request' => $request,
);
$message = array(
'subject' => _og_mail_text('og_request_user_subject', $variables),
'body' => _og_mail_text('og_request_user_body', $variables),
);
// Send notifications to each admin; Sending an array of recipients
// implies that this is a bulk message.
module_invoke_all('og', 'user request', $gid, $admins, $message);
}
$return_value = array(
'type' => 'approval',
'message' => t('Membership request to the %group group awaits approval by an administrator.', array(
'%group' => $node->title,
)),
);
break;
case OG_OPEN:
og_save_subscription($gid, $account->uid, array(
'is_active' => 1,
));
$return_value = array(
'type' => 'subscribed',
'message' => t('You are now a member of %group.', array(
'%group' => $node->title,
)),
);
break;
case OG_CLOSED:
case OG_INVITE_ONLY:
// admins can add members to these groups, but others can't.
if (og_is_group_admin($node)) {
og_save_subscription($gid, $account->uid, array(
'is_active' => 1,
));
$return_value = array(
'type' => 'subscribed',
'message' => t('%user is now a member of %group.', array(
'%user' => theme('username', $account),
'%group' => $node->title,
)),
);
}
else {
$return_value = array(
'type' => 'rejected',
'message' => t('Membership request to the %group group was rejected, only group administrators can add users to this group.', array(
'%group' => $node->title,
)),
);
}
}
}
return $return_value;
}