You are here

function og_notifications_manage_form in Organic groups 6.2

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

Grouptype subscription management form.

Parameters

Object $account: User object of the user whose page is to be displayed.

Return value

Array $form Form array.

File

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

Code

function og_notifications_manage_form($form_state, $account) {
  $content_types = array_filter(variable_get('og_notifications_content_types', array()));
  $content_names = node_get_types('names');
  $send_methods = _notifications_send_methods();
  $send_intervals = _notifications_send_intervals();
  $header = array(
    theme('table_select_header_cell'),
    array(
      'data' => t('Group'),
      'field' => 'n.title',
      'sort' => 'asc',
    ),
    array(
      'data' => t('Type'),
      'field' => 'node_type',
    ),
    array(
      'data' => t('Send method'),
      'field' => 'no.send_method',
    ),
    array(
      'data' => t('Send Interval'),
      'field' => 'no.send_interval',
    ),
  );
  $sql = "SELECT n.nid AS group_nid, n.title, nof2.value AS node_type, no.* FROM {notifications} no\n    INNER JOIN {notifications_fields} nof1 ON no.sid = nof1.sid\n    INNER JOIN {notifications_fields} nof2 ON no.sid = nof2.sid\n    INNER JOIN {node} n ON nof1.value = n.nid\n    WHERE no.uid = %d AND (no.type = 'grouptype') AND no.conditions = 2 AND nof1.field = 'group' AND nof2.field = 'type' AND n.status = 1";
  $sql .= tablesort_sql($header);
  $count_sql = "SELECT COUNT(nof2.value) FROM {notifications} no\n    INNER JOIN {notifications_fields} nof1 ON no.sid = nof1.sid\n    INNER JOIN {notifications_fields} nof2 ON no.sid = nof2.sid\n    INNER JOIN {node} n ON nof1.value = n.nid\n    WHERE no.uid = %d AND (no.type = 'grouptype') AND no.conditions = 2 AND nof1.field = 'group' AND nof2.field = 'type' AND n.status = 1";
  $result = pager_query($sql, 50, 0, $count_sql, $account->uid);

  // Reuse notifications theme function for the embedded table.
  $form['subscriptions'] = array(
    '#type' => 'fieldset',
    '#title' => t('Current subscriptions'),
    '#tree' => TRUE,
    '#collapsible' => TRUE,
    '#theme' => 'notifications_form_table',
    '#header' => &$header,
  );
  $subscriptions_current = array();
  while ($subscription = db_fetch_object($result)) {
    $key = $subscription->sid;
    $subscriptions_current[$key] = $subscription;
    $form['subscriptions']['checkbox'][$key] = array(
      '#type' => 'checkbox',
      '#default_value' => $subscription->sid,
    );
    $form['subscriptions']['group'][$key] = array(
      '#value' => l($subscription->title, 'node/' . $subscription->group_nid),
    );
    $form['subscriptions']['node_type'][$key] = array(
      '#value' => $content_names[$subscription->node_type],
    );

    // Hide send methods if only one available.
    if (count($send_methods) > 1) {
      $form['subscriptions']['send_method'][$key] = array(
        '#type' => 'select',
        '#options' => $send_methods,
        '#default_value' => $subscription->send_method,
      );
    }
    else {

      // Unset send method column if only one is available.
      unset($header[3]);

      // Pass default outside the subscriptions fieldset to avoid theming issues.
      $form['send_method'] = array(
        '#type' => 'value',
        '#value' => $subscription->send_method,
      );
    }
    $form['subscriptions']['send_interval'][$key] = array(
      '#type' => 'select',
      '#options' => $send_intervals,
      '#default_value' => $subscription->send_interval,
    );
  }
  if (empty($subscriptions_current)) {
    $form = array();
  }
  else {
    $form['subscriptions']['current'] = array(
      '#type' => 'value',
      '#value' => $subscriptions_current,
    );
    $form['subscriptions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Update'),
    );
  }
  return $form;
}