You are here

function civicrm_entity_get_schema in CiviCRM Entity 7

Same name and namespace in other branches
  1. 7.2 civicrm_entity.module \civicrm_entity_get_schema()

Get schema for entities.

This approach may not be required as using the schema_alter hook (as opposed to schema_hook) seems to get around a bunch of the reasons I used a separate schema.

Parameters

$table:

Return value

array

3 calls to civicrm_entity_get_schema()
CiviCRMEntityDefaultViewsController::schema_fields in ./civicrm_entity_default_views_controller.inc
Find views fields using schema & entity property information.
civicrm_entity_metadata_convert_schema in ./civicrm_entity_metadata_controller.inc
Converts schema info for table to property info.
civicrm_entity_schema_alter in ./civicrm_entity.module
Implements hook_schema_alter().

File

./civicrm_entity.module, line 102
Implement CiviCRM entities as a Drupal Entity.

Code

function civicrm_entity_get_schema($table) {
  if (!civicrm_initialize(TRUE)) {
    return;
  }
  $schema = array();
  $schema[$table] = array(
    'description' => 'The base table for ' . $table,
    'primary key' => array(
      'id',
    ),
    'fields' => array(),
  );
  $civicrm_entity = substr($table, 8);
  $fields = civicrm_api($civicrm_entity, 'getfields', array(
    'version' => 3,
  ));
  $fields = $fields['values'];
  foreach ($fields as $fieldname => $field_spec) {
    if (empty($field_spec['name'])) {
      continue;
    }
    $unique_name = empty($field_spec['uniqueName']) ? $fieldname : $field_spec['uniqueName'];
    $schema[$table]['fields'][$unique_name] = array(
      'real_field' => $field_spec['name'],
      'description' => _civicrm_entity_get_title($field_spec),
      'unsigned' => TRUE,
      'not null' => TRUE,
    ) + civicrm_entity_get_field_type($field_spec);
  }
  return empty($schema[$table]) ? array() : $schema[$table];
}