function og_subscribe_user in Organic groups 5
Same name and namespace in other branches
- 5.8 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.2 og.module \og_subscribe_user()
- 6 og.module \og_subscribe_user()
Create a new membership for a given user to given group and send proper email. Edits to membership should go through og_save_subscription(). No access control since this is an API function.
Return value
string 'approval', 'subscribed' or 'rejected' depending on the group's configuration.
3 calls to og_subscribe_user()
- og_confirm_subscribe_submit in ./
og.module - Confirm og membership submit handler
- og_user in ./
og.module - og_xmlrpc_subscribe_user in ./
og_xmlrpc.inc
File
- ./
og.module, line 752
Code
function og_subscribe_user($gid, $account, $request = NULL) {
// moderated groups must approve all members (selective=1)
$node = node_load($gid);
switch ($node->og_selective) {
case OG_MODERATED:
og_save_subscription($gid, $account->uid, array(
'is_active' => 0,
));
$sql = og_list_users_sql(1, 1);
$res = db_query($sql, $node->nid);
while ($row = db_fetch_object($res)) {
if ($row->mail) {
$admins[] = $row->mail;
}
}
if ($admins) {
$variables = array(
'@group' => $node->title,
'@username' => $account->name,
'!approve_url' => url("og/approve/{$node->nid}/{$account->uid}", NULL, NULL, TRUE),
'!group_url' => url("og/users/{$node->nid}", NULL, NULL, TRUE),
);
$from = variable_get('site_mail', ini_get('sendmail_from'));
// prepend user's request text with standard cruft. should be a mail variable but thats a bit annoying
if ($request) {
$request = t("\n\nPersonal message from @name:\n------------------\n\n@request", array(
'@name' => $account->name,
'@request' => $request,
));
}
drupal_mail('og_subscription_request', implode(', ', $admins), _og_user_mail_text('og_request_user_subject', $variables), _og_user_mail_text('og_request_user_body', $variables) . $request, $from);
}
$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 the %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_node_admin($node)) {
og_save_subscription($gid, $account->uid, array(
'is_active' => 1,
));
}
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;
}