You are here

function i18nviews_handler_filter_term_node_tid::validate_term_strings in Internationalization Views 6.3

Same name and namespace in other branches
  1. 6.2 includes/i18nviews_handler_filter_term_node_tid.inc \i18nviews_handler_filter_term_node_tid::validate_term_strings()

Validate the user string. Since this can come from either the form or the exposed filter, this is abstracted out a bit so it can handle the multiple input sources.

File

includes/i18nviews_handler_filter_term_node_tid.inc, line 120

Class

i18nviews_handler_filter_term_node_tid
Filter by term id.

Code

function validate_term_strings(&$form, $values) {
  if (empty($values)) {
    return array();
  }
  $tids = array();
  $placeholders = array();
  $args = array();
  $results = array();
  foreach ($values as $value) {
    $missing[strtolower($value)] = TRUE;
    $args[] = $value;
    $placeholders[] = "'%s'";
  }
  if (!$args) {
    return;
  }

  // add the taxonomy vid to the argument list.
  $args[] = $this->options['vid'];
  $result = db_query("SELECT * FROM {term_data} WHERE name IN (" . implode(', ', $placeholders) . ") AND vid = %d", $args);
  while ($term = db_fetch_object($result)) {
    unset($missing[strtolower(tt('taxonomy:term:' . $term->tid . ':name', $term->name))]);
    $tids[] = $term->tid;
  }
  if ($missing) {
    form_error($form, format_plural(count($missing), 'Unable to find term: @terms', 'Unable to find terms: @terms', array(
      '@terms' => implode(', ', array_keys($missing)),
    )));
  }
  return $tids;
}