You are here

function og_notifications_manage_form_submit in Organic groups 6.2

Same name and namespace in other branches
  1. 5.3 og_notifications/og_notifications.module \og_notifications_manage_form_submit()

Process og_notifications_manage_form form submission.

File

modules/og_notifications/og_notifications.pages.inc, line 227
Group subscriptions management methods.

Code

function og_notifications_manage_form_submit($form, &$form_state) {
  $form_values = $form_state['values'];
  $current = $form_values['subscriptions']['current'];
  foreach ($form_values['subscriptions']['checkbox'] as $sid => $check) {
    $subscription = $current[$sid];

    // Insert fields array as per notifications' requirements.
    $subscription->fields = array(
      'group' => (string) $subscription->group_nid,
      'type' => $subscription->node_type,
    );
    if ($check == 1) {
      if ($subscription->send_interval != $form_values['subscriptions']['send_interval'][$sid] || !isset($form_values['send_method']) && $subscription->send_method != $form_values['subscriptions']['send_method'][$sid]) {
        $subscription->send_interval = $form_values['subscriptions']['send_interval'][$sid];
        $subscription->send_method = isset($form_values['send_method']) ? $form_values['send_method'] : $form_values['subscriptions']['send_method'][$sid];

        // String cast due to notifications requiring it as the value field is
        // a varchar.
        notifications_save_subscription($subscription);
      }
    }
    else {

      // Unsubscribe if not checked ...
      notifications_delete_subscription($sid);
    }
  }
  drupal_set_message(t('Subscriptions updated.'));
}