You are here

function user_badges_badge_autocomplete in User Badges 7.3

Same name and namespace in other branches
  1. 6.2 user_badges.module \user_badges_badge_autocomplete()
  2. 6 user_badges.module \user_badges_badge_autocomplete()
  3. 7 user_badges.module \user_badges_badge_autocomplete()
  4. 7.2 user_badges.module \user_badges_badge_autocomplete()

Menu callback; Retrieve a JSON object containing autocomplete suggestions for badges

1 string reference to 'user_badges_badge_autocomplete'
user_badges_menu in ./user_badges.module
Implements hook_menu().

File

./user_badges.module, line 500
@brief User Badges module file

Code

function user_badges_badge_autocomplete($string = '') {
  $matches = array();
  if (preg_match('/^[^(]+/', $string, $searchstring)) {
    $trimstring = trim($searchstring[0]);
    $result = db_select('user_badges_badges', 'ubb')
      ->fields('ubb')
      ->condition('name', '%' . db_like($trimstring) . '%', 'LIKE')
      ->orderBy('weight')
      ->orderBy('name')
      ->extend('PagerDefault')
      ->limit(5)
      ->execute();
    foreach ($result as $badge) {
      $matches[$badge->name . ' (' . 'Badge ID' . ' ' . $badge->bid . ')'] = check_plain($badge->name) . ' ' . theme('user_badge', array(
        'badge' => $badge,
      ));
    }
  }
  drupal_json_output($matches);
}