You are here

function flexiaccess_node_autocomplete in Flexi Access 7

Menu callback.

Retrieve a JSON object containing autocomplete suggestions for existing nodes.

1 string reference to 'flexiaccess_node_autocomplete'
flexiaccess_menu in ./flexiaccess.module
Implements hook_menu().

File

./flexiaccess.users.inc, line 153
Form handling for per user ACL.

Code

function flexiaccess_node_autocomplete($string = '') {

  // TODO: What if range(0,50) does not show the required nodes?
  // TODO: maybe break up search string in words and add separate OR'd
  // conditions with foreach?
  $matches = array();
  if ($string) {

    // Get active content types that have Flexi access managing their ACL.
    $types = array_filter(variable_get('flexiaccess_types', array()));
    if (!empty($types)) {
      $result = db_select('node')
        ->fields('node', array(
        'title',
        'nid',
      ))
        ->condition('type', $types, 'IN')
        ->condition('title', '%' . db_like($string) . '%', 'LIKE')
        ->range(0, 50)
        ->execute();
      foreach ($result as $node) {
        $matches[$node->nid] = check_plain("{$node->nid} : {$node->title}");
      }
    }
  }
  drupal_json_output($matches);
}