You are here

function notifications_tags_user_form in Notifications 5

Same name and namespace in other branches
  1. 6 notifications_tags/notifications_tags.module \notifications_tags_user_form()
  2. 6.2 notifications_tags/notifications_tags.module \notifications_tags_user_form()
  3. 6.3 notifications_tags/notifications_tags.module \notifications_tags_user_form()

Returns the taxonomy subscription form

1 string reference to 'notifications_tags_user_form'
notifications_tags_user_page in notifications_tags/notifications_tags.module
Returns a list of taxonomy subscriptions

File

notifications_tags/notifications_tags.module, line 124
Subscriptions to taxonomy terms

Code

function notifications_tags_user_form($account) {

  // query string for category subscriptions
  $vocabularies = notifications_tags_vocabularies();
  $subscriptions = notifications_get_subscriptions(array(
    'type' => 'taxonomy',
    'uid' => $account->uid,
  ), array(
    'tid' => NULL,
  ), TRUE, 'value');

  // Complete defaults
  $defaults = array(
    'sid' => 0,
    'send_interval' => notifications_user_setting('send_interval', $account),
    'send_method' => notifications_user_setting('send_method', $account),
    'type' => 'taxonomy',
    'event_type' => 'node',
  );
  $form['defaults'] = array(
    '#type' => 'value',
    '#value' => $defaults,
  );
  $form['account'] = array(
    '#type' => 'value',
    '#value' => $account,
  );
  $form['current'] = array(
    '#type' => 'value',
    '#value' => $subscriptions,
  );
  $form['subscription_fields'] = array(
    '#type' => 'value',
    '#value' => array(),
  );

  //$subsrows['subform'][] = array('#value' => t('Current subscriptions:'));
  $form['subscriptions'] = array(
    '#tree' => TRUE,
  );
  foreach ($vocabularies as $vid => $vocab) {

    // display vocabulary name and group terms together
    $form['subscriptions'][$vid] = array(
      '#type' => 'fieldset',
      '#title' => $vocab->name,
      '#tree' => TRUE,
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#theme' => 'notifications_form_table',
      '#header' => array(
        theme('table_select_header_cell'),
        t('Term'),
        t('Send interval'),
        t('Send method'),
      ),
      '#parents' => array(
        'subscriptions',
      ),
    );

    // @ TODO create mechanism to allow users to
    //        subscribe to all terms under this vocabulary
    $tree = taxonomy_get_tree($vocab->vid);
    $field = 'tid';
    foreach ($tree as $term) {
      $key = $term->tid;
      $rowdefaults = isset($subscriptions[$key]) ? (array) $subscriptions[$key] : array();
      $rowdefaults += $defaults;
      $form['subscriptions'][$vid]['checkbox'][$key] = array(
        '#type' => 'checkbox',
        '#default_value' => $rowdefaults['sid'],
      );
      $form['subscriptions'][$vid]['title'][$key] = array(
        '#value' => $term->name,
      );
      $form['subscriptions'][$vid]['send_interval'][$key] = array(
        '#type' => 'select',
        '#options' => _notifications_send_intervals(),
        '#default_value' => $rowdefaults['send_interval'],
      );
      $form['subscriptions'][$vid]['send_method'][$key] = array(
        '#type' => 'select',
        '#options' => _notifications_send_methods(),
        '#default_value' => $rowdefaults['send_method'],
      );

      // Pass on the fields for processing
      $form['subscription_fields']['#value'][$key] = array(
        $field => $key,
      );
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  $form['#submit']['notifications_content_form_submit'] = array();
  return $form;
}