You are here

function nodereference_count_get_fields_db in Nodereference Count 7

Get the db tables and columns for an array of field names.

Parameters

$field_names: An array of field names.

Return value

An indexed array of table and column names.

1 call to nodereference_count_get_fields_db()
nodereference_count_get_count in ./nodereference_count.module
Get the count of node references to a particular node.

File

./nodereference_count.module, line 162
Defines a field type for counting the references to a node.

Code

function nodereference_count_get_fields_db($field_names) {
  $db = array();
  if (!empty($field_names)) {
    foreach ($field_names as $field_name) {
      $field = field_info_field($field_name);

      // Make sure we are dealing with SQL storage.
      if ($field['storage']['type'] == 'field_sql_storage') {
        $db_info = $field['storage']['details']['sql']['FIELD_LOAD_CURRENT'];
        $tables = array_keys($db_info);
        $table = array_pop($tables);
        $db[] = array(
          'table' => $table,
          'column' => array_pop($db_info[$table]),
        );
      }
    }
  }
  return $db;
}