Jelajahi Sumber

Added support for internal chado to views (including joining to node table) for organism, library, feature & analysis

laceysanderson 14 tahun lalu
induk
melakukan
733f3c597b

+ 2 - 0
tripal_analysis/tripal_analysis.views.inc

@@ -20,10 +20,12 @@
  *   relationships between that table and others (joins)
  *   relationships between that table and others (joins)
  */
  */
 require('views/analysis.views.inc');
 require('views/analysis.views.inc');
+require('views/chado_analysis.views.inc');
 function tripal_analysis_views_data()  {
 function tripal_analysis_views_data()  {
   $data = array();
   $data = array();
 
 
   $data = array_merge($data, retrieve_analysis_views_data());
   $data = array_merge($data, retrieve_analysis_views_data());
+  $data = array_merge($data, retrieve_chado_analysis_views_data());
 
 
   return $data;
   return $data;
 }
 }

+ 22 - 10
tripal_analysis/views/analysis.views.inc

@@ -27,15 +27,26 @@
  * @endcode
  * @endcode
  */
  */
 function retrieve_analysis_views_data() {
 function retrieve_analysis_views_data() {
-  
+	global $db_url;
+	$data = array();
+
+  // if the chado database is not local to the drupal database
+  // then we need to set the database name.  This should always
+  // be 'chado'.
+  if(is_array($db_url) and array_key_exists('chado',$db_url)){
+     $database = 'chado';
+  }
+	
   // Basic table definition
   // Basic table definition
   $data['analysis']['table']['group'] = 'Chado Analysis';
   $data['analysis']['table']['group'] = 'Chado Analysis';
  	$data['analysis']['table']['base'] = array(
  	$data['analysis']['table']['base'] = array(
  		'field' => 'analysis_id',
  		'field' => 'analysis_id',
  		'title' => t('Chado Analysis'),
  		'title' => t('Chado Analysis'),
  		'help' => t("An analysis is a particular type of a computational analysis; it may be a blast of one sequence against another, or an all by all blast, or a different kind of analysis altogether. It is a single unit of computation."),
  		'help' => t("An analysis is a particular type of a computational analysis; it may be a blast of one sequence against another, or an all by all blast, or a different kind of analysis altogether. It is a single unit of computation."),
- 		'database' => 'chado',
  	);
  	);
+  if($database){
+     $data['analysis']['table']['database'] = $database;
+  }
 
 
   // Define relationships between this table and others
   // Define relationships between this table and others
   $data['analysis']['table']['join'] = array(
   $data['analysis']['table']['join'] = array(
@@ -78,14 +89,15 @@ function retrieve_analysis_views_data() {
   // Calculated Field: Node ID
   // Calculated Field: Node ID
   //  use custom field handler to query drupal for the node ID
   //  use custom field handler to query drupal for the node ID
   //  this is only needed if chado is in a separate database from drupal
   //  this is only needed if chado is in a separate database from drupal
-	$data['analysis']['analysis_nid'] = array(
-	  'title' => 'Node ID',
-	  'help' => 'The node ID for the current analysis',
-	  'field' => array(
-	    'handler' => 'views_handler_field_computed_analysis_nid',
-	  ),
-	);
-	
+  if($database){
+		$data['analysis']['analysis_nid'] = array(
+	  	'title' => 'Node ID',
+	  	'help' => 'The node ID for the current analysis',
+	  	'field' => array(
+	    	'handler' => 'views_handler_field_computed_analysis_nid',
+	  	),
+		);
+	}	
 	// Field: name (varchar 255)
 	// Field: name (varchar 255)
  	$data['analysis']['name'] = array(
  	$data['analysis']['name'] = array(
     'title' => t('Name'),
     'title' => t('Name'),

+ 50 - 0
tripal_analysis/views/chado_analysis.views.inc

@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * Purpose: this function returns the portion of the data array 
+ *   which describes the chado_analysis drupal table, it's fields and any joins between it and other tables
+ * @see tripal_analysis_views_data() --in tripal_analysis.views.inc
+ *
+ * The main need for description of this table to views is to join chado data with drupal nodes
+ *
+ */
+function retrieve_chado_analysis_views_data () {
+	global $db_url;
+  $data = array();
+  
+  // if the chado database is not local to the drupal database
+  // then we need to set the database name.  This should always
+  // be 'chado'.
+  if(is_array($db_url) and array_key_exists('chado',$db_url)){
+     // return empty data array b/c if chado is external then no join to the nodetable can be made
+     return $data;
+  }
+
+  // Basic table definition
+  $data['chado_analysis']['table'] = array(
+    'field' => 'nid',
+  );
+  
+  // Note: No joins need to be made from $data['analysis']['table']
+  
+  // Join the chado analysis table to analysis
+  $data['chado_analysis']['table']['join']['analysis'] = array(
+  	'left_field' => 'analysis_id',
+  	'field' => 'analysis_id',
+  );
+  
+  // Join the node table to chado analysis
+  $data['node']['table']['join']['chado_analysis'] = array(
+  	'left_field' => 'nid',
+  	'field' => 'nid',
+  );
+  
+  // Join the node table to analysis
+  $data['node']['table']['join']['analysis'] = array(
+  	'left_table' => 'chado_analysis',
+  	'left_field' => 'nid',
+  	'field' => 'nid',
+  );  
+
+	return $data;
+}

+ 2 - 0
tripal_feature/tripal_feature.views.inc

@@ -21,10 +21,12 @@
  *   relationships between that table and others (joins)
  *   relationships between that table and others (joins)
  */
  */
 require_once('views/feature.views.inc');
 require_once('views/feature.views.inc');
+require_once('views/chado_feature.views.inc');
 function tripal_feature_views_data()  {
 function tripal_feature_views_data()  {
   $data = array();
   $data = array();
   
   
   $data = array_merge($data, retrieve_feature_views_data());
   $data = array_merge($data, retrieve_feature_views_data());
+  $data = array_merge($data, retrieve_chado_feature_views_data());
   
   
   return $data;
   return $data;
 }
 }

+ 50 - 0
tripal_feature/views/chado_feature.views.inc

@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * Purpose: this function returns the portion of the data array 
+ *   which describes the chado_feature drupal table, it's fields and any joins between it and other tables
+ * @see tripal_feature_views_data() --in tripal_feature.views.inc
+ *
+ * The main need for description of this table to views is to join chado data with drupal nodes
+ *
+ */
+function retrieve_chado_feature_views_data () {
+	global $db_url;
+  $data = array();
+  
+  // if the chado database is not local to the drupal database
+  // then we need to set the database name.  This should always
+  // be 'chado'.
+  if(is_array($db_url) and array_key_exists('chado',$db_url)){
+     // return empty data array b/c if chado is external then no join to the nodetable can be made
+     return $data;
+  }
+
+  // Basic table definition
+  $data['chado_feature']['table'] = array(
+    'field' => 'nid',
+  );
+  
+  // Note: No joins need to be made from $data['feature']['table']
+  
+  // Join the chado feature table to feature
+  $data['chado_feature']['table']['join']['feature'] = array(
+  	'left_field' => 'feature_id',
+  	'field' => 'feature_id',
+  );
+  
+  // Join the node table to chado feature
+  $data['node']['table']['join']['chado_feature'] = array(
+  	'left_field' => 'nid',
+  	'field' => 'nid',
+  );
+  
+  // Join the node table to feature
+  $data['node']['table']['join']['feature'] = array(
+  	'left_table' => 'chado_feature',
+  	'left_field' => 'nid',
+  	'field' => 'nid',
+  );  
+
+	return $data;
+}

+ 22 - 7
tripal_feature/views/feature.views.inc

@@ -34,15 +34,28 @@
  * @endcode
  * @endcode
  */
  */
  function retrieve_feature_views_data() {
  function retrieve_feature_views_data() {
+	global $db_url;
+	$data = array();
+	
+	// if the chado database is not local to the drupal database
+  // then we need to set the database name.  This should always
+  // be 'chado'.
+  if(is_array($db_url) and array_key_exists('chado',$db_url)){
+     $database = 'chado';
+  }
 
 
+	
   // Basic table definition
   // Basic table definition
   $data['feature']['table']['group'] = 'Chado Feature';
   $data['feature']['table']['group'] = 'Chado Feature';
   $data['feature']['table']['base'] = array(
   $data['feature']['table']['base'] = array(
     'field' => 'feature_id',
     'field' => 'feature_id',
     'title' => 'Chado Features',
     'title' => 'Chado Features',
     'help' => 'Features are Sequence Data Records in Chado.',
     'help' => 'Features are Sequence Data Records in Chado.',
-    'database' => 'chado'
   );
   );
+	if($database){
+		$data['feature']['table']['database'] = $database;
+	}
+
 
 
   // Table Field Definitions----------------------
   // Table Field Definitions----------------------
   // Field: feature_id (primary key)
   // Field: feature_id (primary key)
@@ -64,13 +77,15 @@
   // Calculated Field: Node ID
   // Calculated Field: Node ID
   //  use custom field handler to query drupal for the node ID
   //  use custom field handler to query drupal for the node ID
   //  this is only needed if chado is in a separate database from drupal
   //  this is only needed if chado is in a separate database from drupal
-  $data['feature']['feature_nid'] = array(
-    'title' => 'Node ID',
-    'help' => 'This is the node ID of this feature. It can be used as a link to the node.',
-    'field' => array(
-      'handler' => 'views_handler_field_computed_feature_nid',
+  if($database){
+  	$data['feature']['feature_nid'] = array(
+    	'title' => 'Node ID',
+			'help' => 'This is the node ID of this feature. It can be used as a link to the node.',
+    	'field' => array(
+      	'handler' => 'views_handler_field_computed_feature_nid',
       ),
       ),
-  );
+  	);
+  }
 
 
   // Field: organism_id (forgeign key)
   // Field: organism_id (forgeign key)
   //  join between organism table and this one in tripal_organism/views/organism.views.inc
   //  join between organism table and this one in tripal_organism/views/organism.views.inc

+ 2 - 0
tripal_library/tripal_library.views.inc

@@ -20,10 +20,12 @@
  *   relationships between that table and others (joins)
  *   relationships between that table and others (joins)
  */
  */
 require_once('views/library.views.inc');
 require_once('views/library.views.inc');
+require_once('views/chado_library.views.inc');
 function tripal_library_views_data()  {
 function tripal_library_views_data()  {
   $data = array();
   $data = array();
   
   
   $data = array_merge($data, retrieve_library_views_data());
   $data = array_merge($data, retrieve_library_views_data());
+  $data = array_merge($data, retrieve_chado_library_views_data());
   
   
   return $data;
   return $data;
 }
 }

+ 50 - 0
tripal_library/views/chado_library.views.inc

@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * Purpose: this function returns the portion of the data array 
+ *   which describes the chado_library drupal table, it's fields and any joins between it and other tables
+ * @see tripal_library_views_data() --in tripal_library.views.inc
+ *
+ * The main need for description of this table to views is to join chado data with drupal nodes
+ *
+ */
+function retrieve_chado_library_views_data () {
+	global $db_url;
+  $data = array();
+  
+  // if the chado database is not local to the drupal database
+  // then we need to set the database name.  This should always
+  // be 'chado'.
+  if(is_array($db_url) and array_key_exists('chado',$db_url)){
+     // return empty data array b/c if chado is external then no join to the nodetable can be made
+     return $data;
+  }
+
+  // Basic table definition
+  $data['chado_library']['table'] = array(
+    'field' => 'nid',
+  );
+  
+  // Note: No joins need to be made from $data['library']['table']
+  
+  // Join the chado library table to library
+  $data['chado_library']['table']['join']['library'] = array(
+  	'left_field' => 'library_id',
+  	'field' => 'library_id',
+  );
+  
+  // Join the node table to chado library
+  $data['node']['table']['join']['chado_library'] = array(
+  	'left_field' => 'nid',
+  	'field' => 'nid',
+  );
+  
+  // Join the node table to library
+  $data['node']['table']['join']['library'] = array(
+  	'left_table' => 'chado_library',
+  	'left_field' => 'nid',
+  	'field' => 'nid',
+  );  
+
+	return $data;
+}

+ 21 - 8
tripal_library/views/library.views.inc

@@ -27,6 +27,15 @@
  * @endcode
  * @endcode
  */
  */
 function retrieve_library_views_data() {
 function retrieve_library_views_data() {
+	global $db_url;
+  $data = array();
+
+  // if the chado database is not local to the drupal database
+  // then we need to set the database name.  This should always
+  // be 'chado'.
+  if(is_array($db_url) and array_key_exists('chado',$db_url)){
+     $database = 'chado';
+  }
   
   
   // Basic table definition
   // Basic table definition
 	$data['library']['table']['group'] = 'Chado Library';
 	$data['library']['table']['group'] = 'Chado Library';
@@ -34,8 +43,10 @@ function retrieve_library_views_data() {
 	  'field' => 'library_id',
 	  'field' => 'library_id',
 	  'title' => 'Chado Library',
 	  'title' => 'Chado Library',
 	  'help' => 'Library existing in the Chado Database',                                                                                                                                                                          
 	  'help' => 'Library existing in the Chado Database',                                                                                                                                                                          
-	  'database' => 'chado'
 	);
 	);
+	if($database){
+	  $data['library']['table']['database'] = $database;
+	}
 	
 	
 	// Define relationships between this table and others
 	// Define relationships between this table and others
   $data['library']['table']['join'] = array(
   $data['library']['table']['join'] = array(
@@ -78,13 +89,15 @@ function retrieve_library_views_data() {
   // Calculated Field: Node ID
   // Calculated Field: Node ID
   //  use custom field handler to query drupal for the node ID
   //  use custom field handler to query drupal for the node ID
   //  this is only needed if chado is in a separate database from drupal
   //  this is only needed if chado is in a separate database from drupal
-	$data['library']['library_nid'] = array(
-	  'title' => 'Node ID',
-	  'help' => 'The node ID for the current library',
-	  'field' => array(
-	    'handler' => 'views_handler_field_computed_library_nid',
-	  ),
-	);
+  if($database){
+		$data['library']['library_nid'] = array(
+	  	'title' => 'Node ID',
+	  	'help' => 'The node ID for the current library',
+	  	'field' => array(
+	    	'handler' => 'views_handler_field_computed_library_nid',
+	  	),
+		);
+	}
 	
 	
 	// Field: organism_id (forgeign key)
 	// Field: organism_id (forgeign key)
   //  join between organism table and this one in tripal_organism/views/organism.views.inc
   //  join between organism table and this one in tripal_organism/views/organism.views.inc

+ 2 - 0
tripal_organism/tripal_organism.views.inc

@@ -20,10 +20,12 @@
  *   relationships between that table and others (joins)
  *   relationships between that table and others (joins)
  */
  */
 require_once('views/organism.views.inc');
 require_once('views/organism.views.inc');
+require_once('views/chado_organism.views.inc');
 function tripal_organism_views_data()  {
 function tripal_organism_views_data()  {
   $data = array();
   $data = array();
   
   
   $data = array_merge($data, retrieve_organism_views_data());
   $data = array_merge($data, retrieve_organism_views_data());
+  $data = array_merge($data, retrieve_chado_organism_views_data());
   
   
   return $data;
   return $data;
 }
 }

+ 50 - 0
tripal_organism/views/chado_organism.views.inc

@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * Purpose: this function returns the portion of the data array 
+ *   which describes the chado_organism drupal table, it's fields and any joins between it and other tables
+ * @see tripal_organism_views_data() --in tripal_organism.views.inc
+ *
+ * The main need for description of this table to views is to join chado data with drupal nodes
+ *
+ */
+function retrieve_chado_organism_views_data () {
+	global $db_url;
+  $data = array();
+  
+  // if the chado database is not local to the drupal database
+  // then we need to set the database name.  This should always
+  // be 'chado'.
+  if(is_array($db_url) and array_key_exists('chado',$db_url)){
+     // return empty data array b/c if chado is external then no join to the nodetable can be made
+     return $data;
+  }
+
+  // Basic table definition
+  $data['chado_organism']['table'] = array(
+    'field' => 'nid',
+  );
+  
+  // Note: No joins need to be made from $data['organism']['table']
+  
+  // Join the chado organism table to organism
+  $data['chado_organism']['table']['join']['organism'] = array(
+  	'left_field' => 'organism_id',
+  	'field' => 'organism_id',
+  );
+  
+  // Join the node table to chado organism
+  $data['node']['table']['join']['chado_organism'] = array(
+  	'left_field' => 'nid',
+  	'field' => 'nid',
+  );
+  
+  // Join the node table to organism
+  $data['node']['table']['join']['organism'] = array(
+  	'left_table' => 'chado_organism',
+  	'left_field' => 'nid',
+  	'field' => 'nid',
+  );  
+
+	return $data;
+}

+ 23 - 9
tripal_organism/views/organism.views.inc

@@ -23,15 +23,27 @@
  * @endcode
  * @endcode
  */
  */
 function retrieve_organism_views_data() {
 function retrieve_organism_views_data() {
+	global $db_url;
+	$data = array();
+	
+	// if the chado database is not local to the drupal database
+  // then we need to set the database name.  This should always
+  // be 'chado'.
+  if(is_array($db_url) and array_key_exists('chado',$db_url)){
+     $database = 'chado';
+  }
 
 
+	
   // Basic table definition
   // Basic table definition
   $data['organism']['table']['group'] = 'Chado Organism';
   $data['organism']['table']['group'] = 'Chado Organism';
   $data['organism']['table']['base'] = array(
   $data['organism']['table']['base'] = array(
     'field' => 'organism_id',
     'field' => 'organism_id',
     'title' => 'Chado Organism',
     'title' => 'Chado Organism',
     'help' => 'Organisms existing in the Chado Database',                                                                                                                                                                          
     'help' => 'Organisms existing in the Chado Database',                                                                                                                                                                          
-    'database' => 'chado'
   );
   );
+  if($database){
+     $data['organism']['table']['database'] = $database;
+  }
 
 
   // Define relationships between this table and others
   // Define relationships between this table and others
   $data['organism']['table']['join'] = array(
   $data['organism']['table']['join'] = array(
@@ -72,14 +84,16 @@ function retrieve_organism_views_data() {
   // Calculated Field: Node ID
   // Calculated Field: Node ID
   //  use custom field handler to query drupal for the node ID
   //  use custom field handler to query drupal for the node ID
   //  this is only needed if chado is in a separate database from drupal
   //  this is only needed if chado is in a separate database from drupal
-  $data['organism']['organism_nid'] = array(
-    'title' => 'Node ID',
-    'help' => 'This is the node ID of this organism. It can be used as a link to the node.',
-    'field' => array(
-      'handler' => 'views_handler_field_computed_organism_nid',
-    ),    
-  );
-
+  if($database){
+	  $data['organism']['organism_nid'] = array(
+  	  'title' => 'Node ID',
+    	'help' => 'This is the node ID of this organism. It can be used as a link to the node.',
+    	'field' => array(
+      	'handler' => 'views_handler_field_computed_organism_nid',
+    	),    
+  	);
+	}
+	
   // Field: abbreviation (varchar 255)
   // Field: abbreviation (varchar 255)
   $data['organism']['abbreviation'] = array(
   $data['organism']['abbreviation'] = array(
     'title' => 'Abbreviation',
     'title' => 'Abbreviation',