You are here

function notifications_autosubscribe in Notifications 6

Same name and namespace in other branches
  1. 5 notifications_autosubscribe/notifications_autosubscribe.module \notifications_autosubscribe()
  2. 6.4 notifications_autosubscribe/notifications_autosubscribe.module \notifications_autosubscribe()
  3. 6.2 notifications_autosubscribe/notifications_autosubscribe.module \notifications_autosubscribe()
  4. 6.3 notifications_autosubscribe/notifications_autosubscribe.module \notifications_autosubscribe()

Subscribes users to content they post, if not already subscribed

Parameters

$type: Subscription type

$event type: Event type

$field: String, field that subscription depends on. ie 'nid'.

$value: Int, value of $field that triggers subscription.

1 call to notifications_autosubscribe()
notifications_autosubscribe_notifications in notifications_autosubscribe/notifications_autosubscribe.module
Implementation of hook_notifications.

File

notifications_autosubscribe/notifications_autosubscribe.module, line 20

Code

function notifications_autosubscribe($type, $event_type, $field, $value) {
  global $user;

  // if user has auto subscribe enabled and he's not already subscribed
  if (notifications_user_setting('auto', $user) && !notifications_user_get_subscriptions($user->uid, $event_type, $field, $value)) {
    $subscription = array(
      'uid' => $user->uid,
      'type' => $type,
      'event_type' => $event_type,
      'fields' => array(
        $field => $value,
      ),
    );
    notifications_save_subscription($subscription);
  }
}