function og_save_subscription in Organic groups 5
Same name and namespace in other branches
- 5.8 og.module \og_save_subscription()
- 5.2 og.module \og_save_subscription()
- 5.3 og.module \og_save_subscription()
- 5.7 og.module \og_save_subscription()
- 6.2 og.module \og_save_subscription()
- 6 og.module \og_save_subscription()
Low level function for managing membership
Parameters
$gid node ID of a group:
$uid user ID of user:
$args an array with details of this membership. Possible array keys are:: is_active, is_admin, mail_type, created
8 calls to og_save_subscription()
- og_add_users_submit in ./
og.module - og_approve in ./
og.module - og_create_admin_confirm_submit in ./
og.module - Confirm og create admin form
- og_manage_form_submit in ./
og.module - og_nodeapi in ./
og.module - Implementation of hook_nodeapi().
File
- ./
og.module, line 418
Code
function og_save_subscription($gid, $uid, $args = array()) {
$sql = "SELECT COUNT(*) FROM {og_uid} WHERE nid = %d AND uid = %d";
$cnt = db_result(db_query($sql, $gid, $uid));
$time = time();
// Allow other modules to pass their data inside the $args.
$og_allowed_args = array(
'is_active',
'is_admin',
'mail_type',
'created',
);
$return_args = $args;
foreach ($args as $key => $value) {
if (!in_array($key, $og_allowed_args)) {
unset($args[$key]);
}
}
if ($cnt == 0) {
// this pattern borrowed from user_save()
$fields = array(
'nid',
'uid',
'created',
'changed',
);
$values = array(
$gid,
$uid,
$args['created'] ? $args['created'] : $time,
$time,
);
unset($args['created']);
foreach ($args as $key => $value) {
$fields[] = db_escape_string($key);
$values[] = $value;
$s[] = "'%s'";
}
db_query('INSERT INTO {og_uid} (' . implode(', ', $fields) . ') VALUES (%d, %d, %d, %d, ' . implode(', ', $s) . ')', $values);
module_invoke_all('og', 'user insert', $gid, $uid, $return_args);
}
else {
$cond[] = 'changed = ' . $time;
foreach ($args as $key => $value) {
$cond[] = db_escape_string($key) . " = '" . db_escape_string($value) . "'";
}
$cond = implode(', ', $cond);
db_query("UPDATE {og_uid} SET {$cond} WHERE nid = %d AND uid = %d", $gid, $uid);
module_invoke_all('og', 'user update', $gid, $uid, $return_args);
}
}