function chado_add_node_form_relationships_name_to_id_callback

2.x tripal_core.chado_nodes.relationships.api.inc chado_add_node_form_relationships_name_to_id_callback($base_table, $name_field, $string)
3.x tripal_core.chado_nodes.relationships.api.inc chado_add_node_form_relationships_name_to_id_callback($base_table, $name_field, $string)

Handles autocomplete for subject & object id

Parameters

$string: The part of the string already typed in the textfield

Related topics

1 string reference to 'chado_add_node_form_relationships_name_to_id_callback'
tripal_core_menu in tripal_core/tripal_core.module
Implements hook_menu(). Defines all menu items needed by Tripal Core

File

tripal_core/api/tripal_core.chado_nodes.relationships.api.inc, line 1044
API to manage the chado _relationship table for various Tripal Node Types

Code

function chado_add_node_form_relationships_name_to_id_callback($base_table, $name_field, $string) {
  $matches = array();

  $base_key = $base_table . '_id';

  // determine the chado schema.
  $chado = tripal_get_schema_name('chado');

  $query = db_select($chado . '.' . $base_table, 'b')
    ->fields('b', array($base_key, $name_field))
    ->condition($name_field, '%' . db_like($string) . '%', 'LIKE');

  $result = $query->execute();

  // save the query to matches
  foreach ($result as $row) {
    if (strlen($row->{$name_field}) > 50) {
      $key = '(' . $row->{$base_key} . ') ' . substr($row->{$name_field}, 0, 50) . '...';
    }
    else {
      $key = '(' . $row->{$base_key} . ') ' . $row->{$name_field};
    }
    $matches[$key] = check_plain($row->{$name_field});
  }

  // return for JS
  drupal_json_output($matches);
}