You are here

function messaging_notify_user_form in Messaging 6

Form to set up multiple notifications for a sending method

Parameters

$account: User account

$method: Messaging method to subscribe to

$defaults: Override defaults for the subscription

$max: Maximum number of subscriptions allowed

File

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

Code

function messaging_notify_user_form(&$form_state, $account, $method, $defaults = array(), $max = 0) {
  $form['account'] = array(
    '#type' => 'value',
    '#value' => $account,
  );
  $form['method'] = array(
    '#type' => 'value',
    '#value' => $method,
  );
  $form['defaults'] = array(
    '#type' => 'value',
    '#value' => $defaults,
  );
  $names = array(
    '%method-name' => messaging_method_info($method, 'name'),
  );
  $form['subscriptions'] = array(
    '#type' => 'fieldset',
    '#title' => t('Notifications for %method-name', $names),
    '#description' => t('How you want to get notifications for %method-name. Uncheck the ones you want to be deleted.', $names),
    '#theme' => 'messaging_subscriptions_table',
    '#tree' => TRUE,
  );

  // Get subscriptions for this method
  $subscriptions = notifications_get_subscriptions(array(
    'uid' => $account->uid,
    'type' => 'messaging',
  ), array(
    'method' => $method,
  ));

  // Add template for new one
  if (!$max || count($subscriptions) < $max) {
    $subscriptions['new'] = (object) array(
      'method' => '',
      'interval' => 0,
    );
  }
  $method_list = array(
    '' => '',
  ) + messaging_method_list($account);
  unset($method_list[$method]);
  foreach ($subscriptions as $sid => $subs) {
    $form['subscriptions']['check'][$sid] = array(
      '#type' => 'checkbox',
      '#default_value' => TRUE,
    );
    $form['subscriptions']['method'][$sid] = array(
      '#type' => 'select',
      '#options' => $method_list,
      '#default_value' => $subs->send_method,
    );
    $form['subscriptions']['interval'][$sid] = array(
      '#type' => 'select',
      '#options' => _notifications_send_intervals(),
      '#default_value' => $subs->send_interval,
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
  );
  return $form;
}