Kaynağa Gözat

Tripal: Added Relationship to Node for Feature

laceysanderson 13 yıl önce
ebeveyn
işleme
94e5d0e474

+ 26 - 0
tripal_feature/tripal_feature.views.inc

@@ -72,6 +72,32 @@ function tripal_feature_views_handlers() {
  );
 }
 
+/**
+ * Implementation of hook_views_data_alter().
+ */
+function tripal_feature_views_data_alter(&$data) {
+
+  if( !(is_array($db_url) and array_key_exists('chado',$db_url)) ){
+
+    // Add featuer relationship to node
+    $data['node']['feature_chado_nid'] = array(
+      'group' => 'Feature',
+      'title' => 'Feature Node',
+      'help' => 'Links Chado Feature Fields/Data to the Nodes in the current View.',
+      'real field' => 'nid',
+      'relationship' => array(
+        'handler' => 'views_handler_relationship',
+        'title' => t('Node => Chado'),
+        'label' => t('Node => Chado'),
+        'real field' => 'nid',
+        'base' => 'chado_feature',
+        'base field' => 'nid'
+      ),
+    );
+  }
+  
+}
+
 /**
  *
  * @ingroup tripal_feature_views

+ 33 - 1
tripal_feature/views/chado_feature.views.inc

@@ -45,7 +45,39 @@ function retrieve_chado_feature_views_data () {
   	'left_table' => 'chado_feature',
   	'left_field' => 'nid',
   	'field' => 'nid',
-  );  
+  );
+  
+  // Add relationship between chado_feature and feature
+  $data['chado_feature']['feature_nid'] = array(
+    'group' => 'Feature',
+    'title' => 'Feature Node',
+    'help' => 'Links Chado Feature Fields/Data to the Nodes in the current View.',
+    'real field' => 'feature_id',
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'title' => t('Chado => Feature'),
+      'label' => t('Chado => Feature'),
+      'real field' => 'feature_id',
+      'base' => 'feature',
+      'base field' => 'feature_id'
+    ),
+  );
 
+  // Add node relationship to feature
+  $data['chado_feature']['feature_chado_nid'] = array(
+    'group' => 'Feature',
+    'title' => 'Feature Node',
+    'help' => 'Links Chado Feature Fields/Data to the Nodes in the current View.',
+    'real field' => 'nid',
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'title' => t('Chado => Node'),
+      'label' => t('Chado => Node'),
+      'real field' => 'nid',
+      'base' => 'node',
+      'base field' => 'nid'
+    ),
+  );
+  
 	return $data;
 }

+ 26 - 1
tripal_feature/views/feature.views.inc

@@ -82,6 +82,14 @@
     'sort' => array(
      	'handler' => 'views_handler_sort',
     ),
+    'relationship' => array(
+      'handler' => 'views_handler_many2many_relationship',
+      'title' => t('Feature Node'),
+      'label' => t('Feature Node'),
+      'left' => 'node',
+      'left field' => 'nid',
+      'middle' => 'chado_feature',    
+    ),
   );
 
   // Calculated Field: Node ID
@@ -95,8 +103,25 @@
       	'handler' => 'views_handler_field_computed_feature_nid',
       ),
   	);
-  }
+  } else {
+    // Add relationship between chado_feature and feature
+    $data['feature']['feature_nid'] = array(
+      'group' => 'Feature',
+      'title' => 'Feature Node',
+      'help' => 'Links Chado Feature Fields/Data to the Nodes in the current View.',
+      'real field' => 'feature_id',
+      'relationship' => array(
+        'handler' => 'views_handler_relationship',
+        'title' => t('Feature => Chado'),
+        'label' => t('Feature => Chado'),
+        'real field' => 'feature_id',
+        'base' => 'chado_feature',
+        'base field' => 'feature_id'
+      ),
+    );
 
+  }
+  
   // Field: organism_id (forgeign key)
   //  join between organism table and this one in tripal_organism/views/organism.views.inc