function og_notifications_user_subscribe in Organic groups 6.2
Same name and namespace in other branches
- 5.8 og_notifications/og_notifications.module \og_notifications_user_subscribe()
- 5 og_notifications/og_notifications.module \og_notifications_user_subscribe()
- 5.3 og_notifications/og_notifications.module \og_notifications_user_subscribe()
- 5.7 og_notifications/og_notifications.module \og_notifications_user_subscribe()
- 6 modules/og_notifications/og_notifications.module \og_notifications_user_subscribe()
Subscribe a user to a group or to be more precise, to all subscribe-able content types within the group. This method is also called during the upgrade process in .install.
Parameters
Object $account: The user account object.
Integer $gid: The node ID of the group being subscribed to.
2 calls to og_notifications_user_subscribe()
- og_notifications_og_upgrade in modules/
og_notifications/ og_notifications.install - Notifications upgrade: Based on the upgrade flag, move existing subscriptions to the notifications module.
- og_notifications_user_autosubscribe in modules/
og_notifications/ og_notifications.module - Handle autosubscriptions for users when they join a group.
File
- modules/
og_notifications/ og_notifications.module, line 464 - Provide notifications and messaging support for organic groups.
Code
function og_notifications_user_subscribe($account, $gid) {
// Remove all existing user->group subscriptions.
og_notifications_user_unsubscribe($account, $gid);
$subscription_default = _notifications_subscription_defaults($account);
$subscription_default['uid'] = $account->uid;
$subscription_default['type'] = 'grouptype';
$subscription_default['event_type'] = 'node';
// Only subscribe the user to enabled types.
$content_types = array_filter(variable_get('og_notifications_content_types', array()));
// If the types array is empty, subscribe to all group types. This is mainly
// only valid during the upgrade.
if (empty($content_types)) {
$content_types = og_get_types('group_post');
}
foreach ($content_types as $type) {
// Reset $subscription as notifications_save_subscription casts the input
// array into an object.
$subscription = $subscription_default;
// String cast due to notifications requiring it (as the value field is
// a varchar).
$subscription['fields'] = array(
'group' => (string) $gid,
'type' => $type,
);
notifications_save_subscription($subscription);
}
}