You are here

function course_object_autocomplete_node in Course 7

Same name and namespace in other branches
  1. 8.3 course.module \course_object_autocomplete_node()
  2. 8.2 course.module \course_object_autocomplete_node()
  3. 6 course.module \course_object_autocomplete_node()
  4. 7.2 course.module \course_object_autocomplete_node()

Helper function for autocompletion of node titles.

1 string reference to 'course_object_autocomplete_node'
course_menu in ./course.module
Implements hook_menu().

File

./course.module, line 2608
course.module Core functionality for Courses.

Code

function course_object_autocomplete_node($types, $string) {
  $matches = array();
  $values = explode(',', $types);
  $query = db_select('node', 'n');
  $query
    ->condition('n.type', $values, 'in')
    ->condition(db_or()
    ->condition('n.title', "%{$string}%", 'like')
    ->condition('n.nid', $string))
    ->fields('n', array(
    'nid',
    'title',
  ))
    ->range(0, 10);
  $result = $query
    ->execute();
  while ($node = $result
    ->fetch()) {
    $matches[$node->title . " [nid: {$node->nid}]"] = '<span class="autocomplete_title">' . check_plain($node->title) . '</span>';
  }
  drupal_json_output($matches);
}