You are here

function messaging_notify_user_form_submit in Messaging 6

Form submission

File

messaging_notify/messaging_notify.module, line 400
Subscriptions to messaging events

Code

function messaging_notify_user_form_submit($form, &$form_state) {
  $update = $delete = 0;
  $subscriptions = $form_state['values']['subscriptions'];
  foreach (array_keys($subscriptions['method']) as $key) {
    $subs = $form_state['values']['defaults'] + array(
      'sid' => $key == 'new' ? 0 : $key,
      'type' => 'messaging',
      'event_type' => 'message',
      'send_method' => $subscriptions['method'][$key],
      'send_interval' => $subscriptions['interval'][$key],
      'fields' => array(
        'method' => $form_state['values']['method'],
      ),
      'uid' => $form_state['values']['account']->uid,
      'module' => 'messaging',
    );
    $subs = (object) $subs;
    if ($subs->sid) {
      if ($subscriptions['check'][$key] && $subs->send_method) {
        $update++;
        notifications_save_subscription($subs);
      }
      else {
        $delete++;
        notifications_delete_subscription($subs->sid);
      }
    }
    elseif ($subscriptions['check'][$key] && $subs->send_method) {
      drupal_set_message(t('A new subscription has been created.'));
      notifications_save_subscription($subs);
    }
  }
  if ($update) {
    drupal_set_message(format_plural($update, 'A subscription has been updated.', '%count subscriptions have been updated.'));
  }
  if ($delete) {
    drupal_set_message(format_plural($delete, 'A subscription has been deleted.', '%count subscriptions have been deleted.'));
  }
}