function tripal_chado_bundle_fields_info_linker

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

Parameters

$details:

1 call to tripal_chado_bundle_fields_info_linker()

File

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

Code

function tripal_chado_bundle_fields_info_linker(&$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'];

  // CONTACTS
  $contact_table = $table_name . '_contact';
  if (chado_table_exists($contact_table)) {
    $schema = chado_get_schema($contact_table);
    $pkey = $schema['primary key'][0];
    $field_name = $table_name . '_contact';
    $field_type = 'chado_linker__contact';
    $info[$field_name] = array(
      'field_name' => $field_name,
      'type' => $field_type,
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
      'locked' => FALSE,
      'storage' => array(
        'type' => 'field_chado_storage',
      ),
    );
  }

  // DBXREF
  $dbxref_table = $table_name . '_dbxref';
  if (chado_table_exists($dbxref_table)) {
    $field_name = 'sbo__database_cross_reference';
    $field_type = 'sbo__database_cross_reference';
    $info[$field_name] = array(
      'field_name' => $field_name,
      'type' => $field_type,
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
      'locked' => FALSE,
      'storage' => array(
        'type' => 'field_chado_storage',
      ),
    );
  }

  // EXPRESSION
  // TODO: this should only show up on gene or mRNA bunldes, not every feature.
  //   $expression_table = $table_name . '_expression';
  //   if (chado_table_exists($expression_table)) {
  //     $field_name = 'go__gene_expression';
  //     $field_type = 'go__gene_expression';
  //     $info[$field_name] = array(
  //       'field_name' => $field_name,
  //       'type' => $field_type,
  //       'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  //       'locked' => FALSE,
  //       'storage' => array(
  //         'type' => 'field_chado_storage',
  //       ),
  //     );
  //   }

  // FEATURELOC
  if ($table_name == 'feature') {
    $field_name = 'data__sequence_coordinates';
    $field_type = 'data__sequence_coordinates';
    $info[$field_name] = array(
      'field_name' => $field_name,
      'type' => $field_type,
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
      'locked' => FALSE,
      'storage' => array(
        'type' => 'field_chado_storage',
      ),
    );
  }

  // FEATUREPOS
  if ($table_name == 'feature') {
    $field_name = 'ogi__location_on_map';
    $field_type = 'ogi__location_on_map';
    $info[$field_name] = array(
      'field_name' => $field_name,
      'type' => $field_type,
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
      'locked' => FALSE,
      'storage' => array(
        'type' => 'field_chado_storage',
      ),
    );
  }

  //   // GENOTYPE
  //   $genotype_table = $table_name . '_genotype';
  //   if (chado_table_exists($genotype_table)) {
  //     $field_name = 'so__genotype';
  //     $field_type = 'so__genotype';
  //     $info[$field_name] = array(
  //       'field_name' => $field_name,
  //       'type' => $field_type,
  //       'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  //       'locked' => FALSE,
  //       'storage' => array(
  //         'type' => 'field_chado_storage',
  //       ),
  //     );
  //   }

  //   // PHENOTYPE
  //   $phenotype_table = $table_name . '_phenotype';
  //   if (chado_table_exists($phenotype_table)) {
  //     $field_name = 'sbo__phenotype';
  //     $field_type = 'sbo__phenotype';
  //     $info[$field_name] = array(
  //       'field_name' => $field_name,
  //       'type' => $field_type,
  //       'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  //       'locked' => FALSE,
  //       'storage' => array(
  //         'type' => 'field_chado_storage',
  //       ),
  //     );
  //   }

  // PROPERTIES
  $prop_table = $table_name . 'prop';
  if (chado_table_exists($prop_table)) {
    // Get the list of existing property types for this table.
    $sql = 'SELECT DISTINCT type_id FROM {' . $prop_table . '}';
    $props = chado_query($sql);
    while ($prop = $props->fetchObject()) {
      $term = chado_generate_var('cvterm', array('cvterm_id' => $prop->type_id));

      // The tripal_analysis_KEGG, tripal_analysis_blast, and
      // tripal_analysis_interpro modules store results in the analysisprop
      // table which is probably not the best place, but we don't want to
      // create a ton of fields for this, so skip them.
      if ($prop_table == 'analysisprop' and 
        ($term->dbxref_id->db_id->name == 'KEGG_BRITE' or
          $term->dbxref_id->db_id->name == 'tripal')) {
        continue;
      }

      $field_name = strtolower(preg_replace('/[^\w]/', '_', $term->dbxref_id->db_id->name . '__' . $term->name));
      $field_name = substr($field_name, 0, 32);
      $field_type = 'chado_linker__prop';
      $info[$field_name] = array(
        'field_name' => $field_name,
        'type' => $field_type,
        'cardinality' => 1,
        'locked' => FALSE,
        'storage' => array(
          'type' => 'field_chado_storage',
        ),
      );
    }
  }

  // CVTERMS
  $term_table = $table_name . '_cvterm';
  if (chado_table_exists($term_table)) {
    $schema = chado_get_schema($term_table);
    $pkey = $schema['primary key'][0];
    $lkey = key($schema['foreign keys'][$table_name]['columns']);
    $rkey = $schema['foreign keys'][$table_name]['columns'][$lkey];

    $field_name = 'sio__annotation';
    $field_type = 'sio__annotation';
    $info[$field_name] = array(
      'field_name' => $field_name,
      'type' => $field_type,
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
      'locked' => FALSE,
      'storage' => array(
        'type' => 'field_chado_storage',
      ),
    );
  }

  // PUBLICATIONS
  $pub_table = $table_name . '_pub';
  if (chado_table_exists($pub_table)) {
    $field_name = 'schema__publication';
    $field_type = 'schema__publication';
    $info[$field_name] = array(
      'field_name' => $field_name,
      'type' => $field_type,
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
      'locked' => FALSE,
      'storage' => array(
        'type' => 'field_chado_storage',
      ),
    );
  }

  // PUBLICATIONS (in reverse)
  // We want to be able to show all of the content that a publication links
  // to. The sio__references field does that.
  if ($table_name == 'pub') {
    $field_name = 'sio__references';
    $field_type = 'sio__references';
    $info[$field_name] = array(
      'field_name' => $field_name,
      'type' => $field_type,
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
      'locked' => FALSE,
      'storage' => array(
        'type' => 'field_chado_storage',
      ),
    );
  }

  // RELATIONSHIPS
  // If the linker table does not exists then we don't want to add attach.
  $rel_table = $table_name . '_relationship';
  if (chado_table_exists($rel_table)) {
    $field_name = 'sbo__relationship';
    $field_type = 'sbo__relationship';
    $info[$field_name] = array(
      'field_name' => $field_name,
      'type' => $field_type,
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
      'locked' => FALSE,
      'storage' => array(
        'type' => 'field_chado_storage',
      ),
    );
  }

  // SYNONYMS
  $syn_table = $table_name . '_synonym';
  if (chado_table_exists($syn_table)) {
    $field_name = 'schema__alternate_name';
    $field_type = 'schema__alternate_name';
    $info[$field_name] = array(
      'field_name' => $field_name,
      'type' => $field_type,
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
      'locked' => FALSE,
      'storage' => array(
        'type' => 'field_chado_storage',
      ),
      'settings' => array(
      ),
    );
  }
}