finder_find_choices

Versions
6--1
finder_find_choices($finder, $finder_element_id, $options, $keywords, $match)

Postprocessing for returned finder_find options when mode is choices.

Code

./finder.module, line 1534

<?php
function finder_find_choices($finder, $finder_element_id, $options, $keywords, $match) {
  if ($options) {
    $element = &finder_element($finder, $finder_element_id);
    $fields = &$element->settings['choices']['field'];
    foreach ($fields as $key => $field) {
      $field_info[$key] = finder_split_field($field);
      $field_names[$key] = 'finder_element_'. $finder_element_id .'_'. $field_info[$key]['table'] .'_'. $field_info[$key]['field'];
    }
    $new_options = array();
    foreach ($options as $option) {
      if (count($fields) === 1) {
        $option->field_name = end($field_names);
        $new_options[] = $option;
      }
      elseif (count($fields) > 1) {
        $operator = str_replace('%%', '%', str_replace("'", "", finder_match_operator($match)));
        $matching_names = array();
        if (is_null($keywords)) {
          $matching_names = $field_names;
        }
        else {
          foreach ($field_names as $field_name) {
            $expression = str_replace('%s', $keywords, $operator);
            if (strpos($expression, 'LIKE') !== FALSE) {
              $expression = str_replace(' LIKE ', '', $expression);
              $like_matches = preg_grep(
                "/^". str_replace('%', '(.*?)', preg_quote($expression)) ."$/si",
                array($option->$field_name)
              );
              if (!empty($like_matches)) {
                $matching_names[] = $field_name;
              }
            }
            elseif (eval('return '. $option->$field_name . $expression .';')) {
              $matching_names[] = $field_name;
            }
          }
        }
        if (count($matching_names) === 1) {
          $option->field_name = end($matching_names);
          $new_options[] = $option;
        }
        elseif (!empty($matching_names)) {
          foreach ($matching_names as $matching_name) {
            $new_option = drupal_clone($option);
            $new_option->field_name = $matching_name;
            $new_options[] = $new_option;
          }
        }
      }
    }
    return $new_options;
  }
  return $options;
}
?>

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Mollom CAPTCHA (play audio CAPTCHA)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.