Переглянути джерело

Tripal: Added Relationship to Node for Stocks

laceysanderson 13 роки тому
батько
коміт
2e98152343

+ 26 - 0
tripal_stock/tripal_stock.views.inc

@@ -96,6 +96,32 @@ function tripal_stock_views_handlers() {
  );
 }
 
+/**
+ * Implementation of hook_views_data_alter().
+ */
+function tripal_stock_views_data_alter(&$data) {
+
+  if( !(is_array($db_url) and array_key_exists('chado',$db_url)) ){
+
+    // Add featuer relationship to node
+    $data['node']['stock_chado_nid'] = array(
+      'group' => 'Stock',
+      'title' => 'Stock Node',
+      'help' => 'Links Chado Stock 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_stock',
+        'base field' => 'nid'
+      ),
+    );
+  }
+  
+}
+
 /**
  * Implements hook_views_pre_render
  *

+ 36 - 1
tripal_stock/views/chado_stock.views.inc

@@ -1,5 +1,7 @@
 <?php
 
+//module_load_include('inc','views', 'handlers/views_handler_relationship');
+
 /**
  * Purpose: this function returns the portion of the data array which describes the chado_stock 
  * drupal table, it's fields and any joins between it and other tables
@@ -24,7 +26,8 @@ function retrieve_chado_stock_views_data () {
 
   // Basic table definition
   $data['chado_stock']['table'] = array(
-    'field' => 'nid',
+    'field' => 'stock_id',
+    'group' => 'Chado Stock Node',
   );
   
   // Note: No joins need to be made from $data['stock']['table']
@@ -47,6 +50,38 @@ function retrieve_chado_stock_views_data () {
   	'left_field' => 'nid',
   	'field' => 'nid',
   );  
+  
+  // Add relationship between chado_stock and stock
+  $data['chado_stock']['stock_nid'] = array(
+    'group' => 'Stock',
+    'title' => 'Stock Node',
+    'help' => 'Links Chado Stock Fields/Data to the Nodes in the current View.',
+    'real field' => 'stock_id',
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'title' => t('Chado => Stock'),
+      'label' => t('Chado => Stock'),
+      'real field' => 'stock_id',
+      'base' => 'stock',
+      'base field' => 'stock_id'
+    ),
+  );
 
+  // Add node relationship to stock
+  $data['chado_stock']['stock_chado_nid'] = array(
+    'group' => 'Stock',
+    'title' => 'Stock Node',
+    'help' => 'Links Chado Stock 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;
 }

+ 17 - 0
tripal_stock/views/stock.views.inc

@@ -89,6 +89,23 @@ function retrieve_stock_views_data() {
        'handler' => 'views_handler_field_computed_stock_nid',
       ),
   	);
+  } else {
+    // Add relationship between chado_stock and stock
+    $data['stock']['stock_nid'] = array(
+      'group' => 'Stock',
+      'title' => 'Stock Node',
+      'help' => 'Links Chado Stock Fields/Data to the Nodes in the current View.',
+      'real field' => 'stock_id',
+      'relationship' => array(
+        'handler' => 'views_handler_relationship',
+        'title' => t('Stock => Chado'),
+        'label' => t('Stock => Chado'),
+        'real field' => 'stock_id',
+        'base' => 'chado_stock',
+        'base field' => 'stock_id'
+      ),
+    );
+
   }
 
   //Field: unique name (text)