Browse Source

Views: Created a function to handle making default views compatible with external chado instances by removing non-chado tables from the definition and implemented it for all chado default views.

Lacey Sanderson 11 years ago
parent
commit
a3faf9f7ef

+ 1 - 0
tripal_analysis/tripal_analysis.views_default.inc

@@ -16,6 +16,7 @@ function tripal_analysis_views_default_views() {
   $views = array();
 
   $view = tripal_analysis_defaultvalue_admin_analysis();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
   return $views;

+ 1 - 0
tripal_contact/tripal_contact.views_default.inc

@@ -15,6 +15,7 @@ function tripal_contact_views_default_views() {
   $views = array();
 
   $view = tripal_contact_defaultview_admin_contacts();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
   return $views;

+ 4 - 2
tripal_cv/tripal_cv.views_default.inc

@@ -12,12 +12,14 @@
 function tripal_cv_views_default_views() {
   $views = array();
 
-  // Default Tripal Admin View: Jobs
+  // Default Tripal Admin View: CVs
   $view = tripal_cv_defaultview_admin_cvs_listing();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
-  // Default Tripal Admin View: Templates
+  // Default Tripal Admin View: CV Terms
   $view = tripal_cv_defaultview_admin_cvterms_listing();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
   return $views;

+ 2 - 0
tripal_db/tripal_db.views_default.inc

@@ -14,10 +14,12 @@ function tripal_db_views_default_views() {
 
   // Default Tripal Admin View: DB
   $view = tripal_db_defaultview_admin_db_listing();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
   // Default Tripal Admin View: DB References
   $view = tripal_db_defaultview_admin_dbxref_listing();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
   return $views;

+ 1 - 0
tripal_feature/tripal_feature.views_default.inc

@@ -13,6 +13,7 @@ function tripal_feature_views_default_views() {
   $views = array();
 
   $view = tripal_feature_defaultview_admin_features();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
   return $views;

+ 1 - 0
tripal_featuremap/tripal_featuremap.views_default.inc

@@ -13,6 +13,7 @@ function tripal_featuremap_views_default_views() {
   $views = array();
 
   $view = tripal_featuremap_defaultview_admin_featuremaps();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
   return $views;

+ 1 - 0
tripal_genetic/tripal_genetic.views_default.inc

@@ -13,6 +13,7 @@ function tripal_genetic_views_default_views() {
   $views = array();
 
   $view = tripal_genetic_defaultviews_admin_genotypes();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
   return $views;

+ 1 - 0
tripal_library/tripal_library.views_default.inc

@@ -13,6 +13,7 @@ function tripal_library_views_default_views() {
   $views = array();
 
   $view = tripal_library_admin_defaultviews_library();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
   return $views;

+ 4 - 0
tripal_natural_diversity/tripal_natural_diversity.views_default.inc

@@ -14,18 +14,22 @@ function tripal_natural_diversity_views_default_views() {
 
   // Experiment Listing
   $view = tripal_natural_diversity_defaultview_admin_natdiv_exp();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
   // List geolocations
   $view = tripal_natural_diversity_defaultview_admin_geolocations();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
   // List protocols
   $view = tripal_natural_diversity_defaultview_admin_protocols();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
   // List Reagents
   $view = tripal_natural_diversity_defaultview_admin_reagents();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
   return $views;

+ 1 - 0
tripal_organism/tripal_organism.views_default.inc

@@ -13,6 +13,7 @@ function tripal_organism_views_default_views() {
   $views = array();
 
   $view = tripal_organism_admin_defaultview_organisms();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
   return $views;

+ 1 - 0
tripal_phenotype/tripal_phenotype.views_default.inc

@@ -13,6 +13,7 @@ function tripal_phenotype_views_default_views() {
   $views = array();
 
   $view = tripal_phenotype_defaultview_admin_phenotypes();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
   return $views;

+ 1 - 0
tripal_project/tripal_project.views_default.inc

@@ -13,6 +13,7 @@ function tripal_project_views_default_views() {
   $views = array();
 
   $view = tripal_project_defaultview_admin_projects();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
   return $views;

+ 1 - 0
tripal_pub/tripal_pub.views_default.inc

@@ -14,6 +14,7 @@ function tripal_pub_views_default_views() {
 
   // Main default view
   $view = tripal_pub_defaultview_admin_publications();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
   return $views;

+ 1 - 0
tripal_stock/tripal_stock.views_default.inc

@@ -13,6 +13,7 @@ function tripal_stock_views_default_views() {
   $views = array();
 
   $view = tripal_stock_defaultview_admin_stocks();
+  $view = tripal_views_make_view_compatible_with_external($view);
   $views[$view->name] = $view;
 
   return $views;

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

@@ -281,6 +281,106 @@ function tripal_views_admin_disable_view($view_name, $redirect_link = FALSE) {
   }
 }
 
+/**
+ * Remove any drupal fields from a chado-based default view definition if chado is external.
+ * This ensures compatibility with an external chado database.
+ *
+ * You should be calling this function in your hook_views_default_views(). This function
+ * will only remove drupal tables if chado is external; thus you do not need to worry about
+ * checking yourself. For example, the following is a good hook_views_default_views():
+ * @code
+ function mymodule_views_default_views() {
+  $views = array();
+
+  // NOTE: <VIEW-TYPE> describes the type of view:
+  //     - 'admin' for views used for administration of your module
+  //     - 'search' for views used to search data
+  //     - 'list' for views used primarily as data listings
+
+  // <VIEW-HUMAN-READABLE-NAME>
+  $view = mymodule_defaultview_<VIEW-TYPE>_<VIEW-MACHINE-NAME>();
+  $view = tripal_views_make_view_compatible_with_external($view);
+  $views[$view->name] = $view;
+
+  // <VIEW-HUMAN-READABLE-NAME>
+  $view = mymodule_defaultview_<VIEW-TYPE>_<VIEW-MACHINE-NAME>();
+  $view = tripal_views_make_view_compatible_with_external($view);
+  $views[$view->name] = $view;
+
+  return $views;
+}
+
+function mymodule_defaultview_<VIEW-TYPE>_<VIEW-MACHINE-NAME>() {
+  // PASTE VIEWS EXPORT CODE HERE
+  return $view;
+}
+
+function mymodule_defaultview_<VIEW-TYPE>_<VIEW-MACHINE-NAME>() {
+  // PASTE VIEWS EXPORT CODE HERE
+  return $view;
+}
+ * @endcode
+ * Notice that the actual views export code is in a separate function. This makes your
+ * hook_views_default_views() more readable.
+ *
+ * NOTE: Currently assumes all tables not in the tripal views integration tables are Drupal tables.
+ *
+ * @param $view
+ *   The default view definition object
+ * @return
+ *   The default view with all relationships, fields, filters, sorts, arguements for
+ *   Drupal tables removed.
+ */
+function tripal_views_make_view_compatible_with_external($view) {
+  $remove_table = array();
+
+  // First check that the base table for the view is a chado table
+  // If it's not then don't do any filtering
+  $setup_id = tripal_views_is_integrated($view->base_table);
+  if (!$setup_id) {
+    return $view;
+  }
+
+  // IF chado is external then remove all config relating to drupal tables
+  if (!chado_is_local()) {
+
+    // Iterate through all displays
+    foreach ($view->display as $display_name => $display) {
+      $display_options = $display->handler->display->display_options;
+
+      $sections = array('fields', 'filters', 'sorts', 'relationships');
+      foreach ($sections as $section) {
+        $display_options[$section] = (isset($display_options[$section])) ? $display_options[$section] : array();
+        foreach ($display_options[$section] as $key => $defn) {
+          // If the table has not already been encountered; check if it's in tripal_views
+          if (!isset($remove_table[ $defn['table'] ])) {
+            // If the table is view then this is a general handler; thus keep
+            if ($defn['table'] == 'views') {
+              $remove_table[ $defn['table'] ] = FALSE;
+            }
+            // If this table is integrated then it is chado; thus keep
+            $setup_id = tripal_views_is_integrated($defn['table']);
+            if ($setup_id) {
+              $remove_table[ $defn['table'] ] = FALSE;
+            }
+            else {
+              $remove_table[ $defn['table'] ] = TRUE;
+            }
+          }
+
+          // Based on the $remove_table array, unset this field if its from a drupal table
+          if ($remove_table[ $defn['table'] ]) {
+            unset($view->display[$display_name]->handler->display->display_options[$section][$key]);
+          }
+        }
+      }
+
+    }
+  }
+
+  return $view;
+}
+
 /**
  * Retrieve the priority of the lightest priority for a given table.
  *