You are here

function _pm_attribute_domain_autocomplete in Drupal PM (Project Management) 7

Javascript callback for attribute domain autocomplete field.

1 string reference to '_pm_attribute_domain_autocomplete'
pm_menu in ./pm.module
Implements hook_menu().

File

./pm.admin.inc, line 616
List functions for the Project Management module.

Code

function _pm_attribute_domain_autocomplete($string = '') {
  static $default_domains;
  if (!$default_domains) {
    $default_domains = array(
      'Country' => 'Country',
      'Currency' => 'Currency',
      'Task status' => 'Task status',
      'Project category' => 'Project category',
      'Project status search' => 'Project status search',
      'Project status' => 'Project status',
      'Ticket priority search' => 'Ticket priority search',
      'Ticket priority' => 'Ticket priority',
      'Ticket category' => 'Ticket category',
      'Ticket status search' => 'Ticket status search',
      'Ticket status' => 'Ticket status',
      'Task status search' => 'Task status search',
      'Price mode' => 'Price mode',
      'Project priority' => 'Project priority',
      'Project priority search' => 'Project priority search',
      'Task category' => 'Task category',
      'Task priority' => 'Task priority',
      'Task priority search' => 'Task priority search',
      'Duration unit' => 'Duration unit',
    );
  }
  $matches = array();
  if ($string) {
    $query = db_select('pmattribute', 'att')
      ->fields('att', array(
      'domain',
    ))
      ->distinct()
      ->where('LOWER(domain) LIKE LOWER(:search)', array(
      ':search' => '%' . $string . '%',
    ));
    $result = $query
      ->execute();
    foreach ($result as $a) {
      $matches[$a->domain] = check_plain($a->domain);
    }
  }
  foreach ($default_domains as $domain) {
    if (strpos(drupal_strtoupper($domain), drupal_strtoupper($string)) === FALSE) {
    }
    else {
      $matches[$domain] = $domain;
    }
  }
  $matches = array_slice($matches, 0, 10);
  drupal_json_output($matches);
}