Ver Fonte

adding integration for analysis, constant, cv, db, organism and most of feature -not tested through views ui yet

Lacey Sanderson há 13 anos atrás
pai
commit
bf8d3639d1

+ 16 - 3
base/tripal_analysis/tripal_analysis.views.inc

@@ -35,10 +35,23 @@ require('views/misc_tables.views.inc');
 function tripal_analysis_views_data()  {
   $data = array();
 
-  $data = array_merge($data, retrieve_analysis_views_data());
-  $data = array_merge($data, retrieve_chado_analysis_views_data());
-  $data = array_merge($data, retrieve_analysis_misc_tables_views_data());
+  //$data = array_merge($data, retrieve_analysis_views_data());
+  //$data = array_merge($data, retrieve_chado_analysis_views_data());
+  //$data = array_merge($data, retrieve_analysis_misc_tables_views_data());
 
+  if (module_exists('tripal_views')) {
+    $tables = array(
+      'analysis',
+      'analysisfeature',
+      'analysisprop'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+  }
   return $data;
 }
 

+ 14 - 1
base/tripal_contact/tripal_contact.views.inc

@@ -24,7 +24,20 @@
  */
 function tripal_contact_views_data()  {
   $data = array();
-  
+
+  if (module_exists('tripal_views')) {
+    $tables = array(
+      'contact',
+      'contact_relationship',
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+  }
+    
   return $data;
 }
 

+ 20 - 2
base/tripal_cv/tripal_cv.views.inc

@@ -37,11 +37,29 @@ function tripal_cv_views_data() {
   
   //Function is contained in includes/cvterm.views.inc
   //Returns the data array for the chado cvterm table
-  $data = array_merge($data, retrieve_cvterm_views_data());
+  //$data = array_merge($data, retrieve_cvterm_views_data());
   
   //Function is contained in includes/cv.views.inc
   //Returns the data array for the chado cv table
-  $data = array_merge($data, retrieve_cv_views_data());
+  //$data = array_merge($data, retrieve_cv_views_data());
+  
+    if (module_exists('tripal_views')) {
+    $tables = array(
+      'cv',
+      'cvterm',
+      'cvterm_dbxref',
+      'cvterm_relationship',
+      'cvtermpath',
+      'cvtermprop',
+      'cvtermsynonym'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+  }
   
   return $data;
 }

+ 19 - 4
base/tripal_db/tripal_db.views.inc

@@ -30,11 +30,26 @@ require_once('views/db.views.inc');
  * @ingroup tripal_db_views
  */
 function tripal_db_views_data()  {
+  $data = array();
+   
+   //$data = array_merge($data, retrieve_dbxref_views_data());
+   //$data = array_merge($data, retrieve_db_views_data());
+   
+  if (module_exists('tripal_views')) {
+    $tables = array(
+      'db',
+      'dbxref',
+      'dbxrefprop'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+  }
 
-   $data = array();
-   $data = array_merge($data, retrieve_dbxref_views_data());
-   $data = array_merge($data, retrieve_db_views_data());
-   return $data;
+  return $data;
 
 }
 

+ 35 - 3
base/tripal_feature/tripal_feature.views.inc

@@ -35,9 +35,41 @@ require_once('views/misc_tables.views.inc');
 function tripal_feature_views_data()  {
   $data = array();
   
-  $data = array_merge($data, retrieve_feature_views_data());
-  $data = array_merge($data, retrieve_chado_feature_views_data());
-  $data = array_merge($data, retrieve_feature_misc_tables_views_data());
+  //$data = array_merge($data, retrieve_feature_views_data());
+  //$data = array_merge($data, retrieve_chado_feature_views_data());
+  //$data = array_merge($data, retrieve_feature_misc_tables_views_data());
+  
+  if (module_exists('tripal_views')) {
+    $tables = array(
+      'feature',
+      //'feature_cvterm',
+      'feature_cvterm_dbxref',
+      'feature_cvterm_pub',
+      'feature_cvtermprop',
+      'feature_dbxref',
+      'feature_pub',
+      'feature_pubprop',
+      'feature_relationship',
+      'feature_relationship_pub',
+      'feature_relationshipprop',
+      'feature_relationshipprop_pub',
+      'feature_synonym',
+      'featureloc',
+      'featureloc_pub',
+      'featureprop',
+      'featureprop_pub',
+      'featuremap',
+      'featuremap_pub',
+      'featurepos',
+      'featurerange'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+  }
   
   return $data;
 }

+ 16 - 2
base/tripal_organism/tripal_organism.views.inc

@@ -32,9 +32,23 @@ require_once('views/chado_organism.views.inc');
 function tripal_organism_views_data()  {
   $data = array();
   
-  $data = array_merge($data, retrieve_organism_views_data());
-  $data = array_merge($data, retrieve_chado_organism_views_data());
+  //$data = array_merge($data, retrieve_organism_views_data());
+  //$data = array_merge($data, retrieve_chado_organism_views_data());
   
+  if (module_exists('tripal_views')) {
+    $tables = array(
+      'organism',
+      'organismprop',
+      'organism_dbxref'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+  }
+
   return $data;
 }
 

+ 139 - 4
base/tripal_views/tripal_views.api.inc

@@ -24,6 +24,35 @@ function tripal_views_get_lightest_priority_setup ($table_name) {
   }
 }
 
+/** 
+ * Check to see if this table already has an integration record with the given priority
+ *
+ * @param $table_name
+ *   The name of the table to check for integration
+ * @param $priority (optional)
+ *   The priority of record to check for
+ *
+ * @return
+ *  If the table is already integrated, the setup_id of the existing integration 
+ *  record is returned (If priority is not specified this will be the lightest record);
+ *  Otherwise the table is not already integrated and FALSE is returned.
+ */
+function tripal_views_is_integrated($table_name, $priority = NULL) {
+  
+  if ($priority) {
+    $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name='%s' AND priority=%d";
+    $setup = db_fetch_object(db_query($sql, $table_name, $priority));
+  } else {
+    $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name='%s' ORDER BY priority ASC";
+    $setup = db_fetch_object(db_query($sql, $table_name));  
+  }
+  if ($setup) {
+    return $setup->setup_id;  
+  } else {
+    return FALSE;
+  }
+}
+
 /**
  * Checks if you are dealing with the lightest priority setup for a given table
  */
@@ -94,7 +123,12 @@ function tripal_views_integration_add_entry($defn_array) {
         return FALSE;
       }
   }
-  $status = drupal_write_record('tripal_views',$view_record);
+  if ($view_record['name'] && $view_record['comment']) {
+    $status = drupal_write_record('tripal_views',$view_record);
+  } else {
+    $status = FALSE;
+    drupal_set_message('Unable to integrate '.$defn_array['table'].' table due to a missing name or comment field.', 'error');
+  }
   
   if ($status) {
     
@@ -107,7 +141,12 @@ function tripal_views_integration_add_entry($defn_array) {
         'description' => $field['description'],
         'type' => $field['type'],
       );
-      $status = drupal_write_record('tripal_views_field',$field_record);
+      if ($view_record['setup_id'] && $field['name'] && $field['title'] && $field['description'] && $field['type']) {
+        $status = drupal_write_record('tripal_views_field',$field_record);
+      } else {
+        drupal_set_message('Unable to integrate '.$field['name'].' field due to a missing required fields.', 'error');
+        $status = FALSE;
+      }
       
       if ($status) {
       
@@ -120,7 +159,11 @@ function tripal_views_integration_add_entry($defn_array) {
             'handler_name' => $handler['name'],
             'arguments' => serialize($handler)
           );
-          $status = drupal_write_record('tripal_views_handlers',$handler_record);
+          if ($view_record['setup_id'] && $field['name'] && $handler_type && $handler['name'] && $handler) {
+            $status = drupal_write_record('tripal_views_handlers',$handler_record);
+          } else {
+            $status = FALSE;
+          }
           if (!$status) {
             drupal_set_message('Unable to integrate '.$handler_type.' handler: '.$handler['name'], 'error');
             $no_errors = FALSE;
@@ -144,7 +187,11 @@ function tripal_views_integration_add_entry($defn_array) {
           	$join_record['handler'] = 'views_join';
           }
 
-          $status = drupal_write_record('tripal_views_join',$join_record);
+          if ($view_record['setup_id'] && $defn_array['table'] && $field['name'] && $join['table'] && $join['field']) {
+            $status = drupal_write_record('tripal_views_join',$join_record);
+          } else {
+            $status = FALSE;
+          }
           if (!$status) {
             drupal_set_message('Unable to join '.$join['table'].'.'.$join['field'].' with '.$defn_array['table'].'.'.$field['name'], 'error');
             $no_errors = FALSE;
@@ -201,4 +248,92 @@ function tripal_views_integration_remove_entry_by_setup_id ($setup_id) {
     db_query('DELETE FROM {tripal_views_handlers} WHERE setup_id=%d',$setup_id);
     db_query('DELETE FROM {tripal_views_join} WHERE setup_id=%d',$setup_id);
 
+}
+
+/**
+ * Returns the array needed to integrate a given chado table with views
+ *
+ * @param $tablename
+ *   The table to generate the tripal views integration array for
+ * @return
+ *   The tripal views integration array which is the parameter for 
+ *   tripal_views_integration_add_entry($defn_array)
+ */
+function tripal_views_get_integration_array_for_chado_table ($table_name) {
+
+  // Get the schema for this table (via the chado schema api)
+  $schema = module_invoke_all('chado_'.$table_name.'_schema');
+  
+  // Base definition array
+  $defn_array = array(
+    'table' => $table_name,
+    'type' => 'chado',
+    'name' => ucwords(str_replace('_',' ',$table_name)),
+    'description' => ($schema['description']) ? $schema['description'] : ' ',
+    'priority' => 10,
+    'fields' => array(),
+  );
+  
+  // Add fields
+  foreach ($schema['fields'] as $field_name => $field_schema) {
+    
+    // Base field definition
+    if (!empty($field_name) && !empty($field_schema['type'])) {
+      $defn_array['fields'][$field_name] = array(
+        'name' => $field_name,
+        'title' => ucwords(str_replace('_',' ',$field_name)),
+        'type' => $field_schema['type'],
+        'description' => ($field_schema['description']) ? $field_schema['description'] : ' ',
+        'handlers' => array(),
+        'joins' => array()
+      );
+      
+      // Add handlers based on type
+      if (preg_match('/^int/',$field_schema['type'])) {
+        $defn_array['fields'][$field_name]['handlers'] = array(
+          'field' => array('name' => 'chado_views_handler_field_numeric'),
+          'filter' => array('name' => 'chado_views_handler_filter_numeric'),
+          'sort' => array('name' => 'chado_views_handler_sort'),
+        );
+      } elseif (preg_match('/^serial/',$field_schema['type'])) {
+        $defn_array['fields'][$field_name]['handlers'] = array(
+          'field' => array('name' => 'chado_views_handler_field_numeric'),
+          'filter' => array('name' => 'chado_views_handler_filter_numeric'),
+          'sort' => array('name' => 'chado_views_handler_sort'),
+        );
+        $defn_array['fields'][$field_name]['type'] = 'int';
+      } elseif (preg_match('/^varchar/',$field_schema['type'])) {
+        $defn_array['fields'][$field_name]['handlers'] = array(
+          'field' => array('name' => 'chado_views_handler_field'),
+          'filter' => array('name' => 'chado_views_handler_filter_string'),
+          'sort' => array('name' => 'chado_views_handler_sort'),
+        );
+      } elseif (preg_match('/^text/',$field_schema['type'])) {
+        $defn_array['fields'][$field_name]['handlers'] = array(
+          'field' => array('name' => 'chado_views_handler_field'),
+          'filter' => array('name' => 'chado_views_handler_filter_string'),
+          'sort' => array('name' => 'chado_views_handler_sort'),
+        );
+      } else {
+        $defn_array['fields'][$field_name]['handlers'] = array(
+          'field' => array('name' => 'chado_views_handler_field'),
+          'filter' => array('name' => 'chado_views_handler_filter_string'),
+          'sort' => array('name' => 'chado_views_handler_sort'),
+        );
+      }
+    }
+  }
+  
+  // Add Joins to fields
+  foreach ($schema['foreign keys'] as $foreign_key_schema) {
+    foreach ($foreign_key_schema['columns'] as $left_field => $right_field) {
+      $defn_array['fields'][$left_field]['joins'][ $foreign_key_schema['table'] ] = array(
+        'table' => $foreign_key_schema['table'],
+        'field' => $right_field,
+        'handler' => 'views_handler_join_chado_aggregtor'
+      );
+    }
+  }
+  
+  return $defn_array;
 }

+ 1 - 0
base/tripal_views/tripal_views.views.inc

@@ -375,6 +375,7 @@ function tripal_views_add_node_ids_to_view (&$view) {
 		
 	return $view;
 }
+
 /**
  * Generates a dynamic data array for Views
  *