function tripal_views_integrate_all_chado_tables

2.x tripal_views_integration.inc tripal_views_integrate_all_chado_tables()
1.x tripal_views.api.inc tripal_views_integrate_all_chado_tables()

Integrate all chado tables in the schema api. This integration only occurs once and sets all Chado tables to a priority of 10

Related topics

2 calls to tripal_views_integrate_all_chado_tables()
tripal_rebuild_views_integrations in tripal_views/api/tripal_views.api.inc
Rebuilds all the default integrations.
tripal_views_views_data in tripal_views/tripal_views.views.inc
Implements hook_views_data().

File

tripal_views/includes/tripal_views_integration.inc, line 29
Contains functions used to manage tripal views integrations

Code

function tripal_views_integrate_all_chado_tables() {

  // First integrate all of the Chado tables. Those that are base tables
  // get special treatment.
  $tables = chado_get_table_names(TRUE);

  // Some chado tables might have been created via the Tripal Custom Tables
  // or Tripal Materialized Views interfaces. We need to ensure that the
  // corresponding mview_id and table_id are associated with these tables.
  // @TODO: Add some way to show which integrations are for custom tables.
  //$custom_tables = chado_get_custom_table_names();
  $mview_tables = chado_get_mview_table_names();

  // Hardcode a list of base tables since there isn't really a programatic way
  // to determine which tables in the chado schema should be base tables.
  $base_tables = array(
    'acquisition', 'analysis', 'assay', 'biomaterial', 'contact', 'cv', 'cvterm',
    'db', 'dbxref', 'environment', 'expression', 'feature', 'featuremap', 'genotype',
    'library', 'nd_experiment', 'nd_geolocation', 'nd_protocol', 'nd_reagent',
    'organism', 'phendesc', 'phenotype', 'phenstatement', 'phylonode', 'phylotree',
    'project', 'protocol', 'pub', 'stock', 'study', 'synonym'
  );

  // For each chado table, generate an integration array, keeping the above
  // details in mind, and save that integration with Tripal Views through the API.
  foreach ($tables as $tablename) {
    $priority = 10;
    if (!tripal_is_table_integrated($tablename, $priority)) {

      // Assuming that we have a default chado table, genereate an integration
      // array describing it's Tripal Views integration.
      if (in_array($tablename, $base_tables) OR (is_array($mview_tables) and in_array($tablename, $mview_tables))) {
        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE, $priority);
      }
      else {
        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE, $priority);
      }

      // Check to see if this table is a Materialized view and if it is,
      // treat it specially :).
      if (is_array($mview_tables) and in_array($tablename, $mview_tables)) {
        $table_integration_array['type'] = 'mview';
      }

      // As long as we were able to generate an integration array,
      // Integrate It!
      if ($table_integration_array) {
        tripal_add_views_integration($table_integration_array);
      }
    }
  }
}