function tripal_chado_bundle_fields_info_base

3.x tripal_chado.fields.inc tripal_chado_bundle_fields_info_base(&$info, $details, $entity_type, $bundle)

Parameters

unknown $details:

1 call to tripal_chado_bundle_fields_info_base()

File

tripal_chado/includes/tripal_chado.fields.inc, line 44

Code

function tripal_chado_bundle_fields_info_base(&$info, $details, $entity_type, $bundle) {

  $table_name = $details['chado_table'];
  $type_table = $details['chado_type_table'];
  $type_column = $details['chado_type_column'];
  $cvterm_id = $details['chado_cvterm_id'];
  $type_value = $details['chado_type_value'];

  // Iterate through the columns of the table and see if fields have been
  // created for each one. If not, then create them.
  $schema = chado_get_schema($table_name);
  if (!$schema) {
    return;
  }

  $pkey = $schema['primary key'][0];


  // Get the list of columns for this table and create a new field for each one.
  $columns = $schema['fields'];
  foreach ($columns as $column_name => $details) {

    // Skip the source columns  in the analysis table. We have a custom
    // field for those columns
    if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
        $column_name == 'sourceversion' or $column_name == 'sourcename')) {
      continue;
    }

    // Skip the infraspecific type_id and name from the organism table as we
    // have a special field for those.
    if ($table_name == 'organism' and ($column_name == 'type_id' or
        $column_name == 'infraspecific_name')) {
      continue;
    }

    // Skip the cvterm.is_relationshptype.
    if ($table_name == 'cvterm' and $column_name == 'is_relationshiptype') {
      continue;
    }

    // The biosourceprovider_id and taxon_id are handled by custom fields.
    if ($table_name == 'biomaterial' and (
      $column_name == 'biosourceprovider_id' or $column_name == 'taxon_id')) {
      continue;
    }

    // Don't create base fields for the primary key and the type_id field.
    if ($column_name == $pkey or $column_name == $type_column) {
      continue;
    }
    $cvterm = chado_get_semweb_term($table_name, $column_name, array('return_object' => TRUE));
    if (!$cvterm) {
      tripal_report_error('tripal', TRIPAL_ERROR, 
      'Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term', 
      array('%table_name' => $table_name, '%column_name' => $column_name));
      drupal_set_message(t('Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term', 
      array('%table_name' => $table_name, '%column_name' => $column_name)), 'error');
      continue;
    }
    $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/[^\w]/', '_', $cvterm->name));
    $field_name = substr($field_name, 0, 32);

    // Skip the primary key field.
    if ($column_name == $schema['primary key'][0]) {
      continue;
    }

    // If the type_id defines the content type and it's part of the
    // base table and this column is the type_id then skip it.
    if (!$type_table and $type_column and $column_name == $type_column) {
      continue;
    }

    // Skip the type ID as it will be handled by a custom field.
    if ($column_name == 'type_id') {
      continue;
    }

    // Set some defaults for the field.
    $base_info = array(
      'field_name' => $field_name,
      'type' => '',
      'cardinality' => 1,
      'locked' => FALSE,
      'storage' => array(
        'type' => 'field_chado_storage',
        'sql' => array(),
      ),
    );

    // Alter the field info array depending on the column details.
    switch ($details['type']) {
      case 'char':
        $base_info['type'] = 'text';
        $base_info['settings']['max_length'] = $details['length'];
        break;
      case 'varchar':
        $base_info['type'] = 'text';
        $base_info['settings']['max_length'] = $details['length'];
        break;
      case 'text':
        $base_info['type'] = 'text';
        $base_info['settings']['max_length'] = 17179869184;
        $base_info['settings']['text_processing'] = 1;
        break;
      case 'blob':
        // not sure how to support a blob field.
        continue;
        break;
      case 'int':
        $base_info['type'] = 'number_integer';
        break;
      case 'float':
        $base_info['type'] = 'number_float';
        $base_info['settings']['precision'] = 10;
        $base_info['settings']['scale'] = 2;
        $base_info['settings']['decimal_separator'] = '.';
        break;
      case 'numeric':
        $base_info['type'] = 'number_decimal';
        break;
      case 'serial':
        // Serial fields are most likely not needed as a field.
        break;
      case 'boolean':
        $base_info['type'] = 'list_boolean';
        $base_info['settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
        break;
      case 'datetime':
        // Use the Drupal Date and Date API to create the field/widget
        $base_info['type'] = 'datetime';
        break;
    }

    // Set some defaults for biomaterial table
    if ($table_name == 'biomaterial' and $column_name == 'name') {
      $base_info['type'] = 'text';
      $base_info['settings']['max_length'] = '2048';
      $base_info['settings']['text_processing'] = 0;
    }

    // Set some default semantic web information
    if ($column_name == 'uniquename') {
      $base_info['settings']['text_processing'] = 0;
    }

    // Sometimes the boolean fields are listed as integer.  We need to
    // correct for that.
    if ($column_name == 'is_obsolete' or $column_name == 'is_analysis' or 
      $column_name == 'is_relationshiptype' or $column_name == 'is_for_definition' or 
      $column_name == 'is_view' or $column_name == 'is_updateable') {
      $base_info['type'] = 'list_boolean';
      $base_info['settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
    }

    //
    // PUB TABLE
    //
    if ($table_name == 'pub' and (
      $column_name == 'uniquename' or $column_name == 'title' or
        $column_name == 'volumetitle')) {
      $base_info['type'] = 'text';
      $base_info['settings']['text_processing'] = 0;
    }
    $info[$field_name] = $base_info;
  }
}