You are here

function suggestion_admin_search_form in Autocomplete Search Suggestions 7

Menu callback to index suggestions.

1 string reference to 'suggestion_admin_search_form'
suggestion_menu in ./suggestion.module
Implements hook_menu().

File

./suggestion.admin.inc, line 134
Administration form for suggestion module.

Code

function suggestion_admin_search_form($form, &$state, $ngram = '') {
  $ngram = trim($ngram);
  $opts = array(
    'query' => drupal_get_destination(),
  );
  $rows = array();
  $rpp = variable_get('suggestion_rpp', 100);
  $header = array(
    t('N-Gram'),
    t('Source'),
    t('Atoms'),
    t('Quantity'),
    t('Density'),
    t('Edit'),
  );
  if ($ngram) {
    $pattern = '%' . db_like($ngram) . '%';
    $page = pager_default_initialize(SuggestionStorage::getCount($pattern), $rpp);
    $suggestions = SuggestionStorage::search($pattern, $page * $rpp, $rpp);
  }
  else {
    $page = pager_default_initialize(SuggestionStorage::getCount(), $rpp);
    $suggestions = SuggestionStorage::getAllSuggestions($page * $rpp, $rpp);
  }
  foreach ($suggestions as $obj) {
    $rows[$obj->ngram] = array(
      $obj->ngram,
      $obj->src,
      $obj->atoms,
      $obj->qty,
      $obj->density,
      l(t('Edit'), "admin/config/suggestion/edit/{$obj->ngram}", $opts),
    );
  }
  $form['ngram'] = array(
    '#type' => 'textfield',
    '#autocomplete_path' => 'suggestion/autocomplete',
    '#default_value' => $ngram,
    '#weight' => 10,
  );
  $form['search'] = array(
    '#type' => 'submit',
    '#name' => 'search',
    '#value' => t('Search'),
    '#submit' => array(
      'suggestion_admin_search_form_submit',
    ),
    '#validate' => array(),
    '#weight' => 20,
  );
  $form['list'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $rows,
    '#empty' => t('Nothing found.'),
    '#weight' => 60,
  );
  if (count($rows)) {
    $form['src'] = array(
      '#title' => t('Source'),
      '#type' => 'select',
      '#options' => SuggestionStorage::getSrcOptions(),
      '#multiple' => TRUE,
      '#weight' => 30,
    );
    $form['update'] = array(
      '#type' => 'submit',
      '#name' => 'update',
      '#value' => t('Update'),
      '#submit' => array(
        'suggestion_admin_search_form_update_submit',
        'suggestion_admin_search_form_submit',
      ),
      '#validate' => array(
        'suggestion_admin_search_form_validate',
      ),
      '#weight' => 40,
    );
    $form['pager'] = array(
      '#theme' => 'pager',
      '#weight' => 70,
    );
  }
  return $form;
}