You are here

function recipe_autocomplete_page in Recipe 7.2

Same name and namespace in other branches
  1. 5 recipe.module \recipe_autocomplete_page()
  2. 6 recipe.module \recipe_autocomplete_page()
  3. 7 recipe.module \recipe_autocomplete_page()

Page callback: Outputs JSON for ingredient autocomplete suggestions.

1 string reference to 'recipe_autocomplete_page'
recipe_menu in ./recipe.module
Implements hook_menu().

File

./recipe.admin.inc, line 448
Contains admin page callbacks, form validation, and form submission handlers.

Code

function recipe_autocomplete_page($string = "", $limit = 10) {
  $matches = array();
  $query = db_select('recipe_ingredient', 'ri')
    ->fields('ri', array(
    'name',
  ))
    ->where('LOWER(name) LIKE :name', array(
    ':name' => strtolower($string) . '%',
  ))
    ->orderBy('name', 'ASC')
    ->range(0, $limit);
  $result = $query
    ->execute();
  foreach ($result as $record) {
    $matches[$record->name] = check_plain($record->name);
  }
  drupal_json_output($matches);
  exit;
}