You are here

function subscriptions_taxa_form in Subscriptions 5

Returns the taxonomy subscription form

1 string reference to 'subscriptions_taxa_form'
subscriptions_taxa in ./subscriptions.module
Returns a list of taxonomy subscriptions

File

./subscriptions.module, line 1200

Code

function subscriptions_taxa_form($vocabularies, $account) {

  // query string for category subscriptions
  $subs = subscriptions_get_taxa($account->uid);
  $subsrows['subform'][] = array(
    '#value' => t('You are currently subscribed to the following:'),
  );
  foreach ($vocabularies as $vocab) {

    // display vocabulary name and group terms together
    $subsrows['subform'][$vocab->vid] = array(
      '#type' => 'fieldset',
      '#title' => $vocab->name,
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );

    // @ TODO create mechanism to allow users to
    //        subscribe to all terms under this vocabulary
    $tree = taxonomy_get_tree($vocab->vid);
    foreach ($tree as $term) {
      $defval = 0;
      foreach ($subs as $tid) {
        if ($tid == $term->tid) {
          $defval = 1;
          break;
        }
      }
      $orgstate[] = array(
        $term->tid,
        $account->uid,
        'taxa',
        $defval,
      );
      $title = l($term->name, 'taxonomy/term/' . $term->tid);
      $subsrows['subform'][$vocab->vid]['subs' . $term->tid] = array(
        '#type' => 'checkbox',
        '#title' => str_repeat('  ', $term->depth) . $title,
        '#default_value' => $defval,
      );
    }
  }
  if (empty($orgstate)) {
    $subsrows['subform'] = array(
      '#value' => t('There are no active categories.'),
    );
  }
  else {
    $subsrows['orgstate'] = array(
      '#type' => 'hidden',
      '#value' => serialize($orgstate),
    );
    $subsrows['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save'),
    );
  }
  return $subsrows;
}