You are here

function _civicrm_entity_db_select in CiviCRM Entity 7.2

Utility function to do db_select for FK reference autocomplete widgets

Parameters

$entity_type:

$string:

$condition_column:

Return value

array

1 call to _civicrm_entity_db_select()
civicrm_entity_autocomplete in ./civicrm_entity.module
Menu callback for autocomplete search function

File

./civicrm_entity.module, line 104

Code

function _civicrm_entity_db_select($entity_type, $string, $condition_column) {
  $matches = array();
  $result = db_select('civicrm_' . strtolower($entity_type))
    ->fields('civicrm_' . strtolower($entity_type), array(
    'id',
    $condition_column,
  ))
    ->condition($condition_column, db_like($string) . '%', 'LIKE')
    ->range(0, 10)
    ->execute();
  foreach ($result as $record) {
    $matches[$record->id] = check_plain($record->{$condition_column});
  }
  return $matches;
}