You are here

function biblio_form_filter in Bibliography Module 6.2

Same name and namespace in other branches
  1. 5 biblio.module \biblio_form_filter()
  2. 6 biblio.pages.inc \biblio_form_filter()
  3. 7 includes/biblio.pages.inc \biblio_form_filter()
  4. 7.2 includes/biblio.pages.inc \biblio_form_filter()

Form constructor for a biblio content filter.

Return value

array $form An assoicative array with form elements for the biblio content filter.

See also

biblio_form_filter_submit()

1 string reference to 'biblio_form_filter'
biblio_menu in ./biblio.module
Implements hook_menu().

File

includes/biblio.pages.inc, line 1079
Functions in the biblio module related to filtering and page generation.

Code

function biblio_form_filter() {

  // No longer use &$_SESSION so that we can alter $session in case of the search filter.
  $session = $_SESSION['biblio_filter'];
  $session = is_array($session) ? $session : array();
  $filters = _get_biblio_filters();
  $i = 0;
  $form['filters'] = array(
    '#type' => 'fieldset',
    '#title' => t('Show only items where'),
    '#theme' => 'biblio_filters',
  );
  foreach ($session as $filter) {
    list($type, $value) = $filter;

    // Don't show the search filter. Reset $session because of the $count(session) below.
    if ($type == 'search') {
      $session = array();
      break;
    }
    if ($type == 'category') {

      // Load term name from DB rather than search and parse options array.
      $value = module_invoke('taxonomy', 'get_term', $value);
      $value = $value->name;
    }
    else {
      $value = $filters[$type]['options'][$value];
    }
    $string = $i++ ? '<em>and</em> where <strong>%a</strong> is <strong>%b</strong>' : '<strong>%a</strong> is <strong>%b</strong>';
    $form['filters']['current'][] = array(
      '#value' => t($string, array(
        '%a' => $filters[$type]['title'],
        '%b' => $value,
      )),
    );
  }
  foreach ($filters as $key => $filter) {
    if (isset($filter) && count($filter['options'])) {
      $names[$key] = check_plain($filter['title']);
      $form['filters']['status'][$key] = array(
        '#type' => 'select',
        '#options' => $filter['options'],
      );
    }
  }
  $form['filters']['filter'] = array(
    '#type' => 'radios',
    '#options' => $names,
    '#default_value' => 'author',
  );
  $form['filters']['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => count($session) ? t('Refine') : t('Filter'),
  );
  if (count($session) && $type != 'search') {
    $form['filters']['buttons']['undo'] = array(
      '#type' => 'submit',
      '#value' => t('Undo'),
    );
    $form['filters']['buttons']['reset'] = array(
      '#type' => 'submit',
      '#value' => t('Reset'),
    );
  }
  return $form;
}