Browse Source

Tripal Views: basic views integration using default views handlers is working. Still needs deep testing.

Lacey Sanderson 11 years ago
parent
commit
2e5f10b31b

+ 55 - 4
tripal_views/api/tripal_views.api.inc

@@ -510,11 +510,25 @@ function tripal_views_integration_remove_entry_by_setup_id($setup_id) {
 function tripal_views_integrate_all_chado_tables() {
 
   $tables = tripal_core_get_chado_tables(TRUE);
+
+  $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'
+  );
+
   foreach ($tables as $tablename) {
 
     $priority = 10;
     if (!tripal_views_is_integrated($tablename, $priority)) {
-      $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE, $priority);
+      if (in_array($tablename, $base_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);
+      }
       if ($table_integration_array) {
         tripal_views_integration_add_entry($table_integration_array);
       }
@@ -569,58 +583,93 @@ function tripal_views_get_integration_array_for_chado_table($table_name, $base_t
       // Add handlers based on type
       if (preg_match('/^int/', $field_schema['type'])) {
         $defn_array['fields'][$field_name]['handlers'] = array(
+          /** D6
           'field' => array('name' => 'chado_views_handler_field_numeric'),
           'filter' => array('name' => 'chado_views_handler_filter_numeric'),
           'sort' => array('name' => 'chado_views_handler_sort'),
+          */
+          'field' => array('name' => 'views_handler_field_numeric'),
+          'filter' => array('name' => 'views_handler_filter_numeric'),
+          'sort' => array('name' => 'views_handler_sort'),
         );
       }
       elseif (preg_match('/^serial/', $field_schema['type'])) {
         $defn_array['fields'][$field_name]['handlers'] = array(
+          /** D6
           'field' => array('name' => 'chado_views_handler_field_numeric'),
           'filter' => array('name' => 'chado_views_handler_filter_numeric'),
           'sort' => array('name' => 'chado_views_handler_sort'),
+          */
+          'field' => array('name' => 'views_handler_field_numeric'),
+          'filter' => array('name' => 'views_handler_filter_numeric'),
+          'sort' => array('name' => 'views_handler_sort'),
         );
         $defn_array['fields'][$field_name]['type'] = 'int';
       }
       elseif (preg_match('/^varchar/', $field_schema['type'])) {
         $defn_array['fields'][$field_name]['handlers'] = array(
+          /** D6
           'field' => array('name' => 'chado_views_handler_field'),
           'filter' => array('name' => 'chado_views_handler_filter_string'),
           'sort' => array('name' => 'chado_views_handler_sort'),
+          */
+          'field' => array('name' => 'views_handler_field'),
+          'filter' => array('name' => 'views_handler_filter_string'),
+          'sort' => array('name' => 'views_handler_sort'),
         );
       }
       elseif (preg_match('/^text/', $field_schema['type'])) {
         $defn_array['fields'][$field_name]['handlers'] = array(
+          /** D6
           'field' => array('name' => 'chado_views_handler_field'),
           'filter' => array('name' => 'chado_views_handler_filter_string'),
           'sort' => array('name' => 'chado_views_handler_sort'),
+          */
+          'field' => array('name' => 'views_handler_field'),
+          'filter' => array('name' => 'views_handler_filter_string'),
+          'sort' => array('name' => 'views_handler_sort'),
         );
       }
       elseif (preg_match('/^boolean/', $field_schema['type'])) {
         $defn_array['fields'][$field_name]['handlers'] = array(
+          /**
           'field' => array('name' => 'chado_views_handler_field_boolean'),
           'filter' => array('name' => 'chado_views_handler_filter_boolean_operator'),
           'sort' => array('name' => 'chado_views_handler_sort'),
+          */
+          'field' => array('name' => 'views_handler_field_boolean'),
+          'filter' => array('name' => 'views_handler_filter_boolean_operator'),
+          'sort' => array('name' => 'views_handler_sort'),
         );
       }
       elseif (preg_match('/^datetime/', $field_schema['type'])) {
         $defn_array['fields'][$field_name]['handlers'] = array(
+          /** D6
           'field' => array('name' => 'chado_views_handler_field_date'),
           'filter' => array('name' => 'chado_views_handler_filter_date'),
           'sort' => array('name' => 'views_handler_sort_date'),
+          */
+          'field' => array('name' => 'views_handler_field_date'),
+          'filter' => array('name' => 'views_handler_filter_date'),
+          'sort' => array('name' => 'views_handler_sort_date'),
         );
       }
       else {
         $defn_array['fields'][$field_name]['handlers'] = array(
+          /** D6
           'field' => array('name' => 'chado_views_handler_field'),
           'filter' => array('name' => 'chado_views_handler_filter_string'),
           'sort' => array('name' => 'chado_views_handler_sort'),
+          */
+          'field' => array('name' => 'views_handler_field'),
+          'filter' => array('name' => 'views_handler_filter_string'),
+          'sort' => array('name' => 'views_handler_sort'),
         );
       }
 
       // Specify specialty handlers
       if ($field_name == 'type_id' OR $field_name == 'cvterm_id') {
-        $defn_array['fields'][$field_name]['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_cvterm';
+        //$defn_array['fields'][$field_name]['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_cvterm';
       }
     }
   }
@@ -636,12 +685,14 @@ function tripal_views_get_integration_array_for_chado_table($table_name, $base_t
       $defn_array['fields'][$left_field]['joins'][ $foreign_key_schema['table'] ] = array(
         'table' => $foreign_key_schema['table'],
         'field' => $right_field,
-        'handler' => 'views_handler_join_chado_aggregator'
+        /**D6 'handler' => 'views_handler_join_chado_aggregator'*/
+        'handler' => 'views_handler_join'
       );
 
       // Relationship Handler
       $defn_array['fields'][$left_field]['handlers']['relationship'] = array(
-        'name' => 'chado_views_handler_relationship',
+        /**D6 'name' => 'chado_views_handler_relationship',*/
+        'name' => 'views_handler_relationship',
         'base' => $foreign_key_schema['table'],
         'base field' => $right_field,
         'label' => $table_name . ' ' . $left_field . ' => ' . $foreign_key_schema['table'] . ' ' . $right_field

+ 1 - 1
tripal_views/tripal_views.info

@@ -46,5 +46,5 @@ files[] = views/handlers/tripal_views_handler_field_aggregate.inc
 files[] = views_data_export/plugins/tripal_views_plugin_style_export_fasta.inc
 
 dependencies[] = views
-dependencies[] = views_data_export
+;dependencies[] = views_data_export
 dependencies[] = tripal_core

+ 58 - 61
tripal_views/tripal_views.views.inc

@@ -1,7 +1,7 @@
 <?php
 
-include('views/handlers/views_handler_join_chado_through_linking.inc');
-include('views/handlers/views_handler_join_chado_aggregator.inc');
+// include('views/handlers/views_handler_join_chado_through_linking.inc');
+// include('views/handlers/views_handler_join_chado_aggregator.inc');
 include('api/tripal_views.api.inc');
 
 
@@ -67,6 +67,7 @@ function tripal_views_views_handlers() {
     'handlers' => array(
 
       // Custom Tripal Filter Handlers
+      /** D7 @todo: get handlers working
       'tripal_views_handler_filter_file_upload' => array(
         'parent' => 'views_handler_filter',
       ),
@@ -85,32 +86,40 @@ function tripal_views_views_handlers() {
       'tripal_views_handler_filter_sequence' => array(
         'parent' => 'chado_views_handler_filter_string',
       ),
+      */
 
       // Custom Tripal Field Handlers
+      /** D7 @todo: get handlers working
       'tripal_views_handler_field_aggregate' => array(
         'parent' => 'chado_views_handler_field',
       ),
       'tripal_views_handler_field_sequence' => array(
         'parent' => 'chado_views_handler_field',
       ),
+      */
 
       // Join Handlers
+      /** D7 @todo: determine if we need these anymore :)
       'views_handler_join_chado_aggregator' => array(
         'parent' => 'views_join',
       ),
       'views_handler_join_chado_through_linking' => array(
         'parent' => 'views_join',
       ),
+      */
 
       // Relationship Handlers
+      /** D7 @todo: determine if we need these anymore
       'chado_views_handler_relationship' => array(
         'parent' => 'views_handler_relationship'
       ),
       'chado_views_handler_relationship_to_node' => array(
         'parent' => 'views_handler_relationship'
       ),
+      */
 
       // Wrappers for Default Views Handlers-----
+      /** D7 @todo: determine if we need these anymore :)
       // Field Handlers
       'chado_views_handler_field' => array(
         'parent' => 'views_handler_field'
@@ -174,6 +183,7 @@ function tripal_views_views_handlers() {
       'chado_views_handler_sort_random' => array(
         'parent' => 'views_handler_sort_random'
       ),
+      */
     ),
   );
 }
@@ -189,7 +199,6 @@ function tripal_views_views_handlers() {
  * @todo add if !<chado/drupal same db> around NID portion
  *
  * @ingroup tripal_views
- */
 function tripal_views_views_pre_render(&$view) {
 
   // We need to unset the exposed_input for the view so we can repopulate that
@@ -205,6 +214,7 @@ function tripal_views_views_pre_render(&$view) {
   $form = drupal_get_form('tripal_views_data_export_download_form', $view, $display_id, $args);
   $view->attachment_after = $form;
 }
+*/
 
 /**
  * Generates a dynamic data array for Views
@@ -218,8 +228,8 @@ function tripal_views_views_pre_render(&$view) {
  *
  * @ingroup tripal_views
  */
-
 function tripal_views_views_data() {
+  $data = array();
 
   // Make sure all chado tables are integrated
   tripal_views_integrate_all_chado_tables();
@@ -376,6 +386,7 @@ function tripal_views_views_data() {
         'group' => "$tvi_row->name",
         'title' => "$tvi_row->name",
         'help'  => $tvi_row->comment,
+        'search_path' => 'chado'
       );
     }
     else {
@@ -383,6 +394,7 @@ function tripal_views_views_data() {
         'group' => "$tvi_row->name",
         'title' => "$tvi_row->name",
         'help'  => $tvi_row->comment,
+        'search_path' => 'chado'
       );
     }
 
@@ -474,6 +486,7 @@ function tripal_views_views_data() {
 
           // add the join instructions for the base table
           // (we'll add the recipricol joins for the node table in the hook_views_data_alter
+          /**
           $data[$base_table]['table']['join'][$linker_table] = array(
             'left_field' => 'organism_id',
             'field' => 'organism_id',
@@ -483,6 +496,7 @@ function tripal_views_views_data() {
             'left_field' => 'organism_id',
             'field' => 'organism_id',
           );
+          */
 
 
 			    // Add relationship between linker and base table
@@ -520,42 +534,49 @@ function tripal_views_views_data() {
 		  }
     }
 
-    // now add the joins
-    // D7 TODO: Check DBTNG changes work
-    $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = :setup";
-    $joins = db_query($sql, array(':setup' => $setup_id));
-    if (!isset($joins)) {
-      $joins = array();
-    }
-    foreach ($joins as $join) {
-      $left_table = $join->left_table;
-      $left_field = $join->left_field;
-      $base_field = $join->base_field;
-      $handler = $join->handler;
-
-      // if the 'node' table is in our integrated list then
-      // we want to skip it. It shouldn't be there.
-      if ($left_table == 'node') {
-      	continue;
+    // only add joins if this is a base table
+    // this keeps the list of available fields manageable
+    // all other tables should be added via relationships
+    // D7 todo: add tripal_views_join field that determines whether a join is added
+    if ($is_base_table) {
+      // now add the joins
+      // D7 TODO: Check DBTNG changes work
+      $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = :setup";
+      $joins = db_query($sql, array(':setup' => $setup_id));
+      if (!isset($joins)) {
+        $joins = array();
       }
+      foreach ($joins as $join) {
+        $left_table = $join->left_table;
+        $left_field = $join->left_field;
+        $base_field = $join->base_field;
+        $handler = $join->handler;
 
-      // add join entry
-      $data[$base_table]['table']['join'][$left_table] = array(
-        'left_field' => $left_field,
-        'field' => $base_field,
-      );
-      if ($handler) {
-        $data[$base_table]['table']['join'][$left_table]['handler'] = $handler;
+        // if the 'node' table is in our integrated list then
+        // we want to skip it. It shouldn't be there.
+        if ($left_table == 'node') {
+          continue;
+        }
+
+        // add join entry
+        $data[$left_table]['table']['join'][$base_table] = array(
+          'left_field' => $base_field,
+          'field' => $left_table . '_id',
+        );
+        if ($handler) {
+          $data[$left_table]['table']['join'][$base_table]['handler'] = $handler;
+        }
       }
     }
   }
+
   return $data;
 }
 
 /**
  *
  * @ingroup tripal_views
- */
+
 function tripal_views_views_data_alter(&$data) {
     // D7 TODO: Check DBTNG changes work
     $tvi_query = db_query('SELECT * FROM {tripal_views}');
@@ -609,10 +630,10 @@ function tripal_views_views_data_alter(&$data) {
     }
     return $data;
 }
+*/
 
 /**
  * Implementation of hook_views_plugins().
- */
 function tripal_views_views_plugins() {
   $tc_path = drupal_get_path('module', 'tripal_views');
 
@@ -652,6 +673,7 @@ function tripal_views_views_plugins() {
     ),
   );
 }
+*/
 
 /**
  * Implementation of hook_views_pre_view().
@@ -661,7 +683,7 @@ function tripal_views_views_pre_view(&$view, &$display_id, &$args) {
   // merge the $_GET and $_POST into the $_GET. This is because
   // Views and Views Data Export modules only uses the $_GET variable but
   // file uploads require $_POST. We need to make sure these two modules
-  // have access to everything needed for this view to work properlys
+  // have access to everything needed for this view to work properly
   $_GET = array_merge($_GET, $_POST);
 }
 
@@ -677,35 +699,8 @@ function tripal_views_views_pre_view(&$view, &$display_id, &$args) {
   $view->attachment_after = $form;
 }*/
 
-/*
- *
-
-function tripal_views_views_query_alter(&$view, &$query){
-  // iterate through the tables and see if they are chado tables.
-  // if they are then prefix them with a "chado." prefix
-  dpm($query);
-  $tables = $query->tables;
-  foreach ($tables as $base => $subtables) {
-    $desc = tripal_core_get_chado_table_schema($base);
-    if ($desc) {
-      $query->tables["chado." . $base] = $subtables;
-      unset($query->tables[$base]);
-      $base = "chado." . $base;
-    }
-    foreach ($subtables as $subtable => $values) {
-      $desc = tripal_core_get_chado_table_schema($subtable);
-      if ($desc) {
-        $query->tables[$base]["chado." . $subtable] = $values;
-        unset($query->tables[$base][$subtable]);
-      }
-    }
-  }
-
-  dpm($query);
-} */
 /**
  * Implementation of hook_views_pre_execute().
- */
 function tripal_views_views_pre_execute(&$view) {
   // if the base table is a chado table then we want to set the
   // search path so it can find all of the tables.
@@ -716,9 +711,10 @@ function tripal_views_views_pre_execute(&$view) {
     tripal_db_set_chado_search_path('chado');
   }
 }
+*/
+
 /**
  * Implementation of hook_views_post_render().
- */
 function tripal_views_views_post_render(&$view, &$output, &$cache) {
   // if the base table and the query is completed we want to set
   // the search path back to the default.
@@ -727,10 +723,10 @@ function tripal_views_views_post_render(&$view, &$output, &$cache) {
     tripal_db_set_default_search_path();
   }
 }
+*/
 
 /**
  * the Download Views data export form
- */
 function tripal_views_data_export_download_form(&$form_state, $view, $display_id, $args) {
   $form = array();
   $urls = array();
@@ -797,15 +793,16 @@ function tripal_views_data_export_download_form(&$form_state, $view, $display_id
   }
   return $form;
 }
+*/
 
 /**
  * Submit for the Download Views data export form
- */
 function tripal_views_data_export_download_form_submit($form, &$form_state) {
   $urls = $form_state['storage']['urls'];
   $display_id = $form_state['values']['file_type'];
   drupal_goto($urls[$display_id]['path'], $urls[$display_id]['query']);
 }
+*/