Browse Source

Fixed a bug where the views_handler_filter_float was used but this handler is no longer available in D7 views. Also added a new API function of MViews and made a few minor commenting fixes

Stephen Ficklin 10 years ago
parent
commit
4569c6abc6

+ 30 - 8
tripal_core/api/tripal_core.mviews.api.inc

@@ -120,7 +120,7 @@ function tripal_add_mview($name, $modulename, $mv_schema, $query, $comment = NUL
        'Must have a table name when creating an mview.', array());
      return NULL;
   }
-  
+
   $mv_table = $mv_schema['table'];
 
   // see if the mv_table name already exsists
@@ -138,16 +138,16 @@ function tripal_add_mview($name, $modulename, $mv_schema, $query, $comment = NUL
       $record->mv_table = $mv_table;
       $record->query = $query;
       $record->comment = $comment;
-      
+
       // convert the schema into a string format
       $str_schema = var_export($mv_schema, TRUE);
       $str_schema = preg_replace('/=>\s+\n\s+array/', '=> array', $str_schema);
       $record->mv_schema = $str_schema;
-  
+
       // add the record to the tripal_mviews table and if successful
       // create the new materialized view in the chado schema
       if (drupal_write_record('tripal_mviews', $record)) {
-  
+
         // drop the table from chado if it exists
         if (chado_table_exists($mv_table)) {
           $sql = 'DROP TABLE {' . $mv_table . '}';
@@ -220,7 +220,7 @@ function tripal_edit_mview($mview_id, $name, $modulename, $mv_table, $mv_specs,
       eval("\$schema_arr = $mv_schema;");
       $mv_table = $schema_arr['table'];
     }
-  
+
     $record = new stdClass();
     $record->mview_id    = $mview_id;
     $record->name        = $name;
@@ -231,10 +231,10 @@ function tripal_edit_mview($mview_id, $name, $modulename, $mv_table, $mv_specs,
     $record->comment     = $comment;
     $record->mv_schema   = $mv_schema;
     $record->mv_table    = $mv_table;
-    
+
     // update the record to the tripal_mviews table
     drupal_write_record('tripal_mviews', $record, 'mview_id');
-  
+
     // get the view before we update and check to see if the table structure has
     // changed. If so, then we want to drop and recreate the table. If not, then
     // just save the updated SQL.
@@ -253,7 +253,7 @@ function tripal_edit_mview($mview_id, $name, $modulename, $mv_table, $mv_specs,
       }
       drupal_set_message(t($message, array('%name' => $name)));
     }
-      
+
     // construct the indexes SQL if needed
     $index = '';
     if ($indexed) {
@@ -349,6 +349,28 @@ function tripal_refresh_mview($mview_id) {
 
 }
 
+/**
+ * Retrieves the list of materialized view IDs and their names
+ *
+ * @return
+ *   An array of objects with the following properties:  mview_id, name
+ *
+ * @ingroup tripal_mviews_api
+ *
+ */
+function tripal_get_mviews() {
+
+  $results = db_select('tripal_mviews', 'tm')
+    ->fields('tm', array('mview_id', 'name'))
+    ->execute();
+
+  $list = array();
+  while ($mview = $results->fetchObject()) {
+    $list[] = $mview;
+  }
+  return $list;
+}
+
 /**
  * Does the specified action for the specified Materialized View
  *

+ 6 - 6
tripal_core/tripal_core.install

@@ -394,8 +394,8 @@ function tripal_core_get_tripal_token_schema() {
 }
 
 /**
- * 
- * 
+ *
+ *
  */
 function tripal_core_get_tripal_toc_schema() {
   $schema = array();
@@ -450,7 +450,7 @@ function tripal_core_get_tripal_toc_schema() {
 }
 
 /**
- * 
+ *
  */
 function tripal_core_get_tripal_vars_schema() {
   $schema = array();
@@ -486,7 +486,7 @@ function tripal_core_get_tripal_vars_schema() {
       ),
     ),
   );
-  
+
   $schema['tripal_node_variables'] = array(
     'description' => 'This table is used for storing any type of variable such as ' .
       'a property or setting that should be associated with a Tripal managed Drupal node.  This table is '.
@@ -544,7 +544,7 @@ function tripal_core_get_tripal_vars_schema() {
       ),
     ),
   );
-  
+
   return $schema;
 }
 
@@ -646,7 +646,7 @@ function tripal_core_update_7203() {
   catch (Exception $e) {
     $error = $e->getMessage();
     throw new DrupalUpdateException('Could not add tripal_toc table: '. $error);
-    
+
   }
 }
 

+ 3 - 0
tripal_views/api/tripal_views.api.inc

@@ -563,6 +563,9 @@ function tripal_rebuild_views_integrations($delete_first = FALSE) {
   }
 
   tripal_views_integrate_all_chado_tables();
+
+  // TODO: the function above should have a return value from which we can
+  // determine if the message below is approprite.
   drupal_set_message('Successfully rebuilt default Tripal Views Integrations');
 }
 

+ 31 - 2
tripal_views/includes/tripal_views_integration.inc

@@ -28,8 +28,9 @@ function tripal_views_delete_all_integrations() {
  */
 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);
-
   $base_tables = array(
     'acquisition', 'analysis', 'assay', 'biomaterial', 'contact', 'cv', 'cvterm',
     'db', 'dbxref', 'environment', 'expression', 'feature', 'featuremap', 'genotype',
@@ -39,7 +40,6 @@ function tripal_views_integrate_all_chado_tables() {
   );
 
   foreach ($tables as $tablename) {
-
     $priority = 10;
     if (!tripal_is_table_integrated($tablename, $priority)) {
       if (in_array($tablename, $base_tables)) {
@@ -114,6 +114,7 @@ function tripal_views_get_integration_array_for_chado_table($table_name, $base_t
           'argument' => array('name' => 'views_handler_argument_numeric'),
         );
       }
+      // Set the defaults for a serial type.
       elseif (preg_match('/^serial/', $field_schema['type'])) {
         $defn_array['fields'][$field_name]['handlers'] = array(
           /** D6
@@ -128,6 +129,7 @@ function tripal_views_get_integration_array_for_chado_table($table_name, $base_t
         );
         $defn_array['fields'][$field_name]['type'] = 'int';
       }
+      // Set the defaults for a varchar type.
       elseif (preg_match('/^varchar/', $field_schema['type'])) {
         $defn_array['fields'][$field_name]['handlers'] = array(
           /** D6
@@ -141,6 +143,7 @@ function tripal_views_get_integration_array_for_chado_table($table_name, $base_t
           'argument' => array('name' => 'views_handler_argument_string'),
         );
       }
+      // Set the defaults for a text type.
       elseif (preg_match('/^text/', $field_schema['type'])) {
         $defn_array['fields'][$field_name]['handlers'] = array(
           /** D6
@@ -154,6 +157,21 @@ function tripal_views_get_integration_array_for_chado_table($table_name, $base_t
           'argument' => array('name' => 'views_handler_argument_string'),
         );
       }
+      // Set the defaults for a char type.
+      elseif (preg_match('/^char/', $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'),
+          'argument' => array('name' => 'views_handler_argument_string'),
+        );
+      }
+      // Set the defaults for a boolean type.
       elseif (preg_match('/^boolean/', $field_schema['type'])) {
         $defn_array['fields'][$field_name]['handlers'] = array(
           /**
@@ -166,6 +184,7 @@ function tripal_views_get_integration_array_for_chado_table($table_name, $base_t
           'sort' => array('name' => 'views_handler_sort'),
         );
       }
+      // Set the defaults for a datatime type.
       elseif (preg_match('/^datetime/', $field_schema['type'])) {
         $defn_array['fields'][$field_name]['handlers'] = array(
           /** D6
@@ -179,6 +198,16 @@ function tripal_views_get_integration_array_for_chado_table($table_name, $base_t
           'argument' => array('name' => 'views_handler_argument_date'),
         );
       }
+      // Set the defaults for a float type.
+      elseif (preg_match('/^float/', $field_schema['type'])) {
+        $defn_array['fields'][$field_name]['handlers'] = array(
+          'field' => array('name' => 'views_handler_field_numeric'),
+          'filter' => array('name' => 'views_handler_filter_numeric'),
+          'sort' => array('name' => 'views_handler_sort'),
+          'argument' => array('name' => 'views_handler_argument_numeric'),
+        );
+      }
+      // If the type is not recognize the default to a string handler.
       else {
         $defn_array['fields'][$field_name]['handlers'] = array(
           /** D6

+ 4 - 2
tripal_views/includes/tripal_views_integration_UI.inc

@@ -694,6 +694,9 @@ function tripal_views_integration_form($form, &$form_state) {
          '#default_value' => $default_field_handler,
       );
 
+      // Assign the default filter handler for this field.  Use the handler provided
+      // by the user through the form if provided, or set the default using the
+      // column type.
       $default_filter_handler = 0;
       if (isset($setup_id) && !isset($form_state['values']["fields_filter_handler_$table_id-$i"])) {
         $default_filter_handler = array_key_exists('filter', $default_handlers[$column_name]) ? $default_handlers[$column_name]['filter']['handler_name'] : "";
@@ -712,7 +715,7 @@ function tripal_views_integration_form($form, &$form_state) {
             $default_filter_handler = 'views_handler_filter_boolean';
           }
           elseif ($column_type == 'float') {
-            $default_filter_handler = 'views_handler_filter_float';
+            $default_filter_handler = 'views_handler_filter_numeric';
           }
           elseif ($column_type == 'datetime') {
             $default_filter_handler = 'views_handler_filter_date';
@@ -1391,7 +1394,6 @@ function tripal_views_integration_discover_handlers() {
   $handlers[] = 'views_handler_filter_boolean_operator_string';
   $handlers[] = 'views_handler_filter_in_operator';
   $handlers[] = 'views_handler_filter_numeric';
-  $handlers[] = 'views_handler_filter_float';
   $handlers[] = 'views_handler_filter_date';
   $handlers[] = 'views_handler_filter_many_to_one';
 

+ 2 - 1
tripal_views/tripal_views.views.inc

@@ -96,7 +96,8 @@ function tripal_views_views_pre_render(&$view) {
 }
 
 /**
- * Implements hook_views_date().
+ * Implements hook_views_data().
+ *
  * Generates a dynamic data array for Views
  *
  * This function is a hook used by the Views module. It populates and