You are here

function og_notifications_add_form_submit in Organic groups 5.3

Same name and namespace in other branches
  1. 6.2 modules/og_notifications/og_notifications.pages.inc \og_notifications_add_form_submit()

Process og_notifications_add_form submission.

File

og_notifications/og_notifications.module, line 489
Provide notifications and messaging support for organic groups.

Code

function og_notifications_add_form_submit($form, $form_values) {
  $subscription = new stdClass();
  $subscription->type = 'grouptype';
  $subscription->uid = $form_values['account']->uid;
  $subscription->send_interval = $form_values['subscription']['send_interval'][0];
  $subscription->send_method = isset($form_values['send_method']) ? $form_values['send_method'] : $form_values['subscription']['send_method'][0];

  // String cast due to notifications requiring it as the value field is
  // a varchar.
  $subscription->fields = array(
    'group' => (string) $form_values['subscription']['group'][0],
    'type' => $form_values['subscription']['node_type'][0],
  );
  if ($form_values['subscription']['node_type'][0] == 'all') {
    $types = array_filter(variable_get('og_notifications_content_types', array()));
    foreach ($types as $type) {
      $subscription->fields['type'] = $type;
      notifications_save_subscription($subscription);
      unset($subscription->sid);
    }
  }
  else {
    notifications_save_subscription($subscription);
  }
  drupal_set_message(t('Subscription saved.'));
}