function _bbcom_subscribe_to_thread($uid, $nid)
{
    $account = user_load($uid);
    $subscription = array('type' => 'thread', 'uid' => $uid, 'fields' => array('nid' => $nid), 'send_method' => notifications_user_setting('send_method', $account), 'send_interval' => notifications_user_setting('send_interval', $account), 'event_type' => 'node');
    $subscription = notifications_build_subscription($subscription);
    $ret = notifications_save_subscription($subscription);
}
Esempio n. 2
0
/**
 * Process submission
 */
function notifications_object_options_form_submit($form, $form_state)
{
    $enabled = $disabled = 0;
    // We may have also send method and destination in this form, like on forms from anonymous users
    $send_method = isset($form_state['values']['send_method']) ? $form_state['values']['send_method'] : NULL;
    $destination = isset($form_state['values']['destination']) ? $form_state['values']['destination'] : NULL;
    foreach ($form_state['values']['subscriptions']['options'] as $index => $value) {
        $subscription = $form_state['values']['subscriptions']['params'][$index];
        if ($value && !$subscription->is_instance()) {
            // We checked a disabled subscription
            if ($send_method) {
                $subscription->send_method = $send_method;
            }
            if ($destination) {
                $subscription->set_destination($destination);
            }
            notifications_save_subscription($subscription);
            $enabled++;
        } elseif (!$value && $subscription->is_instance()) {
            // we unchecked an enabled subscription
            Notifications_Subscription::delete_subscription($subscription->sid);
            $disabled++;
        }
    }
    if ($enabled) {
        drupal_set_message(format_plural($enabled, 'A subscription has been created', '@count subscriptions have been created'));
    }
    if ($disabled) {
        drupal_set_message(format_plural($disabled, 'A subscription has been deleted', '@count subscriptions have been deleted'));
    }
}