Bläddra i källkod

Added relationship handler to all joins in case there are multiple joins to the same table -this way you can pick what field to join on

Lacey Sanderson 12 år sedan
förälder
incheckning
ceb848047d

+ 13 - 4
tripal_views/tripal_views.api.inc

@@ -155,7 +155,7 @@ function tripal_views_integration_add_entry($defn_array) {
 
     // Need to update the tripal_views record so base_table can be false
     // this is a fix because drupal_write_record() puts in defaults if !isset()
-    // and a variable is considered not set if its null!
+    // and a variable is considered not set if it's null!
     db_query(
       "UPDATE {tripal_views} SET base_table=%d WHERE table_name='%s' AND priority=%d",
       $defn_array['base_table'],
@@ -176,7 +176,7 @@ function tripal_views_integration_add_entry($defn_array) {
         $status = drupal_write_record('tripal_views_field', $field_record);
       }
       else {
-        drupal_set_message(t('Unable to integrate %name field due to a missing required fields.', array('%name' => $field['name'])), 'error');
+        drupal_set_message(t('Unable to integrate %name field due to missing required fields.', array('%name' => $field['name'])), 'error');
         $status = FALSE;
       }
 
@@ -248,7 +248,7 @@ function tripal_views_integration_add_entry($defn_array) {
 
       }
       else {
-        drupal_set_message(t('Unable to integrate field: %field_name', array('%field_name' => $field['name'])), 'error');
+        drupal_set_message(t('Unable to integrate %field_name field', array('%field_name' => $field['name'])), 'error');
         $no_errors = FALSE;
       }
     }
@@ -479,18 +479,27 @@ function tripal_views_get_integration_array_for_chado_table($table_name, $base_t
     }
   }
 
-  // Add Joins to fields
+  // Add Joins & Relationship Handlers to fields
   if (!isset($schema['foreign keys'])) {
     $schema['foreign keys'] = array();
     watchdog('tripal_views','There are no foreign keys defined for %table in the Chado Schema API.', array('%table' => $table_name), WATCHDOG_WARNING);
   }
   foreach ($schema['foreign keys'] as $foreign_key_schema) {
     foreach ($foreign_key_schema['columns'] as $left_field => $right_field) {
+      // Join
       $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'
       );
+
+      // Relationship Handler
+      $defn_array['fields'][$left_field]['handlers']['relationship'] = array(
+        'name' => 'chado_views_handler_relationship',
+        'base' => $foreign_key_schema['table'],
+        'base field' => $right_field,
+        'label' => $table_name . ' ' . $left_field . ' to ' . $foreign_key_schema['table'] . ' ' .$right_field
+      );
     }
   }
 

+ 27 - 0
tripal_views/views/handlers/chado_views_handler_relationship.inc

@@ -0,0 +1,27 @@
+<?php
+
+/**
+ * Simple relationship handler that allows a new version of the chado primary table
+ * to be linked in.
+ *
+ * The base relationship handler can only handle a single join. Some relationships
+ * are more complex and might require chains of joins; for those, you must
+ * utilize a custom relationship handler.
+ *
+ * Definition items:
+ * - base: The new base table this relationship will be adding. This does not
+ *   have to be a declared base table, but if there are no tables that
+ *   utilize this base table, it won't be very effective.
+ * - base field: The field to use in the relationship; if left out this will be
+ *   assumed to be the primary field.
+ * - relationship table: The actual table this relationship operates against.
+ *   This is analogous to using a 'table' override.
+ * - relationship field: The actual field this relationship operates against.
+ *   This is analogous to using a 'real field' override.
+ * - label: The default label to provide for this relationship, which is
+ *   shown in parentheses next to any field/sort/filter/argument that uses
+ *   the relationship.
+ */
+class chado_views_handler_relationship extends views_handler_relationship {
+
+}