Browse Source

Merged 6.x-0.4-dev into this branch with the Drupal coding standard changes

laceysanderson 13 years ago
parent
commit
b50a8979ae
97 changed files with 971 additions and 8133 deletions
  1. 27 12
      tripal_analysis/tripal_analysis.views.inc
  2. 0 45
      tripal_analysis/views/README
  3. 0 331
      tripal_analysis/views/analysis.views.inc
  4. 0 100
      tripal_analysis/views/chado_analysis.views.inc
  5. 0 23
      tripal_analysis/views/handlers/views_handler_field_computed_analysis_nid.inc
  6. 0 37
      tripal_analysis/views/misc_tables.views.inc
  7. 0 84
      tripal_analysis/views/template.node_join.views.inc
  8. 0 211
      tripal_analysis/views/template.table_defn.views.inc
  9. 22 1
      tripal_contact/tripal_contact.views.inc
  10. 0 45
      tripal_contact/views/README
  11. 0 84
      tripal_contact/views/template.node_join.views.inc
  12. 0 211
      tripal_contact/views/template.table_defn.views.inc
  13. 27 8
      tripal_cv/tripal_cv.views.inc
  14. 0 93
      tripal_cv/views/cv.views.inc
  15. 0 156
      tripal_cv/views/cvterm.views.inc
  16. 27 6
      tripal_db/tripal_db.views.inc
  17. 0 151
      tripal_db/views/db.views.inc
  18. 0 150
      tripal_db/views/dbxref.views.inc
  19. 2 1
      tripal_feature/tripal_feature.api.inc
  20. 50 19
      tripal_feature/tripal_feature.views.inc
  21. 0 45
      tripal_feature/views/README
  22. 0 99
      tripal_feature/views/chado_feature.views.inc
  23. 0 294
      tripal_feature/views/feature.views.inc
  24. 0 23
      tripal_feature/views/handlers/views_handler_field_computed_feature_nid.inc
  25. 0 60
      tripal_feature/views/misc_tables.views.inc
  26. 0 84
      tripal_feature/views/template.node_join.views.inc
  27. 0 211
      tripal_feature/views/template.table_defn.views.inc
  28. 0 0
      tripal_feature/views_handlers/views_handler_field_residues.inc
  29. 31 7
      tripal_genetic/tripal_genetic.views.inc
  30. 0 45
      tripal_genetic/views/README
  31. 0 180
      tripal_genetic/views/genotype.views.inc
  32. 0 84
      tripal_genetic/views/template.node_join.views.inc
  33. 0 211
      tripal_genetic/views/template.table_defn.views.inc
  34. 33 14
      tripal_library/tripal_library.views.inc
  35. 0 45
      tripal_library/views/README
  36. 0 99
      tripal_library/views/chado_library.views.inc
  37. 0 17
      tripal_library/views/handlers/views_handler_field_computed_library_nid.inc
  38. 0 216
      tripal_library/views/library.views.inc
  39. 0 49
      tripal_library/views/misc_tables.views.inc
  40. 0 84
      tripal_library/views/template.node_join.views.inc
  41. 0 211
      tripal_library/views/template.table_defn.views.inc
  42. 45 23
      tripal_natural_diversity/tripal_natural_diversity.views.inc
  43. 0 45
      tripal_natural_diversity/views/README
  44. 0 182
      tripal_natural_diversity/views/nd_experiment.views.inc
  45. 0 127
      tripal_natural_diversity/views/nd_experimentprop.views.inc
  46. 0 161
      tripal_natural_diversity/views/nd_geolocation.views.inc
  47. 0 127
      tripal_natural_diversity/views/nd_geolocationprop.views.inc
  48. 0 121
      tripal_natural_diversity/views/nd_reagent.views.inc
  49. 0 125
      tripal_natural_diversity/views/nd_reagentprop.views.inc
  50. 0 84
      tripal_natural_diversity/views/template.node_join.views.inc
  51. 0 211
      tripal_natural_diversity/views/template.table_defn.views.inc
  52. 32 12
      tripal_organism/tripal_organism.views.inc
  53. 0 45
      tripal_organism/views/README
  54. 0 99
      tripal_organism/views/chado_organism.views.inc
  55. 0 17
      tripal_organism/views/handlers/views_handler_field_computed_organism_nid.inc
  56. 0 230
      tripal_organism/views/organism.views.inc
  57. 0 84
      tripal_organism/views/template.node_join.views.inc
  58. 0 211
      tripal_organism/views/template.table_defn.views.inc
  59. 23 0
      tripal_phenotype/tripal_phenotype.views.inc
  60. 0 45
      tripal_phenotype/views/README
  61. 0 84
      tripal_phenotype/views/template.node_join.views.inc
  62. 0 211
      tripal_phenotype/views/template.table_defn.views.inc
  63. 25 9
      tripal_project/tripal_project.views.inc
  64. 0 45
      tripal_project/views/README
  65. 0 98
      tripal_project/views/chado_project.views.inc
  66. 0 251
      tripal_project/views/project.views.inc
  67. 0 84
      tripal_project/views/template.node_join.views.inc
  68. 0 211
      tripal_project/views/template.table_defn.views.inc
  69. 25 0
      tripal_pub/tripal_pub.views.inc
  70. 0 45
      tripal_pub/views/README
  71. 0 84
      tripal_pub/views/template.node_join.views.inc
  72. 0 211
      tripal_pub/views/template.table_defn.views.inc
  73. 31 6
      tripal_stock/tripal_stock.views.inc
  74. 0 45
      tripal_stock/views/README
  75. 0 102
      tripal_stock/views/chado_stock.views.inc
  76. 0 37
      tripal_stock/views/misc_tables.views.inc
  77. 0 290
      tripal_stock/views/stock.views.inc
  78. 0 84
      tripal_stock/views/template.node_join.views.inc
  79. 0 211
      tripal_stock/views/template.table_defn.views.inc
  80. 160 7
      tripal_views/tripal_views.api.inc
  81. 8 4
      tripal_views/tripal_views.install
  82. 69 50
      tripal_views/tripal_views.views.inc
  83. 157 86
      tripal_views/tripal_views_integration.inc
  84. 0 0
      tripal_views/views/handlers/views_handler_argument_stockprop_id.inc
  85. 0 0
      tripal_views/views/handlers/views_handler_field_chado_relationship_all.inc
  86. 0 0
      tripal_views/views/handlers/views_handler_field_chado_relationship_by_type.inc
  87. 0 0
      tripal_views/views/handlers/views_handler_field_computed_stock_nid.inc
  88. 0 0
      tripal_views/views/handlers/views_handler_field_stock_dbxref_all.inc
  89. 0 0
      tripal_views/views/handlers/views_handler_field_stock_dbxref_by_type.inc
  90. 0 0
      tripal_views/views/handlers/views_handler_field_stockprop_all.inc
  91. 0 0
      tripal_views/views/handlers/views_handler_field_stockprop_by_type.inc
  92. 0 0
      tripal_views/views/handlers/views_handler_field_stockrel_all.inc
  93. 0 0
      tripal_views/views/handlers/views_handler_field_stockrel_by_type.inc
  94. 0 0
      tripal_views/views/handlers/views_handler_filter_stock_dbxref_id.inc
  95. 0 0
      tripal_views/views/handlers/views_handler_filter_stock_relationship_id.inc
  96. 0 0
      tripal_views/views/handlers/views_handler_filter_stockprop_id.inc
  97. 177 83
      tripal_views/views/handlers/views_handler_join_chado_aggregator.inc

+ 27 - 12
tripal_analysis/tripal_analysis.views.inc

@@ -6,7 +6,7 @@
  *  chado/tripal analysis tables. Supplementary functions can be found in
  *  ./views/
  *
- *  Documentation on views integration can be found at 
+ *  Documentation on views integration can be found at
  *  http://views2.logrus.com/doc/html/index.html.
  */
 
@@ -16,9 +16,6 @@
  * @ingroup tripal_analysis
  */
 
-require('views/analysis.views.inc');
-require('views/chado_analysis.views.inc');
-require('views/misc_tables.views.inc'); 
 /**
  * Implements hook_views_data()
  *
@@ -26,7 +23,7 @@ require('views/misc_tables.views.inc');
  *
  * @return: a data array which follows the structure outlined in the
  *   views2 documentation for this hook. Essentially, it's an array of table
- *   definitions keyed by chado/tripal table name. Each table definition 
+ *   definitions keyed by chado/tripal table name. Each table definition
  *   includes basic details about the table, fields in that table and
  *   relationships between that table and others (joins)
  *
@@ -35,9 +32,27 @@ require('views/misc_tables.views.inc');
 function tripal_analysis_views_data()  {
   $data = array();
 
-  $data = array_merge($data, retrieve_analysis_views_data());
-  $data = array_merge($data, retrieve_chado_analysis_views_data());
-  $data = array_merge($data, retrieve_analysis_misc_tables_views_data());
+  if (module_exists('tripal_views')) {
+		// Base Table: Analysis
+		$tablename = 'analysis';
+		if (!tripal_views_is_integrated($tablename, 10)) {
+			$table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
+			tripal_views_integration_add_entry($table_integration_array);
+		}
+
+
+    $tables = array(
+      'analysisfeature',
+      'analysisprop'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+
+  }
 
   return $data;
 }
@@ -46,7 +61,7 @@ function tripal_analysis_views_data()  {
  * Implements hook_views_handlers()
  *
  * Purpose: Register all custom handlers with views
- *   where a handler describes either "the type of field", 
+ *   where a handler describes either "the type of field",
  *   "how a field should be filtered", "how a field should be sorted"
  *
  * @return
@@ -93,7 +108,7 @@ function tripal_analysis_views_data_alter(&$data) {
       ),
     );
   }
-  
+
 }
 
 /**
@@ -103,7 +118,7 @@ function tripal_analysis_views_data_alter(&$data) {
  */
 function tripal_analysis_views_default_views () {
   $views = array();
-  
+
   // Main default view
   // List all cvterms based on cv
   $view = new view;
@@ -541,6 +556,6 @@ function tripal_analysis_views_default_views () {
     'name' => 'navigation',
   ));
   $views[$view->name] = $view;
-  
+
   return $views;
 }

+ 0 - 45
tripal_analysis/views/README

@@ -1,45 +0,0 @@
-
-This directory contains all additional views code needed to integrate this module with views2.
-
-FILE/FOLDER DESCRIPTIONS
----------------------------
-<chado table name>.views.inc:
-	contains a single function retrieve_<chado table name>_views_data()
-	which describes that table to views. This function is called by
-	tripal_analysis_views_data() in ../tripal_analysis.views.inc.
-	For more information on the form of this data array look up the
-	views2 documentation for hook_views_data() 
-	-http://views2.logrus.com/doc/html/index.html
-	
-handlers/
-	Each file contained within this folder defines a views handler. Only custom
-	handlers are included in this folder and each must be described in 
-	hook_views_handlers() in ../tripal_analysis.views.inc.
-	A views handler does one of the following:
-		1) describe the type of a field and how it should be displayed
-		2) describe a method to sort this field
-		3) describe a method to filter this field
-
-
-STANDARDS TO FOLLOW
----------------------------
-
-1. All table definition files should be named tablename.views.inc
-2. All handlers should be in a handlers sub-directory and follow the naming convention of
-   views handlers (ie: views_handler_field/filter/sort_handlername.inc )
-
-Views Table Definitions:
-- Please use the template files provided whenever you are describing a new table to views.
-   For any table in chado simply copy template.table_defn.views.inc to tablename.views.inc and 
-   follow the instructions listed at the top of the template file.
-- ONLY ONE TABLE DEFINITION PER FILE
-- To join a chado table to it's drupal node simply copy template.node_join.views.inc to 
-   basetablename.views.inc and replace all XXX with basetablename.
-   
-   NOTE: Creating the table definition file is not enough. You also need to call the 
-         retrieve_XXX_views_data() function from ../tripal_analysis.views.inc:tripal_analysis_views_data()
-         by adding the following line:
-            $data = array_merge($data, retrieve_XXX_views_data());
-         to the function and including the file directly above the function (blow the function 
-         header by adding:
-            require_once('views/XXX.views.inc');

+ 0 - 331
tripal_analysis/views/analysis.views.inc

@@ -1,331 +0,0 @@
-<?php
-	/**
- * Purpose: this function returns the portion of the data array 
- *   which describes the analysis table, it's fields and any joins between it and other tables
- * @see tripal_analysis_views_data() --in tripal_analysis.views.inc
- *
- * @todo Add support for analysisprop table
- * @todo Add support for multiple analysis' listed per feature
- * @todo Add join to node table within if <chado/drupal same db>; also addd if not around nid field
- *
- * BASE TABLE: analysis
- * @code
- *   create table analysis (
- *       analysis_id serial not null,
- *       primary key (analysis_id),
- *       name varchar(255),
- *       description text,
- *       program varchar(255) not null,
- *       programversion varchar(255) not null,
- *       algorithm varchar(255),
- *       sourcename varchar(255),
- *       sourceversion varchar(255),
- *       sourceuri text,
- *       timeexecuted timestamp not null default current_timestamp,
- *       constraint analysis_c1 unique (program,programversion,sourcename)
- *   );
- * @endcode
- *
- * @ingroup tripal_analysis_views
- */
-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
-  $data['analysis']['table']['group'] = 'Chado Analysis';
- 	$data['analysis']['table']['base'] = array(
- 		'field' => 'analysis_id',
- 		'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."),
- 	);
-  if($database){
-     $data['analysis']['table']['base']['database'] = $database;
-  }
-
-  // Define relationships between this table and others
-  $data['analysis']['table']['join']['feature'] = array(
-    'linking' => array(
-      'table' => 'analysisfeature',
-      'left_field' => 'feature_id',
-      'field' => 'analysis_id',
-    ),
-    'left_field' => 'feature_id',
-    'field' => 'analysis_id',
-    'handler' => 'views_handler_join_chado_through_linking'
-  );
-
-  // Analysis properties?
- 	$data['analysisprop']['table'] = array(
-'group' => 'Chado analysis Properties',
- 		'field' => 'analysisprop_id',
- 		'title' => t('Chado analysis Properties'),
- 		'help' => '  ',
- 	);
- 	
- 	$data['analysisprop']['table']['join']['analysis'] = array(
-    'left_field' => 'analysis_id',
-    'field' => 'analysis_id',
-    'handler' => 'views_handler_join_chado_aggregator'
- 	);
- 	
- 	$data['analysisprop']['value'] = array(
-    'title' => t('Value'),
-    'help' => t(' '),
-    'field' => array(
-      'handler' => 'chado_views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'chado_views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'chado_views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
- 	);
- 	
- 	$data['analysisprop']['all'] = array(
-    'title' => t('All'),
-    'help' => t('An aggregate field that contains all fields for a row.'),
-    'field' => array(
-      'handler' => 'chado_views_handler_field_aggregate',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'chado_views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'chado_views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
- 	);
- 	
-	// Table Field Definitions----------------------
-	// Field: analysis_id (primary key)
-	$data['analysis']['analysis_id'] = array(
-	  'title' => 'analysis ID',
-	  'help' => 'The primary key of the analysis table.',
-	  'field' => array(
-	    'handler' => 'views_handler_field_numeric',
-	    'click sortable' => TRUE,
-	  ),
-	  'filter' => array(
-	    'handler' => 'views_handler_filter_numeric',
-	  ),
-	  'sort' => array(
-	    'handler' => 'chado_views_handler_sort',
-	  ),
-	);
-	
-  // Calculated Field: 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
-  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',
-	  	),
-		);
-  } else {
-    // Add relationship between chado_analysis and analysis
-    $data['analysis']['analysis_nid'] = array(
-      'group' => 'Analysis',
-      'title' => 'Analysis Node',
-      'help' => 'Links Chado Analysis Fields/Data to the Nodes in the current View.',
-      'real field' => 'analysis_id',
-      'relationship' => array(
-        'handler' => 'views_handler_relationship',
-        'title' => t('Analysis => Chado'),
-        'label' => t('Analysis => Chado'),
-        'real field' => 'analysis_id',
-        'base' => 'chado_analysis',
-        'base field' => 'analysis_id'
-      ),
-    );
-
-  }
-	
-	// Field: name (varchar 255)
- 	$data['analysis']['name'] = array(
-    'title' => t('Name'),
-    'help' => t(''),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'chado_views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_chado_select_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-  // if joined to the node table add a "Link to Node" option for the field  
-  if (!$database) {
-    $data['analysis']['name']['field']['handler'] = 'views_handler_field_node_optional';
-  }
-
-  // Field: description (text)
- 	$data['analysis']['description'] = array(
-    'title' => t('Description'),
-    'help' => t(''),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'chado_views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'chado_views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  // Field: program (varchar 255)
- 	$data['analysis']['program'] = array(
-    'title' => t('Program'),
-    'help' => t('Program name, e.g. blastx, blastp, sim4, genscan.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'chado_views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_chado_select_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  // Field: program version (varchar 255)
- 	$data['analysis']['programversion'] = array(
-    'title' => t('Program Version'),
-    'help' => t('Version description, e.g. TBLASTX 2.0MP-WashU [09-Nov-2000].'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'chado_views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_chado_select_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  // Field: algorithm (varchar 255)
- 	$data['analysis']['algorithm'] = array(
-    'title' => t('Algorithm'),
-    'help' => t('Algorithm name, e.g. blast.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'chado_views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_chado_select_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
- 	$data['analysis']['sourcename'] = array(
-    'title' => t('Source Name'),
-    'help' => t('Source name, e.g. cDNA, SwissProt.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'chado_views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'chado_views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  // Field: source version (varchar 255)
- 	$data['analysis']['sourceversion'] = array(
-    'title' => t('Source Version'),
-    'help' => t('The version of the source.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'chado_views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'chado_views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  // Field: source URI/URL (text)
- 	$data['analysis']['sourceuri'] = array(
-    'title' => t('Source URL'),
-    'help' => t('This is an optional, permanent URL or URI for the source of the analysis.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'chado_views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'chado_views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  // Field: time executed (datetime)
- 	$data['analysis']['timeexecuted'] = array(
-    'title' => 'Time Executed',
-    'help' => 'The date & time when this analysis was executed.',
-    'field' => array(
-      'handler' => 'views_handler_field_readable_date',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'chado_views_handler_sort_date',
-    ),
-  );
-
- 	return $data;
-}

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

@@ -1,100 +0,0 @@
-<?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
- *
- *
- * @ingroup tripal_analysis_views
- */
-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',
-    'group' => 'Chado Analysis'
-  );
-
-  $data['chado_analysis']['nid'] = array(
-    'title' => t('Analysis Node ID'),
-    'help' => t('The node ID for this analysis'),
-    'field' => array(
-     	'handler' => 'views_handler_field_numeric',
- 		  'click sortable' => TRUE,
-    ),
-    'filter' => array(
-     	'handler' => 'views_handler_filter_numeric',
-    ),
-    'sort' => array(
-     	'handler' => 'views_handler_sort',
-    ),
-  );
-  
-  // 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',
-  );  
-
-  // Add relationship between chado_analysis and analysis
-  $data['chado_analysis']['analysis_nid'] = array(
-    'group' => 'Analysis',
-    'title' => 'Analysis Node',
-    'help' => 'Links Chado Analysis Fields/Data to the Nodes in the current View.',
-    'real field' => 'analysis_id',
-    'relationship' => array(
-      'handler' => 'views_handler_relationship',
-      'title' => t('Chado => Analysis'),
-      'label' => t('Chado => Analysis'),
-      'real field' => 'analysis_id',
-      'base' => 'analysis',
-      'base field' => 'analysis_id'
-    ),
-  );
-
-  // Add node relationship to analysis
-  $data['chado_analysis']['analysis_chado_nid'] = array(
-    'group' => 'Analysis',
-    'title' => 'Analysis Node',
-    'help' => 'Links Chado Analysis 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;
-}

+ 0 - 23
tripal_analysis/views/handlers/views_handler_field_computed_analysis_nid.inc

@@ -1,23 +0,0 @@
-<?php
-
-/**
- *
- *
- * @ingroup tripal_analysis
- */
-class views_handler_field_computed_analysis_nid extends views_handler_field_numeric {
-	function construct() {
-		parent::construct();
-		drupal_set_message('Computed Analysis NID Handler loaded');
-		$this->additional_fields['analysis_id'] = array('table' => 'analysis', 'field' => 'analysis_id');
-	}
-
-	function query() { 
-		$this->ensure_my_table();
-		$this->add_additional_fields(); 
-	}
-
-	function render($values) { 
-		return $values->analysis_nid;
-	}
-} 

+ 0 - 37
tripal_analysis/views/misc_tables.views.inc

@@ -1,37 +0,0 @@
-<?php
-
-/**
- * Purpose: Allows the analysis module to add fields to other module views
- *
- *   For example, a field counting the number of analysis' associted with a given feature would be
- *   added to the feature view as follows:
- *   @code
-      $data['feature']['num_analysis''] = array(
-        'title' => "Number of analysis'",
-        'help' => "Provides a count of the number of analysis' associated with a given feature",
-        'field' => array(
-          'handler' => 'views_handler_field_chado_count',
-          'table_to_query' => 'analysis_feature',
-        ),
-      ); 
- *   @endcode
- *
- * @ingroup tripal_analysis_views
- */
-function retrieve_analysis_misc_tables_views_data() {
-  $data = array();
- 
-  // Table: Feature---------------------------------------------------------------------------------
-  // Calculated Field: Number of analysis' (Count -Int)
-  // Provides the number of analysis' for a given feature
-  $data['feature']['num_analysis'] = array(
-    'title' => "Number of analysis'",
-    'help' => "Provides a count of the number of analysis' associated with a given feature",
-    'field' => array(
-      'handler' => 'views_handler_field_chado_count',
-      'table_to_query' => 'analysisfeature',
-    ),
-  );  
-  
-  return $data;
-}

+ 0 - 84
tripal_analysis/views/template.node_join.views.inc

@@ -1,84 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *  - simply replace all XXX with the original chado table you want to join to it's drupal nodes.
- *    (ie: If you want to join features to their drupal nodes then XXX=feature)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_analysis.views.inc in 
- *        tripal_analysis_views_data() by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_analysis.views.inc --in tripal_analysis_views_data()
- *
- *  Note: All chado tables are joined to their drupal nodes through the chado_XXX linking table. 
- *        This file simply defines this linking table and joins the three tables together.
- *        No modification of XXX.views.inc is needed.
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
- 
-/**
- * Purpose: this function returns the portion of the data array 
- *   which describes the chado_XXX 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_XXX_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_XXX']['table'] = array(
-    'field' => 'nid',
-  );
-  
-  //Relationship Definitions---------------------------------
-  // Note: No joins need to be made from $data['XXX']['table']
-  
-  // Join the chado_XXX table to XXX
-  $data['chado_XXX']['table']['join']['XXX'] = array(
-  	'left_field' => 'XXX_id',
-  	'field' => 'XXX_id',
-  );
-  
-  // Join the node table to chado_XXX
-  $data['node']['table']['join']['chado_XXX'] = array(
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );
-  
-  // Join the node table to XXX
-  $data['node']['table']['join']['XXX'] = array(
-  	'left_table' => 'chado_XXX',
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );  
-
-	return $data;
-}

+ 0 - 211
tripal_analysis/views/template.table_defn.views.inc

@@ -1,211 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *   - Every instance of XXX should be replaced with the name of your table
- *   - If this is a base table (you want a view where every row is a row from this table)
- *     then change $data['XXX']['table'] to $data['XXX']['table']['base'] 
- *     and $data['XXX']['table']['database'] to $data['XXX']['table']['base']['database']
- *   - Relationships between this table and others: YYY is the table you are trying to join to this
- *     one. You want to join a table to this one if this table contains a foreign key to the other
- *     table. If the join between this table and another is through a linking table
- *     (ie: library-XXX/YYY => library_feature-XY => feature-XXX/YYY) then make the join in both
- *     directions (ie: in the file XXX.views.inc and the file YYY.views.inc
- *   - Create a field definition for each field in this table using the example fields already
- *     listed. Match the type of the database field to the field definition listed below.
- *     (ie: for a text/varchar field from the database use plain_text_field below)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_analysis.views.inc in 
- *        tripal_analysis_views_data() by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_analysis.views.inc --in tripal_analysis_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the XXX table, it's fields and any joins between it and other tables
- * @see tripal_analysis_views_data() --in tripal_analysis.views.inc
- *
- * Table: XXX
- * @code
- * XXX-Copy/Paste Table SQL code here-XXX
- * @endcode
- */
- function retrieve_XXX_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-----------------------------------
-  $data['XXX']['table']['group'] = t('Chado XXX');
-  
-  $data['XXX']['table'] = array(
-    'field' => 'primary_id',
-    'title' => t('Chado XXX'),
-    'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
-  );
-  if($database){
-     $data['XXX']['table']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: YYY => XXX
-  // Notice that this relationship tells the primary table to show it's fields to the
-  // table referencing it by a foreign key and thus the relationship is from
-  // primary table to table referenceing it (ie: cvterm => feature)
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_field' => 'foreign key in YYY table',
-    'field' => 'primary key in XXX table',
-  );  
-  
-  //Join: XXX => XY => YYY
-  // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
-  // describe in both feature.views.inc and library.views.inc)
-  $data['XXX']['table']['join']['XY'] = array(
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );  
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_table' => 'XY',
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );
-  $data['XY']['table']['join']['YYY'] = array(
-    'left_field' => 'primary key in YYY table',
-    'field' => 'matching YYY key in the XY table',
-  );
-   
-  //Table Field Definitions----------------------------------
-      
-  //Field: XXX_id (primary key)
-  $data['XXX']['field_name'] = array(
-    'title' => t('XXX Primary Key'),
-    'help' => t('A unique index for every XXX.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  /*.......................................................
-   * Beginning of Example Field definitions
-   * Remove this section when done
-   */
-
-  //Field: plain_text_field (chado datatype)   
-  $data['XXX']['plain_text_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: numeric_field (chado datatype)   
-  $data['XXX']['numeric_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: boolean_field (chado datatype)   
-  $data['XXX']['boolean_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_boolean',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_boolean_operator',
-    ),
-  );
-
-  //Field: unix_timestamp (chado datatype)   
-  $data['XXX']['unix_timestamp'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_date',
-    ),
-  );
-
-  //Field: human_readable_date (chado datatype)   
-  $data['XXX']['human_readable_date'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_readble_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-  );
-   
-   /*
-    * End of Example Field definitions
-    */
-    
-  return $data;
-}

+ 22 - 1
tripal_contact/tripal_contact.views.inc

@@ -24,7 +24,28 @@
  */
 function tripal_contact_views_data()  {
   $data = array();
-  
+
+  if (module_exists('tripal_views')) {
+    
+    // Base Table: contact
+    $table_name = 'contact';
+    if (!tripal_views_is_integrated($tablename, 10)) {
+      $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE);
+      tripal_views_integration_add_entry($table_integration_array);
+    }
+      
+    // Additional tables
+    $tables = array(
+      'contact_relationship',
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+  }
+    
   return $data;
 }
 

+ 0 - 45
tripal_contact/views/README

@@ -1,45 +0,0 @@
-
-This directory contains all additional views code needed to integrate this module with views2.
-
-FILE/FOLDER DESCRIPTIONS
----------------------------
-<chado table name>.views.inc:
-	contains a single function retrieve_<chado table name>_views_data()
-	which describes that table to views. This function is called by
-	tripal_contact_views_data() in ../tripal_contact.views.inc.
-	For more information on the form of this data array look up the
-	views2 documentation for hook_views_data() 
-	-http://views2.logrus.com/doc/html/index.html
-	
-handlers/
-	Each file contained within this folder defines a views handler. Only custom
-	handlers are included in this folder and each must be described in 
-	hook_views_handlers() in ../tripal_contact.views.inc.
-	A views handler does one of the following:
-		1) describe the type of a field and how it should be displayed
-		2) describe a method to sort this field
-		3) describe a method to filter this field
-
-
-STANDARDS TO FOLLOW
----------------------------
-
-1. All table definition files should be named tablename.views.inc
-2. All handlers should be in a handlers sub-directory and follow the naming convention of
-   views handlers (ie: views_handler_field/filter/sort_handlername.inc )
-
-Views Table Definitions:
-- Please use the template files provided whenever you are describing a new table to views.
-   For any table in chado simply copy template.table_defn.views.inc to tablename.views.inc and 
-   follow the instructions listed at the top of the template file.
-- ONLY ONE TABLE DEFINITION PER FILE
-- To join a chado table to it's drupal node simply copy template.node_join.views.inc to 
-   basetablename.views.inc and replace all XXX with basetablename.
-   
-   NOTE: Creating the table definition file is not enough. You also need to call the 
-         retrieve_XXX_views_data() function from ../tripal_contact.views.inc:tripal_contact_views_data()
-         by adding the following line:
-            $data = array_merge($data, retrieve_XXX_views_data());
-         to the function and including the file directly above the function (blow the function 
-         header by adding:
-            require_once('views/XXX.views.inc');

+ 0 - 84
tripal_contact/views/template.node_join.views.inc

@@ -1,84 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *  - simply replace all XXX with the original chado table you want to join to it's drupal nodes.
- *    (ie: If you want to join features to their drupal nodes then XXX=feature)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_contact.views.inc:tripal_contact_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_contact.views.inc --in tripal_contact_views_data()
- *
- *  Note: All chado tables are joined to their drupal nodes through the chado_XXX linking table. 
- *        This file simply defines this linking table and joins the three tables together.
- *        No modification of XXX.views.inc is needed.
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
- 
-/**
- * Purpose: this function returns the portion of the data array 
- *   which describes the chado_XXX drupal table, it's fields and any joins between it 
- *   and other tables
- * @see tripal_contact_views_data() --in tripal_contact.views.inc
- *
- * The main need for description of this table to views is to join chado data with drupal nodes
- *
- */
-function retrieve_chado_XXX_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_XXX']['table'] = array(
-    'field' => 'nid',
-  );
-  
-  //Relationship Definitions---------------------------------
-  // Note: No joins need to be made from $data['XXX']['table']
-  
-  // Join the chado_XXX table to XXX
-  $data['chado_XXX']['table']['join']['XXX'] = array(
-  	'left_field' => 'XXX_id',
-  	'field' => 'XXX_id',
-  );
-  
-  // Join the node table to chado_XXX
-  $data['node']['table']['join']['chado_XXX'] = array(
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );
-  
-  // Join the node table to XXX
-  $data['node']['table']['join']['XXX'] = array(
-  	'left_table' => 'chado_XXX',
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );  
-
-	return $data;
-}

+ 0 - 211
tripal_contact/views/template.table_defn.views.inc

@@ -1,211 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *   - Every instance of XXX should be replaced with the name of your table
- *   - If this is a base table (you want a view where every row is a row from this table)
- *     then change $data['XXX']['table'] to $data['XXX']['table']['base'] 
- *     and $data['XXX']['table']['database'] to $data['XXX']['table']['base']['database']
- *   - Relationships between this table and others: YYY is the table you are trying to join to this
- *     one. You want to join a table to this one if this table contains a foreign key to the other
- *     table. If the join between this table and another is through a linking table
- *     (ie: library-XXX/YYY => library_feature-XY => feature-XXX/YYY) then make the join in both
- *     directions (ie: in the file XXX.views.inc and the file YYY.views.inc
- *   - Create a field definition for each field in this table using the example fields already
- *     listed. Match the type of the database field to the field definition listed below.
- *     (ie: for a text/varchar field from the database use plain_text_field below)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_contact.views.inc:tripal_contact_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_contact.views.inc --in tripal_contact_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the XXX table, it's fields and any joins between it and other tables
- * @see tripal_contact_views_data() --in tripal_contact.views.inc
- *
- * Table: XXX
- * @code
- * XXX-Copy/Paste Table SQL code here-XXX
- * @endcode
- */
- function retrieve_XXX_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-----------------------------------
-  $data['XXX']['table']['group'] = t('Chado XXX');
-  
-  $data['XXX']['table'] = array(
-    'field' => 'primary_id',
-    'title' => t('Chado XXX'),
-    'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
-  );
-  if($database){
-     $data['XXX']['table']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: YYY => XXX
-  // Notice that this relationship tells the primary table to show it's fields to the
-  // table referencing it by a foreign key and thus the relationship is from
-  // primary table to table referenceing it (ie: cvterm => feature)
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_field' => 'foreign key in YYY table',
-    'field' => 'primary key in XXX table',
-  );  
-  
-  //Join: XXX => XY => YYY
-  // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
-  // describe in both feature.views.inc and library.views.inc)
-  $data['XXX']['table']['join']['XY'] = array(
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );  
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_table' => 'XY',
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );
-  $data['XY']['table']['join']['YYY'] = array(
-    'left_field' => 'primary key in YYY table',
-    'field' => 'matching YYY key in the XY table',
-  );
-   
-  //Table Field Definitions----------------------------------
-      
-  //Field: XXX_id (primary key)
-  $data['XXX']['field_name'] = array(
-    'title' => t('XXX Primary Key'),
-    'help' => t('A unique index for every XXX.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  /*.......................................................
-   * Beginning of Example Field definitions
-   * Remove this section when done
-   */
-
-  //Field: plain_text_field (chado datatype)   
-  $data['XXX']['plain_text_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: numeric_field (chado datatype)   
-  $data['XXX']['numeric_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: boolean_field (chado datatype)   
-  $data['XXX']['boolean_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_boolean',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_boolean_operator',
-    ),
-  );
-
-  //Field: unix_timestamp (chado datatype)   
-  $data['XXX']['unix_timestamp'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_date',
-    ),
-  );
-
-  //Field: human_readable_date (chado datatype)   
-  $data['XXX']['human_readable_date'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_readble_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-  );
-   
-   /*
-    * End of Example Field definitions
-    */
-    
-  return $data;
-}

+ 27 - 8
tripal_cv/tripal_cv.views.inc

@@ -16,8 +16,6 @@
  * @ingroup tripal_cv
  */
 
-require_once('views/cvterm.views.inc');
-require_once('views/cv.views.inc');
 /**
  * Implements hook_views_data()
  *
@@ -35,13 +33,34 @@ require_once('views/cv.views.inc');
 function tripal_cv_views_data() {
   $data = array();
 
-  //Function is contained in includes/cvterm.views.inc
-  //Returns the data array for the chado cvterm table
-  $data = array_merge($data, retrieve_cvterm_views_data());
+  if (module_exists('tripal_views')) {
+    // Base Tables
+    $tables = array(
+      'cv',
+      'cvterm'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
 
-  //Function is contained in includes/cv.views.inc
-  //Returns the data array for the chado cv table
-  $data = array_merge($data, retrieve_cv_views_data());
+    // Additional Tables
+    $tables = array(
+      'cvterm_dbxref',
+      'cvterm_relationship',
+      'cvtermpath',
+      'cvtermprop',
+      'cvtermsynonym'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+  }
 
   return $data;
 }

+ 0 - 93
tripal_cv/views/cv.views.inc

@@ -1,93 +0,0 @@
-<?php
-
-/**
- * Prupose: this function returns a portion of the data array
- *   which describes the cv table, it's fields and any joins between it and other tables
- * @see tripal_cv_views_data()
- *
- * TABLE: cv
- * @code
- *   create table cv (
- *       cv_id serial not null,
- *       primary key (cv_id),
- *       name varchar(255) not null,
- *       definition text,
- *       constraint cv_c1 unique (name)
- *   );
- * @endcode
- *
- * @ingroup tripal_cv_views
- */
-function retrieve_cv_views_data() {
-$data = array();
-
-// Basic table definition
-$data['cv']['table'] = array(
-'field' => 'cv_id',
-'title' => 'Chado CV (Controlled Vocabulary)',
-'group' => 'Chado CV',
-'help' => 'Controlled vocabularies existing in the Chado Database',
-'database' => 'chado'
-);
-
-// Define relationships between this table and others
-$data['cv']['table']['join'] = array(
-'cvterm' => array(
-'left_field' => 'cv_id',
-'field' => 'cv_id',
-),
-);
-
-// Table Field Definitions----------------------
-// Field: cv_id (primary key)
-$data['cv']['cv_id'] = array(
-'title' => t('CV ID'),
-'help' => t('The primary key of the controlled vocabulary.'),
-'field' => array(
-'handler' => 'views_handler_field_numeric',
-'click sortable' => TRUE,
-),
-'filter' => array(
-'handler' => 'views_handler_filter_numeric',
-),
-'sort' => array(
-'handler' => 'views_handler_sort',
-),
-);
-
-//Field: name (varchar -255)
-$data['cv']['name'] = array(
-'title' => 'Vocabulary Name',
-'field' => array(
-'handler' => 'views_handler_field',
-'click sortable' => TRUE,
-),
-'sort' => array(
-'handler' => 'views_handler_sort',
-),
-'filter' => array(
-'handler' => 'views_handler_filter_chado_select_string',
-),
-'argument' => array(
-'handler' => 'views_handler_argument_string',
-),
-);
-
-//Field: definition (text)
-$data['cv']['definition'] = array(
-'title' => 'Vocabulary Definition',
-'field' => array(
-'handler' => 'views_handler_field',
-'click sortable' => TRUE,
-),
-'filter' => array(
-'handler' => 'views_handler_filter_string',
-),
-'argument' => array(
-'handler' => 'views_handler_argument_string',
-),
-);
-
-return $data;
-
-}

+ 0 - 156
tripal_cv/views/cvterm.views.inc

@@ -1,156 +0,0 @@
-<?php
-
-/**
- * @file
- * Purpose: this function returns the portion of the data array
- *   which describes the cv table, it's fields and any joins between it and other tables
- * @see tripal_cv_views_data()
- *
- * BASE TABLE: cvterm
- * @code
- *   create table cvterm (
- *       cvterm_id serial not null,
- *       primary key (cvterm_id),
- *       cv_id int not null,
- *       foreign key (cv_id) references cv (cv_id) on delete cascade INITIALLY DEFERRED,
- *       name varchar(1024) not null,
- *       definition text,
- *       dbxref_id int not null,
- *       foreign key (dbxref_id) references dbxref (dbxref_id) on delete set null INITIALLY DEFERRED,
- *       is_obsolete int not null default 0,
- *       is_relationshiptype int not null default 0,
- *       constraint cvterm_c1 unique (name,cv_id,is_obsolete),
- *       constraint cvterm_c2 unique (dbxref_id)
- *   );
- * @endcode
- *
- * @ingroup tripal_cv_views
- */
-function retrieve_cvterm_views_data() {
-
-// Basic table definition
-$data['cvterm']['table']['group'] = 'Chado CV Terms';
-$data['cvterm']['table']['base'] = array(
-'field' => 'cvterm_id',
-'title' => 'Chado CV Terms (Controlled Vocabulary)',
-'help' => 'Controlled Vocabularies (CVs) are the main way Chado controls content.',
-'database' => 'chado'
-);
-
-// Define relationships between this table and others
-$data['cvterm']['table']['join'] = array(
-'feature' => array(
-'left_field' => 'type_id',
-'field' => 'cvterm_id',
-),
-'library' => array(
-'left_field' => 'type_id',
-'field' => 'cvterm_id',
-),
-'stock' => array(
-'left_field' => 'type_id',
-'field' => 'cvterm_id',
-),
-'nd_reagent' => array(
-'left_field' => 'type_id',
-'field' => 'cvterm_id',
-),
-);
-
-// Table Field Definitions----------------------
-// Field: cvterm_id (primary key)
-$data['cvterm']['cvterm_id'] = array(
-'title' => t('CV Term ID'),
-'help' => t('The primary kep of controlled vocabulary terms.'),
-'field' => array(
-'handler' => 'views_handler_field_numeric',
-'click sortable' => TRUE,
-),
-'filter' => array(
-'handler' => 'views_handler_filter_numeric',
-),
-'sort' => array(
-'handler' => 'views_handler_sort',
-),
-);
-
-//Field: cv_id (foreign key: cv)
-//  join between cv table and this one in cv.views.inc
-
-// Field: Name (varchar 1024)
-$data['cvterm']['name'] = array(
-'title' => 'Name',
-'help' => 'The term name',
-'field' => array(
-'handler' => 'views_handler_field',
-'click sortable' => TRUE,
-),
-'sort' => array(
-'handler' => 'views_handler_sort',
-),
-'filter' => array(
-'handler' => 'views_handler_filter_string',
-),
-'argument' => array(
-'handler' => 'views_handler_argument_string',
-),
-);
-
-// Field: Definition (text)
-$data['cvterm']['definition'] = array(
-'title' => 'Definition',
-'help' => 'A definition of this term',
-'field' => array(
-'handler' => 'views_handler_field',
-'click sortable' => TRUE,
-),
-'filter' => array(
-'handler' => 'views_handler_filter_string',
-),
-'argument' => array(
-'handler' => 'views_handler_argument_string',
-),
-);
-
-// Field: dbxref_id (foreign key: dbxref)
-//  join between dbxref table and this one in tripal_db/views/dbxref.views.inc
-
-// Field: is_obsolete (integer: 1/0)
-$data['cvterm']['is_obsolete'] = array(
-'title' => 'Is Obsolete',
-'help' => 'Whether this term is obsolete or not.',
-'field' => array(
-'handler' => 'views_handler_field_boolean',
-'click sortable' => TRUE,
-),
-'filter' => array(
-'handler' => 'views_handler_filter_string',
-'label' => t('Is Obsolete?'),
-'type' => 'yes-no',
-),
-'sort' => array(
-'handler' => 'views_handler_sort',
-),
-);
-
-// Field: is_relationshiptype (integer: 1/0)
-$data['cvterm']['is_relationshiptype'] = array(
-'title' => 'Is Relationship',
-'help' => 'Whether this term describes a relationship or not.',
-'field' => array(
-'handler' => 'views_handler_field_boolean',
-'click sortable' => TRUE,
-),
-'filter' => array(
-'handler' => 'views_handler_filter_chado_boolean',
-'label' => t('Is Relationship Type?'),
-'type' => 'yes-no',
-),
-'sort' => array(
-'handler' => 'views_handler_sort',
-),
-);
-
-return $data;
-
-}

+ 27 - 6
tripal_db/tripal_db.views.inc

@@ -16,8 +16,6 @@
  * @ingroup tripal_db
  */
 
-require_once('views/dbxref.views.inc');
-require_once('views/db.views.inc');
 /**
  * Implements hook_views_data()
  * Purpose: Describe chado/tripal tables & fields to views
@@ -30,11 +28,34 @@ require_once('views/db.views.inc');
  * @ingroup tripal_db_views
  */
 function tripal_db_views_data()  {
+  $data = array();
 
-   $data = array();
-   $data = array_merge($data, retrieve_dbxref_views_data());
-   $data = array_merge($data, retrieve_db_views_data());
-   return $data;
+  if (module_exists('tripal_views')) {
+    // Base Tables
+    $tables = array(
+      'db',
+      'dbxref'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+
+    // Additional Tables
+    $tables = array(
+      'dbxrefprop'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+  }
+
+  return $data;
 
 }
 

+ 0 - 151
tripal_db/views/db.views.inc

@@ -1,151 +0,0 @@
-<?php
-
-  /**
- * @file
- * Purpose: this function returns the portion of the data array
- *   which describes the cv table, it's fields and any joins between it and other tables
- * @see tripal_cv_views_data() --in tripal_cv.views.inc
- *
- *  TABLE: db
- * @code
- * create table db (
- *    db_id serial not null,
- *    primary key (db_id),
- *    name varchar(255) not null,
- *    description varchar(255) null,
- *    urlprefix varchar(255) null,
- *    url varchar(255) null,
- *    constraint db_c1 unique (name)
- * );
- * @endcode
- *
- * @ingroup tripal_db_views
- */
-function retrieve_db_views_data() {
-
-  // Basic table definition
-  $data['db']['table'] = array(
-    'field' => 'db_id',
-    'group' => 'Chado Database',
-    'title' => 'Chado Database',
-    'help' => 'Database Records existing in the Chado Database',
-    'database' => 'chado'
-  );
-
-  // Define relationships between this table and others
-  $data['db']['table']['join'] = array(
-    'dbxref' => array(
-      'left_field' => 'db_id',
-      'field' => 'db_id',
-    ),
-    'stock' => array(
-      'left_table' => 'dbxref',
-      'left_field' => 'db_id',
-      'field' => 'db_id',
-    ),
-    'cvterm' => array(
-      'left_table' => 'dbxref',
-      'left_field' => 'db_id',
-      'field' => 'db_id',
-    ),
-    'feature' => array(
-      'left_table' => 'dbxref',
-      'left_field' => 'db_id',
-      'field' => 'db_id',
-    ),
-  );
-
-  // Table Field Definitions----------------------
-  // Field: db_id (primary key)
-  $data['db']['db_id'] = array(
-    'title' => t('Database ID'),
-    'help' => t('The primary key of the Database.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-  );
-
-  // Field: name (varchar 255)
-  $data['db']['name'] = array(
-    'title' => 'Name',
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_chado_select_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  // Field: description (varchar 255)
-  $data['db']['description'] = array(
-    'title' => 'Description',
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  // Field: urlprefix (varchar 255)
-  $data['db']['urlprefix'] = array(
-    'title' => 'URL Prefix',
-    'help' => 'The url that when concatenated with the accession of a record in this db produces the url to the record in this database.',
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  // Field: url (varchar 255)
-  $data['db']['url'] = array(
-    'title' => 'URL',
-    'help' => 'The url to the main page of the database',
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  return $data;
-
-}

+ 0 - 150
tripal_db/views/dbxref.views.inc

@@ -1,150 +0,0 @@
-<?php
-
-/**
- * @file
- * Purpose: this function returns the portion of the data array
- *   which describes the db table, it's fields and any joins between it and other tables
- * @see tripal_db_views_data() --in tripal_db.views.inc
- *
- * BASE TABLE: dbxref
- * @code
- * create table dbxref (
- *    dbxref_id serial not null,
- *    primary key (dbxref_id),
- *    db_id int not null,
- *    foreign key (db_id) references db (db_id) on delete cascade INITIALLY DEFERRED,
- *    accession varchar(255) not null,
- *    version varchar(255) not null default '',
- *    description text,
- *    constraint dbxref_c1 unique (db_id,accession,version)
- * );
- * @endcode
- *
- * @ingroup tripal_db_views
- */
-function retrieve_dbxref_views_data() {
-
-  // Basic table definition
-  $data['dbxref']['table']['group'] = 'Chado Database Reference';
-  $data['dbxref']['table']['base'] = array(
-    'field' => 'dbxref_id',
-    'title' => 'Chado Database Reference',
-    'help' => 'A Reference to another database. Allows easy linking between becords in one database to those in another.',
-    'database' => 'chado'
-  );
-
-  // Define relationships between this table and others
-  $data['dbxref']['table']['join'] = array(
-    'cvterm' => array(
-      'left_field' => 'dbxref_id',
-      'field' => 'dbxref_id',
-    ),
-    'feature' => array(
-      'left_field' => 'dbxref_id',
-      'field' => 'dbxref_id',
-    ),
-    'stock' => array(
-      'left_field' => 'dbxref_id',
-      'field' => 'dbxref_id',
-    ),
-  );
-
-  // Table Field Definitions----------------------
-  // Field: dbxref_id (primary key)
-  $data['dbxref']['dbxref_id'] = array(
-    'title' => t('Database Reference ID'),
-    'help' => t('The primary key of Database References.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-  );
-
-  //Field: cv_id (foreign key: cv)
-  //  join between cv table and this one in cv.views.inc
-
-  // Field: accession (varchar 255)
-  $data['dbxref']['accession'] = array(
-    'title' => 'Accession',
-    'help' => 'The accession from the database.',
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  // Field: version (varchar 255)
-  $data['dbxref']['version'] = array(
-    'title' => 'Version',
-    'help' => 'The version of the database reference.',
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  // Field: description (text)
-  $data['dbxref']['description'] = array(
-    'title' => 'Description',
-    'help' => 'a description of the database reference.',
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  // Calculated Field: Accession Link
-  //  uses custom field handler to pull db urlprefix and concatenate with accession
-  //  solves the problem of not being able to add urlprefix to tables which only
-  //  join to dbxref table (not db)
-  $data['dbxref']['accession_link'] = array(
-    'title' => 'Accession Link',
-    'help' => 'Provides a link to the record in the external database.',
-    'field' => array(
-      'handler' => 'views_handler_field_dbxref_accession_link',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  return $data;
-
-}

+ 2 - 1
tripal_feature/tripal_feature.api.inc

@@ -212,7 +212,7 @@ function tripal_feature_chado_feature_cvterm_schema() {
   $description['foreign keys']['cvterm'] = array(
         'table' => 'cvterm',
         'columns' => array(
-          'type_id' => 'cvterm_id',
+          'cvterm_id' => 'cvterm_id',
         ),
   );
   $description['foreign keys']['pub'] = array(
@@ -221,6 +221,7 @@ function tripal_feature_chado_feature_cvterm_schema() {
           'pub_id' => 'pub_id',
         ),
   );
+  
   return $description;
 }
 /**

+ 50 - 19
tripal_feature/tripal_feature.views.inc

@@ -6,7 +6,7 @@
  *  chado/tripal organism tables. Supplementary functions can be found in
  *  ./views/
  *
- *  Documentation on views integration can be found at 
+ *  Documentation on views integration can be found at
  *  http://views2.logrus.com/doc/html/index.html.
  */
 
@@ -15,7 +15,7 @@
  * @ingroup views
  * @ingroup tripal_feature
  */
- 
+
 /**
  * Implements hook_views_data()
  *
@@ -23,22 +23,56 @@
  *
  * @return: a data array which follows the structure outlined in the
  *   views2 documentation for this hook. Essentially, it's an array of table
- *   definitions keyed by chado/tripal table name. Each table definition 
+ *   definitions keyed by chado/tripal table name. Each table definition
  *   includes basic details about the table, fields in that table and
  *   relationships between that table and others (joins)
  *
  * @ingroup tripal_feature_views
  */
-require_once('views/feature.views.inc');
-require_once('views/chado_feature.views.inc');
-require_once('views/misc_tables.views.inc');
 function tripal_feature_views_data()  {
   $data = array();
-  
-  $data = array_merge($data, retrieve_feature_views_data());
-  $data = array_merge($data, retrieve_chado_feature_views_data());
-  $data = array_merge($data, retrieve_feature_misc_tables_views_data());
-  
+
+  if (module_exists('tripal_views')) {
+    $tables = array(
+      'feature',
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+
+    $tables = array(
+      'feature_cvterm',
+      'feature_cvterm_dbxref',
+      'feature_cvterm_pub',
+      'feature_cvtermprop',
+      'feature_dbxref',
+      'feature_pub',
+      'feature_pubprop',
+      'feature_relationship',
+      'feature_relationship_pub',
+      'feature_relationshipprop',
+      'feature_relationshipprop_pub',
+      'feature_synonym',
+      'featureloc',
+      'featureloc_pub',
+      'featureprop',
+      'featureprop_pub',
+      'featuremap',
+      'featuremap_pub',
+      'featurepos',
+      'featurerange'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+  }
+
   return $data;
 }
 
@@ -46,7 +80,7 @@ function tripal_feature_views_data()  {
  * Implements hook_views_handlers()
  *
  * Purpose: Register all custom handlers with views
- *   where a handler describes either "the type of field", 
+ *   where a handler describes either "the type of field",
  *   "how a field should be filtered", "how a field should be sorted"
  *
  * @return: An array of handler definitions
@@ -56,12 +90,9 @@ function tripal_feature_views_data()  {
 function tripal_feature_views_handlers() {
  return array(
    'info' => array(
-     'path' => drupal_get_path('module', 'tripal_feature') . '/views/handlers',
+     'path' => drupal_get_path('module', 'tripal_feature') . '/views_handlers',
    ),
    'handlers' => array(
-     'views_handler_field_computed_feature_nid' => array(
-       'parent' => 'views_handler_field_numeric',
-     ),
      'views_handler_field_residues' => array(
        'parent' => 'views_handler_field',
      ),
@@ -92,7 +123,7 @@ function tripal_feature_views_data_alter(&$data) {
       ),
     );
   }
-  
+
 }
 
 /**
@@ -101,7 +132,7 @@ function tripal_feature_views_data_alter(&$data) {
  */
 function tripal_feature_views_default_views () {
   $views = array();
-  
+
   // Main default view
   // List all cvterms based on cv
   $view = new view;
@@ -431,6 +462,6 @@ function tripal_feature_views_default_views () {
     'name' => 'navigation',
   ));
   $views[$view->name] = $view;
-  
+
   return $views;
 }

+ 0 - 45
tripal_feature/views/README

@@ -1,45 +0,0 @@
-
-This directory contains all additional views code needed to integrate this module with views2.
-
-FILE/FOLDER DESCRIPTIONS
----------------------------
-<chado table name>.views.inc:
-	contains a single function retrieve_<chado table name>_views_data()
-	which describes that table to views. This function is called by
-	tripal_feature_views_data() in ../tripal_feature.views.inc.
-	For more information on the form of this data array look up the
-	views2 documentation for hook_views_data() 
-	-http://views2.logrus.com/doc/html/index.html
-	
-handlers/
-	Each file contained within this folder defines a views handler. Only custom
-	handlers are included in this folder and each must be described in 
-	hook_views_handlers() in ../tripal_feature.views.inc.
-	A views handler does one of the following:
-		1) describe the type of a field and how it should be displayed
-		2) describe a method to sort this field
-		3) describe a method to filter this field
-
-
-STANDARDS TO FOLLOW
----------------------------
-
-1. All table definition files should be named tablename.views.inc
-2. All handlers should be in a handlers sub-directory and follow the naming convention of
-   views handlers (ie: views_handler_field/filter/sort_handlername.inc )
-
-Views Table Definitions:
-- Please use the template files provided whenever you are describing a new table to views.
-   For any table in chado simply copy template.table_defn.views.inc to tablename.views.inc and 
-   follow the instructions listed at the top of the template file.
-- ONLY ONE TABLE DEFINITION PER FILE
-- To join a chado table to it's drupal node simply copy template.node_join.views.inc to 
-   basetablename.views.inc and replace all XXX with basetablename.
-   
-   NOTE: Creating the table definition file is not enough. You also need to call the 
-         retrieve_XXX_views_data() function from ../tripal_feature.views.inc:tripal_feature_views_data()
-         by adding the following line:
-            $data = array_merge($data, retrieve_XXX_views_data());
-         to the function and including the file directly above the function (blow the function 
-         header by adding:
-            require_once('views/XXX.views.inc');

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

@@ -1,99 +0,0 @@
-<?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
- *
- * @ingroup tripal_feature_views
- */
-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',
-    'group' => 'Chado Feature'
-  );
-  
-  $data['chado_feature']['nid'] = array(
-    'title' => t('Feature Node ID'),
-    'help' => t('The node ID for this feature'),
-    'field' => array(
-     	'handler' => 'views_handler_field_numeric',
- 		  'click sortable' => TRUE,
-    ),
-    'filter' => array(
-     	'handler' => 'views_handler_filter_numeric',
-    ),
-    'sort' => array(
-     	'handler' => 'views_handler_sort',
-    ),
-  );
-
-  // 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',
-  );
-  
-  // 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;
-}

+ 0 - 294
tripal_feature/views/feature.views.inc

@@ -1,294 +0,0 @@
-<?php
-
-/**
- * Purpose: this function returns the portion of the data array 
- *   which describes the feature table, it's fields and any joins between it and other tables
- * @see tripal_feature_views_data() --in tripal_feature.views.inc
- *
- * @todo Add better handler for is_analysis, is_obsolete: something which changes the t/f to a true boolean
- * @todo Add support for the following tables: featureprop, featureloc, featurepos, feature_synonym, feature_relationship
- * @todo Add join to node table within if <chado/drupal same db>; also addd if not around nid field
- *
- * BASE TABLE: feature
- * @code
- *   create table feature (
- *        feature_id serial not null,
- *        primary key (feature_id),
- *        dbxref_id int,
- *        foreign key (dbxref_id) references dbxref (dbxref_id) on delete set null INITIALLY DEFERRED,
- *        organism_id int not null,
- *        foreign key (organism_id) references organism (organism_id) on delete cascade INITIALLY DEFERRED,
- *        name varchar(255),
- *        uniquename text not null,
- *        residues text,
- *        seqlen int,
- *        md5checksum char(32),
- *        type_id int not null,
- *        foreign key (type_id) references cvterm (cvterm_id) on delete cascade INITIALLY DEFERRED,
- *        is_analysis boolean not null default 'false',
- *        is_obsolete boolean not null default 'false',
- *        timeaccessioned timestamp not null default current_timestamp,
- *        timelastmodified timestamp not null default current_timestamp,
- *        constraint feature_c1 unique (organism_id,uniquename,type_id)
- *   );
- * @endcode
- *
- * @ingroup tripal_feature_views
- */
- 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
-   $data['feature']['table']['group'] = 'Chado Feature';
-   $data['feature']['table']['base'] = array(
-     'field' => 'feature_id',
-     'title' => 'Chado Features',
-     'help' => 'Features are Sequence Data Records in Chado.',
-   );
-
-	if($database){
-		$data['feature']['table']['base']['database'] = $database;
-	}
-	
-
-  //Relationship Definitions---------------------------------
-  //Join: feature => nd_reagent
-  $data['feature']['table']['join']['nd_reagent'] = array(
-    'left_field' => 'feature_id',
-    'field' => 'feature_id',
-  );  
-
-  // Table Field Definitions----------------------
-  // Field: feature_id (primary key)
-  $data['feature']['feature_id'] = array(
-    'title' => 'Feature ID',
-    'help' => 'The primary key of a feature',
-    'field' => array(
-     	'handler' => 'views_handler_field_numeric',
- 		  'click sortable' => TRUE,
-    ),
-    'filter' => array(
-     	'handler' => 'views_handler_filter_numeric',
-    ),
-    'sort' => array(
-     	'handler' => 'views_handler_sort',
-    ),
-  );
-
-  // Calculated Field: 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
-  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',
-      ),
-  	);
-  } 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
-  
-  // Field: dbxref_id (forgeign key)
-  //  join between dbxref table and this one in tripal_db/views/dbxref.views.inc
-  
-  // Field: type_id (forgeign key)
-  //  join between cvterm table and this one in tripal_cv/views/cvterm.views.inc
-  
-  // Field: name (varchar 255)
-  $data['feature']['name'] = array(
-    'title' => 'Name',
-    'help' => 'The human-readable, non-unique name of a feature.',
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-  // if joined to the node table add a "Link to Node" option for the field  
-  if (!$database && module_exists('tripal_views')) {
-    $data['feature']['name']['field']['handler'] = 'views_handler_field_node_optional';
-  }
-
-  // Field: unique name (text)
-  $data['feature']['uniquename'] = array(
-    'title' => 'Unique Name',
-    'help' => 'The unique name of a feature.',
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-  // if joined to the node table add a "Link to Node" option for the field  
-  if (!$database && module_exists('tripal_views')) {
-    $data['feature']['uniquename']['field']['handler'] = 'views_handler_field_node_optional';
-  }
-
-  // Field: residues (text)
-  $data['feature']['residues'] = array(
-    'title' => 'Residues',
-    'help' => 'The sequence of a feature.',
-    'field' => array(
-      'handler' => 'views_handler_field_residues',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  // Field: sequence length (integer)
-  $data['feature']['seqlen'] = array(
-    'title' => 'Sequence Length',
-    'help' => 'The length of the sequence',
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-  );
-
-  // Field: is analysis (boolean -t/f)
-  $data['feature']['is_analysis'] = array(
-    'title' => 'Is Analysis',
-    'help' => 'A boolean indicating whether this feature was annotated by means of automated analysis.',
-    'field' => array(
-       'handler' => 'views_handler_field_chado_tf_boolean',
-       'click sortable' => TRUE,
-       'label' => t('Is Analysis?'),
-       'type' => 'yes-no',
-    ),
-    'filter' => array(
-       'handler' => 'views_handler_filter_chado_boolean',
-       'label' => t('Is Analysis?'),
-       'type' => 'yes-no',
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-  );
-
-  // Field: is obsolete (boolean -t/f)
-  $data['feature']['is_obsolete'] = array(
-    'title' => 'Is Obsolete',
-    'help' => 'A boolean indicating whether this feature is obsolete.',
-    'field' => array(
-       'handler' => 'views_handler_field_chado_tf_boolean',
-       'click sortable' => TRUE,
-       'label' => t('Is Obsolete?'),
-       'type' => 'yes-no',
-    ),
-    'filter' => array(
-       'handler' => 'views_handler_filter_chado_boolean',
-       'label' => t('Is Obsolete?'),
-       'type' => 'yes-no',
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-  );
-
-  // Field: time accessioned (datetime)
-  $data['feature']['timeaccessioned'] = array(
-    'title' => 'Time Accessioned',
-    'help' => 'The date & time when this feature was accessioned (added into the database)',
-    'field' => array(
-      'handler' => 'views_handler_field_readable_date',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-  );
-
-  // Field: time last modified (datetime)
-  $data['feature']['timelastmodified'] = array(
-    'title' => 'Time Last Modified',
-    'help' => 'The date & time when this feature was last modified.',
-    'field' => array(
-      'handler' => 'views_handler_field_readable_date',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-  );
-
-  // Calculated Field: Number of Analysis' (Count -Int)
-  // Provides the number of analysis' for a given feature
-  // @see tripal_analysis/views/misc_tables.views.inc
-  
-  //Calculated Field: Number of Libraries (Count -Int)
-  // Provides the number of libraries for a given feature
-  // @see tripal_library/views/misc_tables.views.inc 
-
-	// Calculated Field: feature relationships
-	// uses a custom field handler which pulls results from the view
-	$data['feature']['relationships'] = array(
-    'title' => t('Feature Relationships'),
-    'help' => t('Relationships including the current feature.'),
-    'field' => array(
-      'title' => t('Relationships'),
-      'help' => t('Display a given type of relationships including the current feature.'),
-      'handler' => 'views_handler_field_chado_rel_by_type',
-    ),
-  ); 
-  
-  return $data;
- }

+ 0 - 23
tripal_feature/views/handlers/views_handler_field_computed_feature_nid.inc

@@ -1,23 +0,0 @@
-<?php
-
-/**
- *
- *
- * @ingroup tripal_feature
- * @ingroup views_field_handlers
- */
-class views_handler_field_computed_feature_nid extends views_handler_field_numeric {
-	function construct() {
-		parent::construct();
-		$this->additional_fields['feature_id'] = array('table' => 'feature', 'field' => 'feature_id');
-	}
-
-	function query() { 
-		$this->ensure_my_table();
-		$this->add_additional_fields(); 
-	}
-
-	function render($values) { 
-		return $values->feature_nid;
-	}
-} 

+ 0 - 60
tripal_feature/views/misc_tables.views.inc

@@ -1,60 +0,0 @@
-<?php
-
-/**
- * Purpose: Allows the feature module to add fields to other module views
- *
- *   For example, a field counting the number of features associted with a given organism would be
- *   added to the organism view as follows:
- *   @code
-      $data['organism']['num_features'] = array(
-        'title' => 'Number of features',
-        'help' => 'Provides a count of the number of features associated with a given organism',
-        'field' => array(
-          'handler' => 'views_handler_field_chado_count',
-          'table_to_query' => 'feature',
-        ),
-      ); 
- *   @endcode
- *
- * @ingroup tripal_feature_views
- */
-function retrieve_feature_misc_tables_views_data() {
-  $data = array();
- 
-  // Table: Organism--------------------------------------------------------------------------------
-  // Calculated Field: Number of features (Count -Int)
-  // Provides the number of features for a given organism
-  $data['organism']['num_features'] = array(
-    'title' => 'Number of Features',
-    'help' => 'Provides a count of the number of features associated with a given organism',
-    'field' => array(
-      'handler' => 'views_handler_field_chado_count',
-      'table_to_query' => 'feature',
-    ),
-  );  
-
-  // Table: Library---------------------------------------------------------------------------------
-  // Calculated Field: Number of features (Count -Int)
-  // Provides the number of features for a given organism
-  $data['library']['num_features'] = array(
-    'title' => 'Number of Features',
-    'help' => 'Provides a count of the number of features associated with a given library',
-    'field' => array(
-      'handler' => 'views_handler_field_chado_count',
-      'table_to_query' => 'library_feature',
-    ),
-  );   
-
-  // Table: Analysis--------------------------------------------------------------------------------
-  // Calculated Field: Number of features (Count -Int)
-  // Provides the number of features for a given organism
-  $data['analysis']['num_features'] = array(
-    'title' => 'Number of Features',
-    'help' => 'Provides a count of the number of features associated with a given analysis',
-    'field' => array(
-      'handler' => 'views_handler_field_chado_count',
-      'table_to_query' => 'analysisfeature',
-    ),
-  ); 
-  return $data;
-}

+ 0 - 84
tripal_feature/views/template.node_join.views.inc

@@ -1,84 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *  - simply replace all XXX with the original chado table you want to join to it's drupal nodes.
- *    (ie: If you want to join features to their drupal nodes then XXX=feature)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_feature.views.inc:tripal_feature_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_feature.views.inc --in tripal_feature_views_data()
- *
- *  Note: All chado tables are joined to their drupal nodes through the chado_XXX linking table. 
- *        This file simply defines this linking table and joins the three tables together.
- *        No modification of XXX.views.inc is needed.
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
- 
-/**
- * Purpose: this function returns the portion of the data array 
- *   which describes the chado_XXX 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_XXX_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_XXX']['table'] = array(
-    'field' => 'nid',
-  );
-  
-  //Relationship Definitions---------------------------------
-  // Note: No joins need to be made from $data['XXX']['table']
-  
-  // Join the chado_XXX table to XXX
-  $data['chado_XXX']['table']['join']['XXX'] = array(
-  	'left_field' => 'XXX_id',
-  	'field' => 'XXX_id',
-  );
-  
-  // Join the node table to chado_XXX
-  $data['node']['table']['join']['chado_XXX'] = array(
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );
-  
-  // Join the node table to XXX
-  $data['node']['table']['join']['XXX'] = array(
-  	'left_table' => 'chado_XXX',
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );  
-
-	return $data;
-}

+ 0 - 211
tripal_feature/views/template.table_defn.views.inc

@@ -1,211 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *   - Every instance of XXX should be replaced with the name of your table
- *   - If this is a base table (you want a view where every row is a row from this table)
- *     then change $data['XXX']['table'] to $data['XXX']['table']['base'] 
- *     and $data['XXX']['table']['database'] to $data['XXX']['table']['base']['database']
- *   - Relationships between this table and others: YYY is the table you are trying to join to this
- *     one. You want to join a table to this one if this table contains a foreign key to the other
- *     table. If the join between this table and another is through a linking table
- *     (ie: library-XXX/YYY => library_feature-XY => feature-XXX/YYY) then make the join in both
- *     directions (ie: in the file XXX.views.inc and the file YYY.views.inc
- *   - Create a field definition for each field in this table using the example fields already
- *     listed. Match the type of the database field to the field definition listed below.
- *     (ie: for a text/varchar field from the database use plain_text_field below)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_feature.views.inc:tripal_feature_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_feature.views.inc --in tripal_feature_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the XXX table, it's fields and any joins between it and other tables
- * @see tripal_feature_views_data() --in tripal_feature.views.inc
- *
- * Table: XXX
- * @code
- * XXX-Copy/Paste Table SQL code here-XXX
- * @endcode
- */
- function retrieve_XXX_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-----------------------------------
-  $data['XXX']['table']['group'] = t('Chado XXX');
-  
-  $data['XXX']['table'] = array(
-    'field' => 'primary_id',
-    'title' => t('Chado XXX'),
-    'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
-  );
-  if($database){
-     $data['XXX']['table']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: YYY => XXX
-  // Notice that this relationship tells the primary table to show it's fields to the
-  // table referencing it by a foreign key and thus the relationship is from
-  // primary table to table referenceing it (ie: cvterm => feature)
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_field' => 'foreign key in YYY table',
-    'field' => 'primary key in XXX table',
-  );  
-  
-  //Join: XXX => XY => YYY
-  // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
-  // describe in both feature.views.inc and library.views.inc)
-  $data['XXX']['table']['join']['XY'] = array(
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );  
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_table' => 'XY',
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );
-  $data['XY']['table']['join']['YYY'] = array(
-    'left_field' => 'primary key in YYY table',
-    'field' => 'matching YYY key in the XY table',
-  );
-   
-  //Table Field Definitions----------------------------------
-      
-  //Field: XXX_id (primary key)
-  $data['XXX']['field_name'] = array(
-    'title' => t('XXX Primary Key'),
-    'help' => t('A unique index for every XXX.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  /*.......................................................
-   * Beginning of Example Field definitions
-   * Remove this section when done
-   */
-
-  //Field: plain_text_field (chado datatype)   
-  $data['XXX']['plain_text_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: numeric_field (chado datatype)   
-  $data['XXX']['numeric_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: boolean_field (chado datatype)   
-  $data['XXX']['boolean_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_boolean',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_boolean_operator',
-    ),
-  );
-
-  //Field: unix_timestamp (chado datatype)   
-  $data['XXX']['unix_timestamp'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_date',
-    ),
-  );
-
-  //Field: human_readable_date (chado datatype)   
-  $data['XXX']['human_readable_date'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_readble_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-  );
-   
-   /*
-    * End of Example Field definitions
-    */
-    
-  return $data;
-}

+ 0 - 0
tripal_feature/views/handlers/views_handler_field_residues.inc → tripal_feature/views_handlers/views_handler_field_residues.inc


+ 31 - 7
tripal_genetic/tripal_genetic.views.inc

@@ -6,33 +6,57 @@
  *  chado/tripal_genetic tables. Supplementary functions can be found in
  *  ./views/
  *
- *  Documentation on views integration can be found at 
+ *  Documentation on views integration can be found at
  *  http://views2.logrus.com/doc/html/index.html.
  */
 
-require_once('views/genotype.views.inc');
 /*************************************************************************
  * Implements hook_views_data()
  * Purpose: Describe chado/tripal tables & fields to views
  *
  * @return: a data array which follows the structure outlined in the
  *   views2 documentation for this hook. Essentially, it's an array of table
- *   definitions keyed by chado/tripal table name. Each table definition 
+ *   definitions keyed by chado/tripal table name. Each table definition
  *   includes basic details about the table, fields in that table and
  *   relationships between that table and others (joins)
  */
 function tripal_genetic_views_data()  {
   $data = array();
-  
-  $data = array_merge($data, retrieve_genotype_views_data());
-  
+
+  if (module_exists('tripal_views')) {
+    $tables = array(
+      'environment',
+      'genotype',
+      'phenstatement'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+
+    $tables = array(
+      'environment_cvterm',
+      'feautre_genotype',
+      'phendesc',
+      'phenotype_comparison'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+  }
+
   return $data;
 }
 
 /*************************************************************************
  * Implements hook_views_handlers()
  * Purpose: Register all custom handlers with views
- *   where a handler describes either "the type of field", 
+ *   where a handler describes either "the type of field",
  *   "how a field should be filtered", "how a field should be sorted"
  *
  * @return: An array of handler definitions

+ 0 - 45
tripal_genetic/views/README

@@ -1,45 +0,0 @@
-
-This directory contains all additional views code needed to integrate this module with views2.
-
-FILE/FOLDER DESCRIPTIONS
----------------------------
-<chado table name>.views.inc:
-	contains a single function retrieve_<chado table name>_views_data()
-	which describes that table to views. This function is called by
-	tripal_genetic_views_data() in ../tripal_genetic.views.inc.
-	For more information on the form of this data array look up the
-	views2 documentation for hook_views_data() 
-	-http://views2.logrus.com/doc/html/index.html
-	
-handlers/
-	Each file contained within this folder defines a views handler. Only custom
-	handlers are included in this folder and each must be described in 
-	hook_views_handlers() in ../tripal_genetic.views.inc.
-	A views handler does one of the following:
-		1) describe the type of a field and how it should be displayed
-		2) describe a method to sort this field
-		3) describe a method to filter this field
-
-
-STANDARDS TO FOLLOW
----------------------------
-
-1. All table definition files should be named tablename.views.inc
-2. All handlers should be in a handlers sub-directory and follow the naming convention of
-   views handlers (ie: views_handler_field/filter/sort_handlername.inc )
-
-Views Table Definitions:
-- Please use the template files provided whenever you are describing a new table to views.
-   For any table in chado simply copy template.table_defn.views.inc to tablename.views.inc and 
-   follow the instructions listed at the top of the template file.
-- ONLY ONE TABLE DEFINITION PER FILE
-- To join a chado table to it's drupal node simply copy template.node_join.views.inc to 
-   basetablename.views.inc and replace all XXX with basetablename.
-   
-   NOTE: Creating the table definition file is not enough. You also need to call the 
-         retrieve_XXX_views_data() function from ../tripal_genetic.views.inc:tripal_genetic_views_data()
-         by adding the following line:
-            $data = array_merge($data, retrieve_XXX_views_data());
-         to the function and including the file directly above the function (blow the function 
-         header by adding:
-            require_once('views/XXX.views.inc');

+ 0 - 180
tripal_genetic/views/genotype.views.inc

@@ -1,180 +0,0 @@
-<?php 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_genetic.views.inc --in tripal_genetic_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the genotype table, it's fields and any joins between it and other tables
- * @see tripal_genetic_views_data() --in tripal_genetic.views.inc
- *
- * Table: genotype
- * @code
- * genotype-Copy/Paste Table SQL code here-genotype
- * @endcode
- */
- function retrieve_genotype_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-----------------------------------
-  $data['genotype']['table']['group'] = t('Chado Genotype');
-  
-  $data['genotype']['table']['base'] = array(
-    'field' => 'genotype_id',
-    'title' => t('Chado Genotype'),
-    'help' => t('A genotype is defined by a collection of features, mutations, balancers, deficiencies, haplotype blocks, or engineered constructs.'),
-  );
-  if($database){
-     $data['genotype']['table']['base']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-
-  //Join: feature => feature_genotype => feature
-  // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
-  // describe in both feature.views.inc and library.views.inc)
-  $data['feature']['table']['join']['feature_genotype'] = array(
-    'left_field' => 'feature_id',
-    'field' => 'feature_id',
-  );  
-  $data['feature']['table']['join']['genotype'] = array(
-    'left_table' => 'feature_genotype',
-    'left_field' => 'feature_id',
-    'field' => 'feature_id',
-  );
-  $data['feature_genotype']['table']['join']['genotype'] = array(
-    'left_field' => 'genotype_id',
-    'field' => 'genotype_id',
-  );
-
-  //Join: feature => feature_genotype => feature
-  // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
-  // describe in both feature.views.inc and library.views.inc)
-  $data['genotype']['table']['join']['feature_genotype'] = array(
-    'left_field' => 'genotype_id',
-    'field' => 'genotype_id',
-  );  
-  $data['genotype']['table']['join']['feature'] = array(
-    'left_table' => 'feature_genotype',
-    'left_field' => 'genotype_id',
-    'field' => 'genotype_id',
-  );
-  $data['feature_genotype']['table']['join']['feature'] = array(
-    'left_field' => 'feature_id',
-    'field' => 'feature_id',
-  );
-  
-   //Join: stock => stock_genotype => stock
-  // This relationship should be described in both directions
-  // in the appropriate files (ie: for stock => library 
-  // describe in both stock.views.inc and library.views.inc)
-  $data['stock']['table']['join']['stock_genotype'] = array(
-    'left_field' => 'stock_id',
-    'field' => 'stock_id',
-  );  
-  $data['stock']['table']['join']['genotype'] = array(
-    'left_table' => 'stock_genotype',
-    'left_field' => 'stock_id',
-    'field' => 'stock_id',
-  );
-  $data['stock_genotype']['table']['join']['genotype'] = array(
-    'left_field' => 'genotype_id',
-    'field' => 'genotype_id',
-  );
-  
-  //Table Field Definitions----------------------------------
-      
-  //Field: genotype_id (primary key)
-  $data['genotype']['genotype_id'] = array(
-    'title' => t('Genotype Primary Key'),
-    'help' => t('A unique index for every genotype.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: name (text)  
-  $data['genotype']['name'] = array(
-    'title' => t('Name'),
-    'help' => t('Human-readable Name of the genotype.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: uniquename (text)  
-  $data['genotype']['uniquename'] = array(
-    'title' => t('Unique Name'),
-    'help' => t('Unique Name of the genotype.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: description (varchar -255)   
-  $data['genotype']['description'] = array(
-    'title' => t('Description/Value'),
-    'help' => t('A Description of the genotype.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-    
-  return $data;
-}

+ 0 - 84
tripal_genetic/views/template.node_join.views.inc

@@ -1,84 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *  - simply replace all XXX with the original chado table you want to join to it's drupal nodes.
- *    (ie: If you want to join features to their drupal nodes then XXX=feature)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_genetic.views.inc:tripal_genetic_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_genetic.views.inc --in tripal_genetic_views_data()
- *
- *  Note: All chado tables are joined to their drupal nodes through the chado_XXX linking table. 
- *        This file simply defines this linking table and joins the three tables together.
- *        No modification of XXX.views.inc is needed.
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
- 
-/**
- * Purpose: this function returns the portion of the data array 
- *   which describes the chado_XXX drupal table, it's fields and any joins between it 
- *   and other tables
- * @see tripal_genetic_views_data() --in tripal_genetic.views.inc
- *
- * The main need for description of this table to views is to join chado data with drupal nodes
- *
- */
-function retrieve_chado_XXX_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_XXX']['table'] = array(
-    'field' => 'nid',
-  );
-  
-  //Relationship Definitions---------------------------------
-  // Note: No joins need to be made from $data['XXX']['table']
-  
-  // Join the chado_XXX table to XXX
-  $data['chado_XXX']['table']['join']['XXX'] = array(
-  	'left_field' => 'XXX_id',
-  	'field' => 'XXX_id',
-  );
-  
-  // Join the node table to chado_XXX
-  $data['node']['table']['join']['chado_XXX'] = array(
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );
-  
-  // Join the node table to XXX
-  $data['node']['table']['join']['XXX'] = array(
-  	'left_table' => 'chado_XXX',
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );  
-
-	return $data;
-}

+ 0 - 211
tripal_genetic/views/template.table_defn.views.inc

@@ -1,211 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *   - Every instance of XXX should be replaced with the name of your table
- *   - If this is a base table (you want a view where every row is a row from this table)
- *     then change $data['XXX']['table'] to $data['XXX']['table']['base'] 
- *     and $data['XXX']['table']['database'] to $data['XXX']['table']['base']['database']
- *   - Relationships between this table and others: YYY is the table you are trying to join to this
- *     one. You want to join a table to this one if this table contains a foreign key to the other
- *     table. If the join between this table and another is through a linking table
- *     (ie: library-XXX/YYY => library_feature-XY => feature-XXX/YYY) then make the join in both
- *     directions (ie: in the file XXX.views.inc and the file YYY.views.inc
- *   - Create a field definition for each field in this table using the example fields already
- *     listed. Match the type of the database field to the field definition listed below.
- *     (ie: for a text/varchar field from the database use plain_text_field below)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_genetic.views.inc:tripal_genetic_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_genetic.views.inc --in tripal_genetic_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the XXX table, it's fields and any joins between it and other tables
- * @see tripal_genetic_views_data() --in tripal_genetic.views.inc
- *
- * Table: XXX
- * @code
- * XXX-Copy/Paste Table SQL code here-XXX
- * @endcode
- */
- function retrieve_XXX_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-----------------------------------
-  $data['XXX']['table']['group'] = t('Chado XXX');
-  
-  $data['XXX']['table'] = array(
-    'field' => 'primary_id',
-    'title' => t('Chado XXX'),
-    'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
-  );
-  if($database){
-     $data['XXX']['table']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: YYY => XXX
-  // Notice that this relationship tells the primary table to show it's fields to the
-  // table referencing it by a foreign key and thus the relationship is from
-  // primary table to table referenceing it (ie: cvterm => feature)
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_field' => 'foreign key in YYY table',
-    'field' => 'primary key in XXX table',
-  );  
-  
-  //Join: XXX => XY => YYY
-  // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
-  // describe in both feature.views.inc and library.views.inc)
-  $data['XXX']['table']['join']['XY'] = array(
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );  
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_table' => 'XY',
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );
-  $data['XY']['table']['join']['YYY'] = array(
-    'left_field' => 'primary key in YYY table',
-    'field' => 'matching YYY key in the XY table',
-  );
-   
-  //Table Field Definitions----------------------------------
-      
-  //Field: XXX_id (primary key)
-  $data['XXX']['field_name'] = array(
-    'title' => t('XXX Primary Key'),
-    'help' => t('A unique index for every XXX.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  /*.......................................................
-   * Beginning of Example Field definitions
-   * Remove this section when done
-   */
-
-  //Field: plain_text_field (chado datatype)   
-  $data['XXX']['plain_text_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: numeric_field (chado datatype)   
-  $data['XXX']['numeric_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: boolean_field (chado datatype)   
-  $data['XXX']['boolean_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_boolean',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_boolean_operator',
-    ),
-  );
-
-  //Field: unix_timestamp (chado datatype)   
-  $data['XXX']['unix_timestamp'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_date',
-    ),
-  );
-
-  //Field: human_readable_date (chado datatype)   
-  $data['XXX']['human_readable_date'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_readble_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-  );
-   
-   /*
-    * End of Example Field definitions
-    */
-    
-  return $data;
-}

+ 33 - 14
tripal_library/tripal_library.views.inc

@@ -6,7 +6,7 @@
  *  chado/tripal organism tables. Supplementary functions can be found in
  *  ./views/
  *
- *  Documentation on views integration can be found at 
+ *  Documentation on views integration can be found at
  *  http://views2.logrus.com/doc/html/index.html.
  */
 
@@ -16,15 +16,12 @@
  * @ingroup tripal_library
  */
 
-require_once('views/library.views.inc');
-require_once('views/chado_library.views.inc');
-require_once('views/misc_tables.views.inc'); 
 /*************************************************************************
  * Implements hook_views_data()
  * Purpose: Describe chado/tripal tables & fields to views
  * @return: a data array which follows the structure outlined in the
  *   views2 documentation for this hook. Essentially, it's an array of table
- *   definitions keyed by chado/tripal table name. Each table definition 
+ *   definitions keyed by chado/tripal table name. Each table definition
  *   includes basic details about the table, fields in that table and
  *   relationships between that table and others (joins)
  *
@@ -32,18 +29,40 @@ require_once('views/misc_tables.views.inc');
  */
 function tripal_library_views_data()  {
   $data = array();
-  
-  $data = array_merge($data, retrieve_library_views_data());
-  $data = array_merge($data, retrieve_chado_library_views_data());
-  $data = array_merge($data, retrieve_library_misc_tables_views_data());
-  
+
+  if (module_exists('tripal_views')) {
+    $tables = array(
+      'library'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+
+    $tables = array(
+      'library_cvterm',
+      'library_feature',
+      'library_pub',
+      'library_synonym',
+      'libraryprop'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+  }
+
   return $data;
 }
 
 /*************************************************************************
  * Implements hook_views_handlers()
  * Purpose: Register all custom handlers with views
- *   where a handler describes either "the type of field", 
+ *   where a handler describes either "the type of field",
  *   "how a field should be filtered", "how a field should be sorted"
  * @return: An array of handler definitions
  *
@@ -85,7 +104,7 @@ function tripal_library_views_data_alter(&$data) {
       ),
     );
   }
-  
+
 }
 
 /**
@@ -95,7 +114,7 @@ function tripal_library_views_data_alter(&$data) {
  */
 function tripal_library_views_default_views () {
   $views = array();
-  
+
   // Main default view
   // List all cvterms based on cv
   $view = new view;
@@ -389,6 +408,6 @@ function tripal_library_views_default_views () {
     'name' => 'navigation',
   ));
   $views[$view->name] = $view;
-  
+
   return $views;
 }

+ 0 - 45
tripal_library/views/README

@@ -1,45 +0,0 @@
-
-This directory contains all additional views code needed to integrate this module with views2.
-
-FILE/FOLDER DESCRIPTIONS
----------------------------
-<chado table name>.views.inc:
-	contains a single function retrieve_<chado table name>_views_data()
-	which describes that table to views. This function is called by
-	tripal_library_views_data() in ../tripal_library.views.inc.
-	For more information on the form of this data array look up the
-	views2 documentation for hook_views_data() 
-	-http://views2.logrus.com/doc/html/index.html
-	
-handlers/
-	Each file contained within this folder defines a views handler. Only custom
-	handlers are included in this folder and each must be described in 
-	hook_views_handlers() in ../tripal_library.views.inc.
-	A views handler does one of the following:
-		1) describe the type of a field and how it should be displayed
-		2) describe a method to sort this field
-		3) describe a method to filter this field
-
-
-STANDARDS TO FOLLOW
----------------------------
-
-1. All table definition files should be named tablename.views.inc
-2. All handlers should be in a handlers sub-directory and follow the naming convention of
-   views handlers (ie: views_handler_field/filter/sort_handlername.inc )
-
-Views Table Definitions:
-- Please use the template files provided whenever you are describing a new table to views.
-   For any table in chado simply copy template.table_defn.views.inc to tablename.views.inc and 
-   follow the instructions listed at the top of the template file.
-- ONLY ONE TABLE DEFINITION PER FILE
-- To join a chado table to it's drupal node simply copy template.node_join.views.inc to 
-   basetablename.views.inc and replace all XXX with basetablename.
-   
-   NOTE: Creating the table definition file is not enough. You also need to call the 
-         retrieve_XXX_views_data() function from ../tripal_library.views.inc:tripal_library_views_data()
-         by adding the following line:
-            $data = array_merge($data, retrieve_XXX_views_data());
-         to the function and including the file directly above the function (blow the function 
-         header by adding:
-            require_once('views/XXX.views.inc');

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

@@ -1,99 +0,0 @@
-<?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
- *
- * @ingroup tripal_library_views
- */
-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',
-    'group' => 'Chado Library'
-  );
-  
-  $data['chado_library']['nid'] = array(
-    'title' => t('Library Node ID'),
-    'help' => t('The node ID for this library'),
-    'field' => array(
-     	'handler' => 'views_handler_field_numeric',
- 		  'click sortable' => TRUE,
-    ),
-    'filter' => array(
-     	'handler' => 'views_handler_filter_numeric',
-    ),
-    'sort' => array(
-     	'handler' => 'views_handler_sort',
-    ),
-  );
-
-  // 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',
-  );  
-
-  // Add relationship between chado_library and library
-  $data['chado_library']['library_nid'] = array(
-    'group' => 'Library',
-    'title' => 'Library Node',
-    'help' => 'Links Chado Library Fields/Data to the Nodes in the current View.',
-    'real field' => 'library_id',
-    'relationship' => array(
-      'handler' => 'views_handler_relationship',
-      'title' => t('Chado => Library'),
-      'label' => t('Chado => Library'),
-      'real field' => 'library_id',
-      'base' => 'library',
-      'base field' => 'library_id'
-    ),
-  );
-
-  // Add node relationship to library
-  $data['chado_library']['library_chado_nid'] = array(
-    'group' => 'Library',
-    'title' => 'Library Node',
-    'help' => 'Links Chado Library 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;
-}

+ 0 - 17
tripal_library/views/handlers/views_handler_field_computed_library_nid.inc

@@ -1,17 +0,0 @@
-<?php
-
-class views_handler_field_computed_library_nid extends views_handler_field_numeric {
-	function construct() {
-		parent::construct();
-		$this->additional_fields['library_id'] = array('table' => 'library', 'field' => 'library_id');
-	}
-
-	function query() { 
-		$this->ensure_my_table();
-		$this->add_additional_fields(); 
-	}
-
-	function render($values) { 
-		return $values->library_nid;
-	}
-} 

+ 0 - 216
tripal_library/views/library.views.inc

@@ -1,216 +0,0 @@
-<?php
-	/**
- * Purpose: this function returns the portion of the data array 
- *   which describes the library table, it's fields and any joins between it and other tables
- * @see tripal_library_views_data() --in tripal_library.views.inc
- *
- * @todo Add support for the following tables: library_cvterm, library_pub, library_synonym, libraryprop
- * @todo Add support for multiple libraries listed per feature
- * @todo Add join to node table within if <chado/drupal same db>; also addd if not around nid field
- *
- * BASE TABLE: library
- * @code
- * create table library (
- *    library_id serial not null,
- *    primary key (library_id),
- *    organism_id int not null,
- *    foreign key (organism_id) references organism (organism_id),
- *    name varchar(255),
- *    uniquename text not null,
- *    type_id int not null,
- *    foreign key (type_id) references cvterm (cvterm_id),
- *    is_obsolete int not null default 0,
- *    timeaccessioned timestamp not null default current_timestamp,
- *    timelastmodified timestamp not null default current_timestamp,
- *    constraint library_c1 unique (organism_id,uniquename,type_id)
- * );
- * @endcode
- *
- * @ingroup tripal_library_views
- */
-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
-	$data['library']['table']['group'] = 'Chado Library';
-	$data['library']['table']['base'] = array(
-	  'field' => 'library_id',
-	  'title' => 'Chado Library',
-	  'help' => 'Library existing in the Chado Database',                                                                                                                                                                          
-	);
-	if($database){
-	  $data['library']['table']['base']['database'] = $database;
-	}
-	
-	// Define relationships between this table and others
-  $data['library']['table']['join'] = array(
-    'library_feature' => array(
-      'left_field' => 'library_id',
-      'field' => 'library_id',
-    ),
-    'feature' => array(
-      'left_table' => 'library_feature',
-      'left_field' => 'library_id',
-      'field' => 'library_id',
-    ),
-  );
-
-  // Describe the joins with the library_feature table
-  $data['library_feature']['table']['join'] = array(
-    'feature' => array(
-      'left_field' => 'feature_id',
-      'field' => 'feature_id',
-    ),
-  );
-	
-	// Table Field Definitions----------------------
-	// Field: library_id (primary key)
-	$data['library']['library_id'] = array(
-	  'title' => 'Library ID',
-	  'help' => 'The primary key of the library table.',
-	  'field' => array(
-	    'handler' => 'views_handler_field_numeric',
-	    'click sortable' => TRUE,
-	  ),
-	  'filter' => array(
-	    'handler' => 'views_handler_filter_numeric',
-	  ),
-	  'sort' => array(
-	    'handler' => 'views_handler_sort',
-	  ),
-	);
-	
-  // Calculated Field: 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
-  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',
-	  	),
-		);
-  } else {
-    // Add relationship between chado_library and library
-    $data['library']['library_nid'] = array(
-      'group' => 'Library',
-      'title' => 'Library Node',
-      'help' => 'Links Chado Library Fields/Data to the Nodes in the current View.',
-      'real field' => 'library_id',
-      'relationship' => array(
-        'handler' => 'views_handler_relationship',
-        'title' => t('Library => Chado'),
-        'label' => t('Library => Chado'),
-        'real field' => 'library_id',
-        'base' => 'chado_library',
-        'base field' => 'library_id'
-      ),
-    );
-
-  }
-	
-	// Field: organism_id (forgeign key)
-  //  join between organism table and this one in tripal_organism/views/organism.views.inc
-	
-	// Field: type_id (forgeign key)
-  //  join between cvterm table and this one in tripal_cv/views/cvterm.views.inc
-  
-	// Field: Name (varchar 255)
-	$data['library']['name'] = array(
-	  'title' => 'Name',
-	  'help' => 'The human-readable name of the current library.',
-	  'field' => array(
-	    'handler' => 'views_handler_field',
-	    'click sortable' => TRUE,
-	  ),
-	  'sort' => array(
-	    'handler' => 'views_handler_sort',
-	  ),
-	  'filter' => array(
-	    'handler' => 'views_handler_filter_chado_select_string',
-	  ),
-	  'argument' => array(
-	    'handler' => 'views_handler_argument_string',
-	  ),
-	);
-  // if joined to the node table add a "Link to Node" option for the field  
-  if (!$database) {
-    $data['library']['name']['field']['handler'] = 'views_handler_field_node_optional';
-  }
-	
-	// Field: Unique name (text)
-	$data['library']['uniquename'] = array(
-	  'title' => 'Unique Name',
-	  'help' => 'The unique name of the current library.',
-	  'field' => array(
-	    'handler' => 'views_handler_field',
-	    'click sortable' => TRUE,
-	  ),
-	  'filter' => array(
-	    'handler' => 'views_handler_filter_string',
-	  ),
-	  'argument' => array(
-	    'handler' => 'views_handler_argument_string',
-	  ),
-	);
-  // if joined to the node table add a "Link to Node" option for the field  
-  if (!$database) {
-    $data['library']['uniquename']['field']['handler'] = 'views_handler_field_node_optional';
-  }
-	
-	// Field: Is obsolete (integer 0/1)
-	$data['library']['is_obsolete'] = array(
-	  'title' => t('Is Obsolete?'),
-	  'help' => t('Indicates whether a given library is obsolete or not.'),
-	  'field' => array(
-	    'handler' => 'views_handler_field_boolean',
-	    'click sortable' => TRUE,
-	  ),
-	  'filter' => array(
-       'handler' => 'views_handler_filter_chado_boolean',
-       'label' => t('Is Obsolete?'),
-       'type' => 'yes-no',
-	  ),
-	  'sort' => array(
-	    'handler' => 'views_handler_sort',
-	  ),
-	);
-	
-	// Field: time accessioned (datetime)
-	$data['library']['timeaccessioned'] = array(
-	  'title' => t('Date Accessioned'),
-	  'help' => t('Indicates the date a given library was accessioned (entered into the database).'),
-	  'field' => array(
-	    'handler' => 'views_handler_field_readable_date',
-	    'click sortable' => TRUE,
-	  ),
-	  'sort' => array(
-	    'handler' => 'views_handler_sort_date',
-	  ),
-	);
-	
-	// Field: time last modified (datetime)
-	$data['library']['timelastmodified'] = array(
-	  'title' => t('Date Last Modified'),
-	  'help' => t('Indicates the date that a given library was last modified.'),
-	  'field' => array(
-	    'handler' => 'views_handler_field_readable_date',
-	    'click sortable' => TRUE,
-	  ),
-	  'sort' => array(
-	    'handler' => 'views_handler_sort_date',
-	  ),
-	);
-	
-	return $data;
-	
-}

+ 0 - 49
tripal_library/views/misc_tables.views.inc

@@ -1,49 +0,0 @@
-<?php
-
-/**
- * Purpose: Allows the library module to add fields to other module views
- *
- *   For example, a field counting the number of libraries associted with a given feature would be
- *   added to the feature view as follows:
- *   @code
-      $data['feature']['num_libraries'] = array(
-        'title' => "Number of Libraries",
-        'help' => "Provides a count of the number of libraries associated with a given feature",
-        'field' => array(
-          'handler' => 'views_handler_field_chado_count',
-          'table_to_query' => 'library_feature',
-        ),
-      ); 
- *   @endcode
- *
- * @ingroup tripal_library_views
- */
-function retrieve_library_misc_tables_views_data() {
-  $data = array();
- 
-  // Table: Feature---------------------------------------------------------------------------------
-  // Calculated Field: Number of Libraries (Count -Int)
-  // Provides the number of libraries for a given feature
-  $data['feature']['num_libraries'] = array(
-    'title' => "Number of Libraries",
-    'help' => "Provides a count of the number of libraries associated with a given feature",
-    'field' => array(
-      'handler' => 'views_handler_field_chado_count',
-      'table_to_query' => 'library_feature',
-    ),
-  ); 
-
-  // Table: Organism--------------------------------------------------------------------------------
-  // Calculated Field: Number of Libraries (Count -Int)
-  // Provides the number of libraries for a given organism
-  $data['organism']['num_libraries'] = array(
-    'title' => 'Number of Libraries',
-    'help' => 'Provides a count of the number of libraries associated with a given organism',
-    'field' => array(
-      'handler' => 'views_handler_field_chado_count',
-      'table_to_query' => 'library',
-    ),
-  );  
-  
-  return $data;
-}

+ 0 - 84
tripal_library/views/template.node_join.views.inc

@@ -1,84 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *  - simply replace all XXX with the original chado table you want to join to it's drupal nodes.
- *    (ie: If you want to join features to their drupal nodes then XXX=feature)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_library.views.inc:tripal_library_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_library.views.inc --in tripal_library_views_data()
- *
- *  Note: All chado tables are joined to their drupal nodes through the chado_XXX linking table. 
- *        This file simply defines this linking table and joins the three tables together.
- *        No modification of XXX.views.inc is needed.
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
- 
-/**
- * Purpose: this function returns the portion of the data array 
- *   which describes the chado_XXX 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_XXX_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_XXX']['table'] = array(
-    'field' => 'nid',
-  );
-  
-  //Relationship Definitions---------------------------------
-  // Note: No joins need to be made from $data['XXX']['table']
-  
-  // Join the chado_XXX table to XXX
-  $data['chado_XXX']['table']['join']['XXX'] = array(
-  	'left_field' => 'XXX_id',
-  	'field' => 'XXX_id',
-  );
-  
-  // Join the node table to chado_XXX
-  $data['node']['table']['join']['chado_XXX'] = array(
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );
-  
-  // Join the node table to XXX
-  $data['node']['table']['join']['XXX'] = array(
-  	'left_table' => 'chado_XXX',
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );  
-
-	return $data;
-}

+ 0 - 211
tripal_library/views/template.table_defn.views.inc

@@ -1,211 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *   - Every instance of XXX should be replaced with the name of your table
- *   - If this is a base table (you want a view where every row is a row from this table)
- *     then change $data['XXX']['table'] to $data['XXX']['table']['base'] 
- *     and $data['XXX']['table']['database'] to $data['XXX']['table']['base']['database']
- *   - Relationships between this table and others: YYY is the table you are trying to join to this
- *     one. You want to join a table to this one if this table contains a foreign key to the other
- *     table. If the join between this table and another is through a linking table
- *     (ie: library-XXX/YYY => library_feature-XY => feature-XXX/YYY) then make the join in both
- *     directions (ie: in the file XXX.views.inc and the file YYY.views.inc
- *   - Create a field definition for each field in this table using the example fields already
- *     listed. Match the type of the database field to the field definition listed below.
- *     (ie: for a text/varchar field from the database use plain_text_field below)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_library.views.inc:tripal_library_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_library.views.inc --in tripal_library_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the XXX table, it's fields and any joins between it and other tables
- * @see tripal_library_views_data() --in tripal_library.views.inc
- *
- * Table: XXX
- * @code
- * XXX-Copy/Paste Table SQL code here-XXX
- * @endcode
- */
- function retrieve_XXX_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-----------------------------------
-  $data['XXX']['table']['group'] = t('Chado XXX');
-  
-  $data['XXX']['table'] = array(
-    'field' => 'primary_id',
-    'title' => t('Chado XXX'),
-    'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
-  );
-  if($database){
-     $data['XXX']['table']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: YYY => XXX
-  // Notice that this relationship tells the primary table to show it's fields to the
-  // table referencing it by a foreign key and thus the relationship is from
-  // primary table to table referenceing it (ie: cvterm => feature)
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_field' => 'foreign key in YYY table',
-    'field' => 'primary key in XXX table',
-  );  
-  
-  //Join: XXX => XY => YYY
-  // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
-  // describe in both feature.views.inc and library.views.inc)
-  $data['XXX']['table']['join']['XY'] = array(
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );  
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_table' => 'XY',
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );
-  $data['XY']['table']['join']['YYY'] = array(
-    'left_field' => 'primary key in YYY table',
-    'field' => 'matching YYY key in the XY table',
-  );
-   
-  //Table Field Definitions----------------------------------
-      
-  //Field: XXX_id (primary key)
-  $data['XXX']['field_name'] = array(
-    'title' => t('XXX Primary Key'),
-    'help' => t('A unique index for every XXX.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  /*.......................................................
-   * Beginning of Example Field definitions
-   * Remove this section when done
-   */
-
-  //Field: plain_text_field (chado datatype)   
-  $data['XXX']['plain_text_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: numeric_field (chado datatype)   
-  $data['XXX']['numeric_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: boolean_field (chado datatype)   
-  $data['XXX']['boolean_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_boolean',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_boolean_operator',
-    ),
-  );
-
-  //Field: unix_timestamp (chado datatype)   
-  $data['XXX']['unix_timestamp'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_date',
-    ),
-  );
-
-  //Field: human_readable_date (chado datatype)   
-  $data['XXX']['human_readable_date'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_readble_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-  );
-   
-   /*
-    * End of Example Field definitions
-    */
-    
-  return $data;
-}

+ 45 - 23
tripal_natural_diversity/tripal_natural_diversity.views.inc

@@ -6,48 +6,70 @@
  *  chado/tripal_natural_diversity tables. Supplementary functions can be found in
  *  ./views/
  *
- *  Documentation on views integration can be found at 
+ *  Documentation on views integration can be found at
  *  http://views2.logrus.com/doc/html/index.html.
  */
- 
+
 /*************************************************************************
  * Implements hook_views_data()
  * Purpose: Describe chado/tripal tables & fields to views
  *
  * @return: a data array which follows the structure outlined in the
  *   views2 documentation for this hook. Essentially, it's an array of table
- *   definitions keyed by chado/tripal table name. Each table definition 
+ *   definitions keyed by chado/tripal table name. Each table definition
  *   includes basic details about the table, fields in that table and
  *   relationships between that table and others (joins)
  */
-require_once('views/nd_experiment.views.inc');
-require_once('views/nd_experimentprop.views.inc');
-require_once('views/nd_geolocation.views.inc');
-require_once('views/nd_geolocationprop.views.inc');
-require_once('views/nd_reagent.views.inc');
-require_once('views/nd_reagentprop.views.inc');
 function tripal_natural_diversity_views_data()  {
   $data = array();
-  
-  //EXPERIMENT
-  $data = array_merge($data, retrieve_nd_experiment_views_data());
-  $data = array_merge($data, retrieve_nd_experimentprop_views_data());
-  
-  // GEOLOCATION
-  $data = array_merge($data, retrieve_nd_geolocation_views_data());
-  $data = array_merge($data, retrieve_nd_geolocationprop_views_data());
-  
-  // REAGENTS
-  $data = array_merge($data, retrieve_nd_reagent_views_data());
-  $data = array_merge($data, retrieve_nd_reagentprop_views_data());
-  
+
+  if (module_exists('tripal_views')) {
+    $tables = array(
+      'nd_experiment',
+      'nd_geolocation',
+      'nd_protocol',
+      'nd_reagent'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+
+    $tables = array(
+      'nd_experiment_contact',
+      'nd_experiment_dbxref',
+      'nd_experiment_genotype',
+      'nd_experiment_phenotype',
+      'nd_experiment_project',
+      'nd_experiment_protocol',
+      'nd_experiment_pub',
+      'nd_experiment_stock',
+      'nd_experiment_stock_dbxref',
+      'nd_experiment_stockprop',
+      'nd_experimentprop',
+      'nd_geolocationprop',
+      'nd_protocol_reagent',
+      'nd_protocolprop',
+      'nd_reagent_relationship',
+      'nd_reagentprop'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+  }
+
   return $data;
 }
 
 /*************************************************************************
  * Implements hook_views_handlers()
  * Purpose: Register all custom handlers with views
- *   where a handler describes either "the type of field", 
+ *   where a handler describes either "the type of field",
  *   "how a field should be filtered", "how a field should be sorted"
  *
  * @return: An array of handler definitions

+ 0 - 45
tripal_natural_diversity/views/README

@@ -1,45 +0,0 @@
-
-This directory contains all additional views code needed to integrate this module with views2.
-
-FILE/FOLDER DESCRIPTIONS
----------------------------
-<chado table name>.views.inc:
-	contains a single function retrieve_<chado table name>_views_data()
-	which describes that table to views. This function is called by
-	tripal_natural_diversity_views_data() in ../tripal_natural_diversity.views.inc.
-	For more information on the form of this data array look up the
-	views2 documentation for hook_views_data() 
-	-http://views2.logrus.com/doc/html/index.html
-	
-handlers/
-	Each file contained within this folder defines a views handler. Only custom
-	handlers are included in this folder and each must be described in 
-	hook_views_handlers() in ../tripal_natural_diversity.views.inc.
-	A views handler does one of the following:
-		1) describe the type of a field and how it should be displayed
-		2) describe a method to sort this field
-		3) describe a method to filter this field
-
-
-STANDARDS TO FOLLOW
----------------------------
-
-1. All table definition files should be named tablename.views.inc
-2. All handlers should be in a handlers sub-directory and follow the naming convention of
-   views handlers (ie: views_handler_field/filter/sort_handlername.inc )
-
-Views Table Definitions:
-- Please use the template files provided whenever you are describing a new table to views.
-   For any table in chado simply copy template.table_defn.views.inc to tablename.views.inc and 
-   follow the instructions listed at the top of the template file.
-- ONLY ONE TABLE DEFINITION PER FILE
-- To join a chado table to it's drupal node simply copy template.node_join.views.inc to 
-   basetablename.views.inc and replace all XXX with basetablename.
-   
-   NOTE: Creating the table definition file is not enough. You also need to call the 
-         retrieve_XXX_views_data() function from ../tripal_natural_diversity.views.inc:tripal_natural_diversity_views_data()
-         by adding the following line:
-            $data = array_merge($data, retrieve_XXX_views_data());
-         to the function and including the file directly above the function (blow the function 
-         header by adding:
-            require_once('views/XXX.views.inc');

+ 0 - 182
tripal_natural_diversity/views/nd_experiment.views.inc

@@ -1,182 +0,0 @@
-<?php
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_natural_diversity.views.inc --in tripal_natural_diversity_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the nd_experiment table, it's fields and any joins between it and other tables
- * @see tripal_natural_diversity_views_data() --in tripal_natural_diversity.views.inc
- *
- * @todo Add relationship to nd_geolocations.views.inc
- *
- * Table: nd_experiment
- * @code
-  CREATE TABLE nd_experiment (
-    nd_experiment_id serial PRIMARY KEY NOT NULL,
-    nd_geolocation_id integer NOT NULL references nd_geolocation (nd_geolocation_id) on delete cascade INITIALLY DEFERRED,
-    type_id integer NOT NULL references cvterm (cvterm_id) on delete cascade INITIALLY DEFERRED 
-  );
- * @endcode
- */
- function retrieve_nd_experiment_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-----------------------------------
-  $data['nd_experiment']['table']['group'] = t('Chado ND Experiment');
-  
-  $data['nd_experiment']['table']['base'] = array(
-    'field' => 'nd_experiment_id',
-    'title' => t('Chado Natural Diversity Experiment'),
-    'help' => t('Represents one data point in a natural diversity project.'),
-  );
-  if($database){
-     $data['nd_experiment']['table']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: nd_experiment => nd_geolocation
-  // In nd_experiment.views.inc
-  
-  //Join: nd_experiment => nd_experiment_contact => contact
-  $data['nd_experiment']['table']['join']['nd_experiment_contact'] = array(
-    'left_field' => 'nd_experiment_id',
-    'field' => 'nd_experiment_id',
-  );  
-  $data['nd_experiment']['table']['join']['contact'] = array(
-    'left_table' => 'nd_experiment_contact',
-    'left_field' => 'nd_experiment_id',
-    'field' => 'nd_experiment_id',
-  );
-  $data['nd_experiment_contact']['table']['join']['contact'] = array(
-    'left_field' => 'contact_id',
-    'field' => 'contact_id',
-  );
-  
-  //Join: nd_experiment => nd_experiment_dbxref => dbxref
-  $data['nd_experiment']['table']['join']['nd_experiment_dbxref'] = array(
-    'left_field' => 'nd_experiment_id',
-    'field' => 'nd_experiment_id',
-  );  
-  $data['nd_experiment']['table']['join']['dbxref'] = array(
-    'left_table' => 'nd_experiment_dbxref',
-    'left_field' => 'nd_experiment_id',
-    'field' => 'nd_experiment_id',
-  );
-  $data['nd_experiment_dbxref']['table']['join']['dbxref'] = array(
-    'left_field' => 'dbxref_id',
-    'field' => 'dbxref_id',
-  );
-  
-  //Join: nd_experiment => nd_experiment_genotype => genotype
-  $data['nd_experiment']['table']['join']['nd_experiment_genotype'] = array(
-    'left_field' => 'nd_experiment_id',
-    'field' => 'nd_experiment_id',
-  );  
-  $data['nd_experiment']['table']['join']['genotype'] = array(
-    'left_table' => 'nd_experiment_genotype',
-    'left_field' => 'nd_experiment_id',
-    'field' => 'nd_experiment_id',
-  );
-  $data['nd_experiment_genotype']['table']['join']['genotype'] = array(
-    'left_field' => 'genotype_id',
-    'field' => 'genotype_id',
-  );
-  
-  //Join: nd_experiment => nd_experiment_phenotype => phenotype
-  $data['nd_experiment']['table']['join']['nd_experiment_phenotype'] = array(
-    'left_field' => 'nd_experiment_id',
-    'field' => 'nd_experiment_id',
-  );  
-  $data['nd_experiment']['table']['join']['phenotype'] = array(
-    'left_table' => 'nd_experiment_phenotype',
-    'left_field' => 'nd_experiment_id',
-    'field' => 'nd_experiment_id',
-  );
-  $data['nd_experiment_phenotype']['table']['join']['phenotype'] = array(
-    'left_field' => 'phenotype_id',
-    'field' => 'phenotype_id',
-  );
-  
-  //Join: nd_experiment => nd_experiment_project => project
-  $data['nd_experiment']['table']['join']['nd_experiment_project'] = array(
-    'left_field' => 'nd_experiment_id',
-    'field' => 'nd_experiment_id',
-  );  
-  $data['nd_experiment']['table']['join']['project'] = array(
-    'left_table' => 'nd_experiment_project',
-    'left_field' => 'nd_experiment_id',
-    'field' => 'nd_experiment_id',
-  );
-  $data['nd_experiment_project']['table']['join']['project'] = array(
-    'left_field' => 'project_id',
-    'field' => 'project_id',
-  );
-  
-  //Join: nd_experiment => nd_experiment_pub => pub
-  $data['nd_experiment']['table']['join']['nd_experiment_pub'] = array(
-    'left_field' => 'nd_experiment_id',
-    'field' => 'nd_experiment_id',
-  );  
-  $data['nd_experiment']['table']['join']['pub'] = array(
-    'left_table' => 'nd_experiment_pub',
-    'left_field' => 'nd_experiment_id',
-    'field' => 'nd_experiment_id',
-  );
-  $data['nd_experiment_pub']['table']['join']['pub'] = array(
-    'left_field' => 'pub_id',
-    'field' => 'pub_id',
-  );
-
-  //Join: nd_experiment => nd_experiment_stock => YYY
-  $data['nd_experiment']['table']['join']['nd_experiment_stock'] = array(
-    'left_field' => 'nd_experiment_id',
-    'field' => 'nd_experiment_id',
-  );  
-  $data['nd_experiment']['table']['join']['stock'] = array(
-    'left_table' => 'nd_experiment_stock',
-    'left_field' => 'nd_experiment_id',
-    'field' => 'nd_experiment_id',
-  );
-  $data['nd_experiment_stock']['table']['join']['stock'] = array(
-    'left_field' => 'stock_id',
-    'field' => 'stock_id',
-  );
-
-  //Table Field Definitions----------------------------------
-      
-  //Field: nd_experiment_id (primary key)
-  $data['nd_experiment']['nd_experiment_id'] = array(
-    'title' => t('ND Experiment Primary Key'),
-    'help' => t('A unique index for every nd_experiment.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-    
-  return $data;
-}

+ 0 - 127
tripal_natural_diversity/views/nd_experimentprop.views.inc

@@ -1,127 +0,0 @@
-<?php
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_natural_diversity.views.inc --in tripal_natural_diversity_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the nd_experimentprop table, it's fields and any joins between it and other tables
- * @see tripal_natural_diversity_views_data() --in tripal_natural_diversity.views.inc
- *
- * Table: nd_experimentprop
- * @code
- * nd_experimentprop-Copy/Paste Table SQL code here-nd_experimentprop
- * @endcode
- */
- function retrieve_nd_experimentprop_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-----------------------------------
-  $data['nd_experimentprop']['table'] = array(
-    'group' => t('Chado ND Experiment Properties'),
-    'field' => 'nd_experimentprop_id',
-    'title' => t('Chado ND Experiment Property'),
-    'help' => t('Properties of a given Natural Diversity Experiment.'),
-  );
-  if($database){
-     $data['nd_experimentprop']['table']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: nd_experimentprop => nd_experiment
-  $data['nd_experimentprop']['table']['join']['nd_experiment'] = array(
-    'left_field' => 'nd_experiment_id',
-    'field' => 'nd_experiment_id',
-  );
-  
-  //Table Field Definitions----------------------------------
-      
-  //Field: nd_experimentprop_id (primary key)
-  $data['nd_experimentprop']['nd_experimentprop_id'] = array(
-    'title' => t('ND Experiment Property Primary Key'),
-    'help' => t('A unique index for every nd_experimentprop.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: value (varchar 255)   
-  $data['nd_experimentprop']['value'] = array(
-    'title' => t('Property Value'),
-    'help' => t('The value of a given property.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: rank (int)   
-  $data['nd_experimentprop']['rank'] = array(
-    'title' => t('Property Rank'),
-    'help' => t('The rank of a given propery.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Calculated Field: type/cvterm name (varchar 255)   
-  $data['nd_experimentprop']['nd_experimentprop_cvterm_name'] = array(
-    'title' => t('Property Type'),
-    'help' => t('The type of property.'),
-    'field' => array(
-      'handler' => 'views_handler_field_cvterm_name',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );  
-  
-  return $data;
-}

+ 0 - 161
tripal_natural_diversity/views/nd_geolocation.views.inc

@@ -1,161 +0,0 @@
-<?php
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_natural_diversity.views.inc --in tripal_natural_diversity_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the nd_geolocation table, it's fields and any joins between it and other tables
- * @see tripal_natural_diversity_views_data() --in tripal_natural_diversity.views.inc
- *
- * Table: nd_geolocation
- * @code
- * nd_geolocation-Copy/Paste Table SQL code here-nd_geolocation
- * @endcode
- */
- function retrieve_nd_geolocation_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-----------------------------------
-  $data['nd_geolocation']['table']['group'] = t('Chado ND geolocation');
-  
-  $data['nd_geolocation']['table']['base'] = array(
-    'field' => 'nd_geolocation_id',
-    'title' => t('Chado Natural Diversity Geolocation'),
-    'help' => t('A listing of locations where Natural Diversity Experiments can be performed.'),
-  );
-  if($database){
-     $data['nd_geolocation']['table']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: nd_geolocation => nd_experiment
-  $data['nd_geolocation']['table']['join']['nd_experiment'] = array(
-    'left_field' => 'nd_geolocation_id',
-    'field' => 'nd_geolocation_id',
-  );  
-  
-  //Table Field Definitions----------------------------------
-      
-  //Field: nd_geolocation_id (primary key)
-  $data['nd_geolocation']['nd_geolocation_id'] = array(
-    'title' => t('ND Geolocation Primary Key'),
-    'help' => t('A unique index for every nd_geolocation.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: description (varchar 255)   
-  $data['nd_geolocation']['description'] = array(
-    'title' => t('Description'),
-    'help' => t('A short description of a given geolocation.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: latitude (real)   
-  $data['nd_geolocation']['latitude'] = array(
-    'title' => t('Latitude'),
-    'help' => t('The decimal latitude coordinate of the georeference, using positive and negative sign to indicate N and S, respectively.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: longitude (real)   
-  $data['nd_geolocation']['longitude'] = array(
-    'title' => t('Longitude'),
-    'help' => t('The decimal longitude coordinate of the georeference, using positive and negative sign to indicate E and W, respectively.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: altitude (real)   
-  $data['nd_geolocation']['altitude'] = array(
-    'title' => t('Altitude'),
-    'help' => t('The altitude (elevation) of the location in meters. If the altitude is only known as a range, this is the average, and altitude_dev will hold half of the width of the range.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: geodetic_datum (varchar 255)   
-  $data['nd_geolocation']['geodetic_datum'] = array(
-    'title' => t('Deodetic Datum'),
-    'help' => t('The geodetic system on which the geo-reference coordinates are based. For geo-references measured between 1984 and 2010, this will typically be WGS84.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-  
-    
-  return $data;
-}

+ 0 - 127
tripal_natural_diversity/views/nd_geolocationprop.views.inc

@@ -1,127 +0,0 @@
-<?php
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_natural_diversity.views.inc --in tripal_natural_diversity_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the nd_geolocationprop table, it's fields and any joins between it and other tables
- * @see tripal_natural_diversity_views_data() --in tripal_natural_diversity.views.inc
- *
- * Table: nd_geolocationprop
- * @code
- * nd_geolocationprop-Copy/Paste Table SQL code here-nd_geolocationprop
- * @endcode
- */
- function retrieve_nd_geolocationprop_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-----------------------------------
-  $data['nd_geolocationprop']['table'] = array(
-    'field' => 'nd_geolocationprop_id',
-    'title' => t('Chado ND Geolocation Properties'),
-    'help' => t('Properties of Natural Diversity Geolocations.'),
-    'group' => t('Chado ND Geolocation Properties'),
-  );
-  if($database){
-     $data['nd_geolocationprop']['table']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: nd_geolocation => nd_geolocationprop
-  $data['nd_geolocationprop']['table']['join']['nd_geolocation'] = array(
-    'left_field' => 'nd_geolocation_id',
-    'field' => 'nd_geolocation_id',
-  );
-  
-  //Table Field Definitions----------------------------------
-      
-  //Field: nd_geolocationprop_id (primary key)
-  $data['nd_geolocationprop']['field_name'] = array(
-    'title' => t('ND Geolocation Property Primary Key'),
-    'help' => t('A unique index for every ND Geolocation Property.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-  
-  //Field: value (varchar 255)   
-  $data['nd_geolocationprop']['value'] = array(
-    'title' => t('Property Value'),
-    'help' => t('The value of a given property.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: rank (int)   
-  $data['nd_geolocationprop']['rank'] = array(
-    'title' => t('Property Rank'),
-    'help' => t('The rank of a given propery.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Calculated Field: type/cvterm name (varchar 255)   
-  $data['nd_geolocationprop']['nd_geolocationprop_cvterm_name'] = array(
-    'title' => t('Property Type'),
-    'help' => t('The type of property.'),
-    'field' => array(
-      'handler' => 'views_handler_field_cvterm_name',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );  
-    
-  return $data;
-}

+ 0 - 121
tripal_natural_diversity/views/nd_reagent.views.inc

@@ -1,121 +0,0 @@
-<?php
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_natural_diversity.views.inc --in tripal_natural_diversity_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the nd_reagent table, it's fields and any joins between it and other tables
- * @see tripal_natural_diversity_views_data() --in tripal_natural_diversity.views.inc
- *
- * Table: nd_reagent
- * @code
-  CREATE TABLE nd_reagent (
-    nd_reagent_id serial PRIMARY KEY NOT NULL,
-    name character varying(80) NOT NULL,
-    type_id integer NOT NULL references cvterm (cvterm_id) on delete cascade INITIALLY DEFERRED,
-    feature_id integer
-  );
- * @endcode
- */
- function retrieve_nd_reagent_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-----------------------------------
-  $data['nd_reagent']['table']['group'] = t('Chado ND Reagent');
-  
-  $data['nd_reagent']['table']['base'] = array(
-    'field' => 'nd_reagent_id',
-    'title' => t('Chado Natural Diversity Reagent'),
-    'help' => t('Reagents used in Natural Diversity Experiments.'),
-  );
-  if($database){
-     $data['nd_reagent']['table']['base']['database'] = $database;
-  }
-   
-  //Table Field Definitions----------------------------------
-      
-  //Field: nd_reagent_id (primary key)
-  $data['nd_reagent']['nd_reagent_id'] = array(
-    'title' => t('ND Reagent Primary Key'),
-    'help' => t('A unique index for every ND Reagent.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: name (varchar 255)   
-  $data['nd_reagent']['name'] = array(
-    'title' => t('Name'),
-    'help' => t('The name of the reagent.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: type_id (foreign key)
-  // Join described in cvterm.views.inc
-  
-  //Field: feature_id (foreign key)
-  // Join described in feature.views.inc
- 
- 	//Calculated Field: stock relationships (ALL)
-	// uses a custom field handler which pulls results from the view
-	// actual query performed in chado_stock_views_views_pre_render	(&$view) -file:tripal_stock.views.inc
-	$data['nd_reagent']['all_relationships'] = array(
-  	'title' => t('All Reagent Relationships'),
-  	'help' => t('Relationships including the current reagent.'),
-  	'field' => array(
-    	'title' => t('All Relationships'),
-    	'help' => t('Display all relationships including the current reagent.'),
-    	'handler' => 'views_handler_field_chado_relationship_all',
-  	),
-	);
-
-	//Calculated Field: stock relationships
-	// uses a custom field handler which pulls results from the view
-	// actual query performed in chado_stock_views_views_pre_render	(&$view) -file:tripal_stock.views.inc
-	$data['nd_reagent']['relationships'] = array(
-    'title' => t('ND Reagent Relationships'),
-    'help' => t('Relationships including the current reagent.'),
-    'field' => array(
-      'title' => t('Relationships'),
-      'help' => t('Display a given type of relationships including the current reagent.'),
-      'handler' => 'views_handler_field_chado_relationship_by_type',
-    ),
-  );
-  return $data;
-}

+ 0 - 125
tripal_natural_diversity/views/nd_reagentprop.views.inc

@@ -1,125 +0,0 @@
-<?php
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_natural_diversity.views.inc --in tripal_natural_diversity_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the nd_reagentprop table, it's fields and any joins between it and other tables
- * @see tripal_natural_diversity_views_data() --in tripal_natural_diversity.views.inc
- *
- * Table: nd_reagentprop
- * @code
- * nd_reagentprop-Copy/Paste Table SQL code here-nd_reagentprop
- * @endcode
- */
- function retrieve_nd_reagentprop_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-----------------------------------  
-  $data['nd_reagentprop']['table'] = array(
-    'field' => 'primary_id',
-    'title' => t('Chado ND Reagent Property'),
-    'help' => t('Properties of Natural Diversity Reagents.'),
-    'group' => t('Chado ND Reagent Property'),
-  );
-  if($database){
-     $data['nd_reagentprop']['table']['database'] = $database;
-  }
-
-  //Relationship Definitions---------------------------------
-  //Join: nd_reagentprop => nd_reagent
-  $data['nd_reagentprop']['table']['join']['nd_reagent'] = array(
-    'left_field' => 'nd_reagent_id',
-    'field' => 'nd_reagent_id',
-  );
-   
-  //Table Field Definitions----------------------------------
-      
-  //Field: nd_reagentprop_id (primary key)
-  $data['nd_reagentprop']['nd_reagentprop_id'] = array(
-    'title' => t('ND Reagent Propery Primary Key'),
-    'help' => t('A unique index for every ND Reagent Property.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-  //Field: value (varchar 255)   
-  $data['nd_reagentprop']['value'] = array(
-    'title' => t('Property Value'),
-    'help' => t('The value of a given property.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: rank (int)   
-  $data['nd_reagentprop']['rank'] = array(
-    'title' => t('Property Rank'),
-    'help' => t('The rank of a given propery.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Calculated Field: type/cvterm name (varchar 255)   
-  $data['nd_reagentprop']['nd_reagentprop_cvterm_name'] = array(
-    'title' => t('Property Type'),
-    'help' => t('The type of property.'),
-    'field' => array(
-      'handler' => 'views_handler_field_cvterm_name',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );  
-    
-  return $data;
-}

+ 0 - 84
tripal_natural_diversity/views/template.node_join.views.inc

@@ -1,84 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *  - simply replace all XXX with the original chado table you want to join to it's drupal nodes.
- *    (ie: If you want to join features to their drupal nodes then XXX=feature)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_natural_diversity.views.inc:tripal_natural_diversity_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_natural_diversity.views.inc --in tripal_natural_diversity_views_data()
- *
- *  Note: All chado tables are joined to their drupal nodes through the chado_XXX linking table. 
- *        This file simply defines this linking table and joins the three tables together.
- *        No modification of XXX.views.inc is needed.
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
- 
-/**
- * Purpose: this function returns the portion of the data array 
- *   which describes the chado_XXX drupal table, it's fields and any joins between it 
- *   and other tables
- * @see tripal_natural_diversity_views_data() --in tripal_natural_diversity.views.inc
- *
- * The main need for description of this table to views is to join chado data with drupal nodes
- *
- */
-function retrieve_chado_XXX_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_XXX']['table'] = array(
-    'field' => 'nid',
-  );
-  
-  //Relationship Definitions---------------------------------
-  // Note: No joins need to be made from $data['XXX']['table']
-  
-  // Join the chado_XXX table to XXX
-  $data['chado_XXX']['table']['join']['XXX'] = array(
-  	'left_field' => 'XXX_id',
-  	'field' => 'XXX_id',
-  );
-  
-  // Join the node table to chado_XXX
-  $data['node']['table']['join']['chado_XXX'] = array(
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );
-  
-  // Join the node table to XXX
-  $data['node']['table']['join']['XXX'] = array(
-  	'left_table' => 'chado_XXX',
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );  
-
-	return $data;
-}

+ 0 - 211
tripal_natural_diversity/views/template.table_defn.views.inc

@@ -1,211 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *   - Every instance of XXX should be replaced with the name of your table
- *   - If this is a base table (you want a view where every row is a row from this table)
- *     then change $data['XXX']['table'] to $data['XXX']['table']['base'] 
- *     and $data['XXX']['table']['database'] to $data['XXX']['table']['base']['database']
- *   - Relationships between this table and others: YYY is the table you are trying to join to this
- *     one. You want to join a table to this one if this table contains a foreign key to the other
- *     table. If the join between this table and another is through a linking table
- *     (ie: library-XXX/YYY => library_feature-XY => feature-XXX/YYY) then make the join in both
- *     directions (ie: in the file XXX.views.inc and the file YYY.views.inc
- *   - Create a field definition for each field in this table using the example fields already
- *     listed. Match the type of the database field to the field definition listed below.
- *     (ie: for a text/varchar field from the database use plain_text_field below)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_natural_diversity.views.inc:tripal_natural_diversity_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_natural_diversity.views.inc --in tripal_natural_diversity_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the XXX table, it's fields and any joins between it and other tables
- * @see tripal_natural_diversity_views_data() --in tripal_natural_diversity.views.inc
- *
- * Table: XXX
- * @code
- * XXX-Copy/Paste Table SQL code here-XXX
- * @endcode
- */
- function retrieve_XXX_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-----------------------------------
-  $data['XXX']['table']['group'] = t('Chado XXX');
-  
-  $data['XXX']['table'] = array(
-    'field' => 'primary_id',
-    'title' => t('Chado XXX'),
-    'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
-  );
-  if($database){
-     $data['XXX']['table']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: YYY => XXX
-  // Notice that this relationship tells the primary table to show it's fields to the
-  // table referencing it by a foreign key and thus the relationship is from
-  // primary table to table referenceing it (ie: cvterm => feature)
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_field' => 'foreign key in YYY table',
-    'field' => 'primary key in XXX table',
-  );  
-  
-  //Join: XXX => XY => YYY
-  // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
-  // describe in both feature.views.inc and library.views.inc)
-  $data['XXX']['table']['join']['XY'] = array(
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );  
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_table' => 'XY',
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );
-  $data['XY']['table']['join']['YYY'] = array(
-    'left_field' => 'primary key in YYY table',
-    'field' => 'matching YYY key in the XY table',
-  );
-   
-  //Table Field Definitions----------------------------------
-      
-  //Field: XXX_id (primary key)
-  $data['XXX']['field_name'] = array(
-    'title' => t('XXX Primary Key'),
-    'help' => t('A unique index for every XXX.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  /*.......................................................
-   * Beginning of Example Field definitions
-   * Remove this section when done
-   */
-
-  //Field: plain_text_field (chado datatype)   
-  $data['XXX']['plain_text_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: numeric_field (chado datatype)   
-  $data['XXX']['numeric_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: boolean_field (chado datatype)   
-  $data['XXX']['boolean_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_boolean',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_boolean_operator',
-    ),
-  );
-
-  //Field: unix_timestamp (chado datatype)   
-  $data['XXX']['unix_timestamp'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_date',
-    ),
-  );
-
-  //Field: human_readable_date (chado datatype)   
-  $data['XXX']['human_readable_date'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_readble_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-  );
-   
-   /*
-    * End of Example Field definitions
-    */
-    
-  return $data;
-}

+ 32 - 12
tripal_organism/tripal_organism.views.inc

@@ -6,7 +6,7 @@
  *  chado/tripal organism tables. Supplementary functions can be found in
  *  ./views/
  *
- *  Documentation on views integration can be found at 
+ *  Documentation on views integration can be found at
  *  http://views2.logrus.com/doc/html/index.html.
  */
 
@@ -16,14 +16,12 @@
  * @ingroup tripal_organism
  */
 
-require_once('views/organism.views.inc');
-require_once('views/chado_organism.views.inc'); 
 /**
  * Implements hook_views_data()
  * Purpose: Describe chado/tripal tables & fields to views
  * @return: a data array which follows the structure outlined in the
  *   views2 documentation for this hook. Essentially, it's an array of table
- *   definitions keyed by chado/tripal table name. Each table definition 
+ *   definitions keyed by chado/tripal table name. Each table definition
  *   includes basic details about the table, fields in that table and
  *   relationships between that table and others (joins)
  *
@@ -31,17 +29,39 @@ require_once('views/chado_organism.views.inc');
  */
 function tripal_organism_views_data()  {
   $data = array();
-  
-  $data = array_merge($data, retrieve_organism_views_data());
-  $data = array_merge($data, retrieve_chado_organism_views_data());
-  
+
+  if (module_exists('tripal_views')) {
+    // Base Table
+    $tables = array(
+      'organism'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+
+    // Additional Tables
+    $tables = array(
+      'organismprop',
+      'organism_dbxref'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+  }
+
   return $data;
 }
 
 /**
  * Implements hook_views_handlers()
  * Purpose: Register all custom handlers with views
- *   where a handler describes either "the type of field", 
+ *   where a handler describes either "the type of field",
  *   "how a field should be filtered", "how a field should be sorted"
  * @return: An array of handler definitions
  *
@@ -86,7 +106,7 @@ function tripal_organism_views_data_alter(&$data) {
       ),
     );
   }
-  
+
 }
 
 /**
@@ -95,7 +115,7 @@ function tripal_organism_views_data_alter(&$data) {
  */
 function tripal_organism_views_default_views () {
   $views = array();
-  
+
   // Main default view
   // List all cvterms based on cv
   $view = new view;
@@ -375,6 +395,6 @@ function tripal_organism_views_default_views () {
     'name' => 'navigation',
   ));
   $views[$view->name] = $view;
-  
+
   return $views;
 }

+ 0 - 45
tripal_organism/views/README

@@ -1,45 +0,0 @@
-
-This directory contains all additional views code needed to integrate this module with views2.
-
-FILE/FOLDER DESCRIPTIONS
----------------------------
-<chado table name>.views.inc:
-	contains a single function retrieve_<chado table name>_views_data()
-	which describes that table to views. This function is called by
-	tripal_organism_views_data() in ../tripal_organism.views.inc.
-	For more information on the form of this data array look up the
-	views2 documentation for hook_views_data() 
-	-http://views2.logrus.com/doc/html/index.html
-	
-handlers/
-	Each file contained within this folder defines a views handler. Only custom
-	handlers are included in this folder and each must be described in 
-	hook_views_handlers() in ../tripal_organism.views.inc.
-	A views handler does one of the following:
-		1) describe the type of a field and how it should be displayed
-		2) describe a method to sort this field
-		3) describe a method to filter this field
-
-
-STANDARDS TO FOLLOW
----------------------------
-
-1. All table definition files should be named tablename.views.inc
-2. All handlers should be in a handlers sub-directory and follow the naming convention of
-   views handlers (ie: views_handler_field/filter/sort_handlername.inc )
-
-Views Table Definitions:
-- Please use the template files provided whenever you are describing a new table to views.
-   For any table in chado simply copy template.table_defn.views.inc to tablename.views.inc and 
-   follow the instructions listed at the top of the template file.
-- ONLY ONE TABLE DEFINITION PER FILE
-- To join a chado table to it's drupal node simply copy template.node_join.views.inc to 
-   basetablename.views.inc and replace all XXX with basetablename.
-   
-   NOTE: Creating the table definition file is not enough. You also need to call the 
-         retrieve_XXX_views_data() function from ../tripal_organism.views.inc:tripal_organism_views_data()
-         by adding the following line:
-            $data = array_merge($data, retrieve_XXX_views_data());
-         to the function and including the file directly above the function (blow the function 
-         header by adding:
-            require_once('views/XXX.views.inc');

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

@@ -1,99 +0,0 @@
-<?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
- *
- * @ingroup tripal_organism_views
- */
-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',
-    'group' => 'Chado Organism'
-  );
-  
-  $data['chado_organism']['nid'] = array(
-    'title' => t('Organism Node ID'),
-    'help' => t('The node ID for this organism'),
-    'field' => array(
-     	'handler' => 'views_handler_field_numeric',
- 		  'click sortable' => TRUE,
-    ),
-    'filter' => array(
-     	'handler' => 'views_handler_filter_numeric',
-    ),
-    'sort' => array(
-     	'handler' => 'views_handler_sort',
-    ),
-  );
-
-  // 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',
-  );  
-
-  // Add relationship between chado_organism and organism
-  $data['chado_organism']['organism_id'] = array(
-    'group' => 'Organism',
-    'title' => 'Organism Node',
-    'help' => 'Links Chado Organism Fields/Data to the Nodes in the current View.',
-    'real field' => 'organism_id',
-    'relationship' => array(
-      'handler' => 'views_handler_relationship',
-      'title' => t('Chado => Organism'),
-      'label' => t('Chado => Organism'),
-      'real field' => 'organism_id',
-      'base' => 'organism',
-      'base field' => 'organism_id'
-    ),
-  );
-/*
-  // Add node relationship to organism
-  $data['chado_organism']['nid'] = array(
-    'group' => 'Organism',
-    'title' => 'Organism Node',
-    'help' => 'Links Chado Organism 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;
-}

+ 0 - 17
tripal_organism/views/handlers/views_handler_field_computed_organism_nid.inc

@@ -1,17 +0,0 @@
-<?php
-
-class views_handler_field_computed_organism_nid extends views_handler_field_numeric {
-	function construct() {
-		parent::construct();
-		$this->additional_fields['organism_id'] = array('table' => 'organism', 'field' => 'organism_id');
-	}
-
-	function query() { 
-		$this->ensure_my_table();
-		$this->add_additional_fields(); 
-	}
-
-	function render($values) { 
-		return $values->organism_nid;
-	}
-} 

+ 0 - 230
tripal_organism/views/organism.views.inc

@@ -1,230 +0,0 @@
-<?php
-
-/**
- * Purpose: this function returns the portion of the data array 
- *   which describes the organism table, it's fields and any joins between it and other tables
- * @see tripal_organism_views_data() --in tripal_organism.views.inc
- *
- * @todo Add support for the following tables: organismprop, organism_dbxref
- * @todo Add join to node table within if <chado/drupal same db>; also addd if not around nid field
- *
- * BASE TABLE: organism
- * @code
- * create table organism (
- *        organism_id serial not null,
- *        primary key (organism_id),
- *        abbreviation varchar(255) null,
- *        genus varchar(255) not null,
- *        species varchar(255) not null,
- *        common_name varchar(255) null,
- *        comment text null,
- *        constraint organism_c1 unique (genus,species)
- * );
- * @endcode
- *
- * @ingroup tripal_organism_views
- */
-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
-  $data['organism']['table']['group'] = 'Chado Organism';
-  $data['organism']['table']['base'] = array(
-    'field' => 'organism_id',
-    'title' => 'Chado Organism',
-    'help' => 'Organisms existing in the Chado Database',                                                                                                                                                                          
-  );
-  if($database){
-     $data['organism']['table']['base']['database'] = $database;
-  }
-
-  // Define relationships between this table and others
-  $data['organism']['table']['join'] = array(
-    'feature' => array(
-      'left_field' => 'organism_id',
-      'field' => 'organism_id',
-    ),
-    'library' => array(
-      'left_field' => 'organism_id',
-      'field' => 'organism_id',
-    ),
-    'stock' => array(
-      'left_field' => 'organism_id',
-      'field' => 'organism_id',
-    ),
-  ); 
-
-  // Table Field Definitions----------------------
-  // Field: organism_id (primary key)
-  $data['organism']['organism_id'] = array(
-    'title' => 'Organism ID',
-    'help' => 'The primary key of the organism.',
-    'field' => array(
-       'handler' => 'views_handler_field_numeric',
-       'click sortable' => TRUE,
-      ),
-     'filter' => array(
-       'handler' => 'views_handler_filter_numeric',
-     ),
-     'sort' => array(
-       'handler' => 'views_handler_sort',
-     ),
-     'argument' => array(
-     	 'handler' => 'views_handler_argument',
-     ),
-  );
-
-  // Calculated Field: 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
-  if($database && module_exists('tripal_views')){
-	  $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',
-    	),    
-  	);
-  } else {
-    // Add relationship between chado_organism and organism
-    $data['organism']['organism_id'] = array(
-      'group' => 'Organism',
-      'title' => 'Organism Node',
-      'help' => 'Links Chado Organism Fields/Data to the Nodes in the current View.',
-      'real field' => 'organism_id',
-      'relationship' => array(
-        'handler' => 'views_handler_relationship',
-        'title' => t('Organism => Chado'),
-        'label' => t('Organism => Chado'),
-        'real field' => 'organism_id',
-        'base' => 'chado_organism',
-        'base field' => 'organism_id'
-      ),
-    );
-
-  }
-	
-  // Field: abbreviation (varchar 255)
-  $data['organism']['abbreviation'] = array(
-    'title' => 'Abbreviation',
-    'help' => 'The abbreviation of the organism name ie: A.thaliana.',
-    'field' => array(
-       'handler' => 'views_handler_field',
-       'click sortable' => TRUE,
-     ),
-     'sort' => array(
-       'handler' => 'views_handler_sort',
-     ),
-     'filter' => array(
-       'handler' => 'views_handler_filter_string',
-     ),
-     'argument' => array(
-       'handler' => 'views_handler_argument_string',
-     ),
-  );
-  // if joined to the node table add a "Link to Node" option for the field  
-  if (!$database && module_exists('tripal_views')) {
-    $data['organism']['abbreviation']['field']['handler'] = 'views_handler_field_node_optional';
-  }
-
-  // Field: genus (varchar 255)
-  $data['organism']['genus'] = array(
-    'title' => 'Genus',
-    'help' => 'The genus portion of the organism\'s scientific name',
-    'field' => array(
-       'handler' => 'views_handler_field',
-       'click sortable' => TRUE,
-     ),
-     'sort' => array(
-       'handler' => 'views_handler_sort',
-     ),
-     'filter' => array(
-       'handler' => 'views_handler_filter_string',
-     ),
-     'argument' => array(
-       'handler' => 'views_handler_argument_string',
-     ),
-  );
-
-  // Field: species (varchar 255)
-  $data['organism']['species'] = array(
-    'title' => 'Species',
-    'help' => 'The species portion of the organism\'s scientific name',
-    'field' => array(
-       'handler' => 'views_handler_field',
-       'click sortable' => TRUE,
-     ),
-     'sort' => array(
-       'handler' => 'views_handler_sort',
-     ),
-     'filter' => array(
-       'handler' => 'views_handler_filter_string',
-     ),
-     'argument' => array(
-       'handler' => 'views_handler_argument_string',
-     ),
-  );
-
-  // Field: common name (varchar 255)
-  $data['organism']['common_name'] = array(
-    'title' => 'Common Name',
-    'help' => 'The common name of the organism.',
-    'field' => array(
-       'handler' => 'views_handler_field',
-       'click sortable' => TRUE,
-     ),
-     'sort' => array(
-       'handler' => 'views_handler_sort',
-     ),
-     'filter' => array(
-       'handler' => 'views_handler_filter_string',
-     ),
-     'argument' => array(
-       'handler' => 'views_handler_argument_string',
-     ),
-  );
-  // if joined to the node table add a "Link to Node" option for the field  
-  if (!$database && module_exists('tripal_views')) {
-    $data['organism']['common_name']['field']['handler'] = 'views_handler_field_node_optional';
-  }
-
-  // Field: Comment (text)
-  $data['organism']['comment'] = array(
-    'title' => 'Comment',
-    'help' => 'A free-text comment about the organism',
-    'field' => array(
-       'handler' => 'views_handler_field',
-       'click sortable' => TRUE,
-     ),
-     'filter' => array(
-       'handler' => 'views_handler_filter_string',
-     ),
-     'argument' => array(
-       'handler' => 'views_handler_argument_string',
-     ),
-  );
-  
-  //Calculated Field: Count (Int)
-  // Provides the number of features for a given organism
-  // @see tripal_feature/views/misc_tables.views.inc
-
-  //Calculated Field: Count (Int)
-  // Provides the number of stocks for a given organism
-  // @see tripal_stock/views/misc_tables.views.inc
-
-  //Calculated Field: Number of Libraries (Count -Int)
-  // Provides the number of libraries for a given organism
-  // @see tripal_library/views/misc_tables.views.inc
-
-  return $data;
-
-}

+ 0 - 84
tripal_organism/views/template.node_join.views.inc

@@ -1,84 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *  - simply replace all XXX with the original chado table you want to join to it's drupal nodes.
- *    (ie: If you want to join features to their drupal nodes then XXX=feature)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_organism.views.inc:tripal_organism_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_organism.views.inc --in tripal_organism_views_data()
- *
- *  Note: All chado tables are joined to their drupal nodes through the chado_XXX linking table. 
- *        This file simply defines this linking table and joins the three tables together.
- *        No modification of XXX.views.inc is needed.
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
- 
-/**
- * Purpose: this function returns the portion of the data array 
- *   which describes the chado_XXX 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_XXX_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_XXX']['table'] = array(
-    'field' => 'nid',
-  );
-  
-  //Relationship Definitions---------------------------------
-  // Note: No joins need to be made from $data['XXX']['table']
-  
-  // Join the chado_XXX table to XXX
-  $data['chado_XXX']['table']['join']['XXX'] = array(
-  	'left_field' => 'XXX_id',
-  	'field' => 'XXX_id',
-  );
-  
-  // Join the node table to chado_XXX
-  $data['node']['table']['join']['chado_XXX'] = array(
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );
-  
-  // Join the node table to XXX
-  $data['node']['table']['join']['XXX'] = array(
-  	'left_table' => 'chado_XXX',
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );  
-
-	return $data;
-}

+ 0 - 211
tripal_organism/views/template.table_defn.views.inc

@@ -1,211 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *   - Every instance of XXX should be replaced with the name of your table
- *   - If this is a base table (you want a view where every row is a row from this table)
- *     then change $data['XXX']['table'] to $data['XXX']['table']['base'] 
- *     and $data['XXX']['table']['database'] to $data['XXX']['table']['base']['database']
- *   - Relationships between this table and others: YYY is the table you are trying to join to this
- *     one. You want to join a table to this one if this table contains a foreign key to the other
- *     table. If the join between this table and another is through a linking table
- *     (ie: library-XXX/YYY => library_feature-XY => feature-XXX/YYY) then make the join in both
- *     directions (ie: in the file XXX.views.inc and the file YYY.views.inc
- *   - Create a field definition for each field in this table using the example fields already
- *     listed. Match the type of the database field to the field definition listed below.
- *     (ie: for a text/varchar field from the database use plain_text_field below)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_organism.views.inc:tripal_organism_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_organism.views.inc --in tripal_organism_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the XXX table, it's fields and any joins between it and other tables
- * @see tripal_organism_views_data() --in tripal_organism.views.inc
- *
- * Table: XXX
- * @code
- * XXX-Copy/Paste Table SQL code here-XXX
- * @endcode
- */
- function retrieve_XXX_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-----------------------------------
-  $data['XXX']['table']['group'] = t('Chado XXX');
-  
-  $data['XXX']['table'] = array(
-    'field' => 'primary_id',
-    'title' => t('Chado XXX'),
-    'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
-  );
-  if($database){
-     $data['XXX']['table']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: YYY => XXX
-  // Notice that this relationship tells the primary table to show it's fields to the
-  // table referencing it by a foreign key and thus the relationship is from
-  // primary table to table referenceing it (ie: cvterm => feature)
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_field' => 'foreign key in YYY table',
-    'field' => 'primary key in XXX table',
-  );  
-  
-  //Join: XXX => XY => YYY
-  // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
-  // describe in both feature.views.inc and library.views.inc)
-  $data['XXX']['table']['join']['XY'] = array(
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );  
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_table' => 'XY',
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );
-  $data['XY']['table']['join']['YYY'] = array(
-    'left_field' => 'primary key in YYY table',
-    'field' => 'matching YYY key in the XY table',
-  );
-   
-  //Table Field Definitions----------------------------------
-      
-  //Field: XXX_id (primary key)
-  $data['XXX']['field_name'] = array(
-    'title' => t('XXX Primary Key'),
-    'help' => t('A unique index for every XXX.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  /*.......................................................
-   * Beginning of Example Field definitions
-   * Remove this section when done
-   */
-
-  //Field: plain_text_field (chado datatype)   
-  $data['XXX']['plain_text_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: numeric_field (chado datatype)   
-  $data['XXX']['numeric_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: boolean_field (chado datatype)   
-  $data['XXX']['boolean_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_boolean',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_boolean_operator',
-    ),
-  );
-
-  //Field: unix_timestamp (chado datatype)   
-  $data['XXX']['unix_timestamp'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_date',
-    ),
-  );
-
-  //Field: human_readable_date (chado datatype)   
-  $data['XXX']['human_readable_date'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_readble_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-  );
-   
-   /*
-    * End of Example Field definitions
-    */
-    
-  return $data;
-}

+ 23 - 0
tripal_phenotype/tripal_phenotype.views.inc

@@ -22,6 +22,29 @@
  */
 function tripal_phenotype_views_data()  {
   $data = array();
+
+  if (module_exists('tripal_views')) {
+    $tables = array(
+      'phenotype'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+        
+    $tables = array(
+      'feature_phenotype',
+      'phenotype_cvterm'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+  }
   
   return $data;
 }

+ 0 - 45
tripal_phenotype/views/README

@@ -1,45 +0,0 @@
-
-This directory contains all additional views code needed to integrate this module with views2.
-
-FILE/FOLDER DESCRIPTIONS
----------------------------
-<chado table name>.views.inc:
-	contains a single function retrieve_<chado table name>_views_data()
-	which describes that table to views. This function is called by
-	tripal_phenotype_views_data() in ../tripal_phenotype.views.inc.
-	For more information on the form of this data array look up the
-	views2 documentation for hook_views_data() 
-	-http://views2.logrus.com/doc/html/index.html
-	
-handlers/
-	Each file contained within this folder defines a views handler. Only custom
-	handlers are included in this folder and each must be described in 
-	hook_views_handlers() in ../tripal_phenotype.views.inc.
-	A views handler does one of the following:
-		1) describe the type of a field and how it should be displayed
-		2) describe a method to sort this field
-		3) describe a method to filter this field
-
-
-STANDARDS TO FOLLOW
----------------------------
-
-1. All table definition files should be named tablename.views.inc
-2. All handlers should be in a handlers sub-directory and follow the naming convention of
-   views handlers (ie: views_handler_field/filter/sort_handlername.inc )
-
-Views Table Definitions:
-- Please use the template files provided whenever you are describing a new table to views.
-   For any table in chado simply copy template.table_defn.views.inc to tablename.views.inc and 
-   follow the instructions listed at the top of the template file.
-- ONLY ONE TABLE DEFINITION PER FILE
-- To join a chado table to it's drupal node simply copy template.node_join.views.inc to 
-   basetablename.views.inc and replace all XXX with basetablename.
-   
-   NOTE: Creating the table definition file is not enough. You also need to call the 
-         retrieve_XXX_views_data() function from ../tripal_phenotype.views.inc:tripal_phenotype_views_data()
-         by adding the following line:
-            $data = array_merge($data, retrieve_XXX_views_data());
-         to the function and including the file directly above the function (blow the function 
-         header by adding:
-            require_once('views/XXX.views.inc');

+ 0 - 84
tripal_phenotype/views/template.node_join.views.inc

@@ -1,84 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *  - simply replace all XXX with the original chado table you want to join to it's drupal nodes.
- *    (ie: If you want to join features to their drupal nodes then XXX=feature)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_phenotype.views.inc:tripal_phenotype_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_phenotype.views.inc --in tripal_phenotype_views_data()
- *
- *  Note: All chado tables are joined to their drupal nodes through the chado_XXX linking table. 
- *        This file simply defines this linking table and joins the three tables together.
- *        No modification of XXX.views.inc is needed.
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
- 
-/**
- * Purpose: this function returns the portion of the data array 
- *   which describes the chado_XXX drupal table, it's fields and any joins between it 
- *   and other tables
- * @see tripal_phenotype_views_data() --in tripal_phenotype.views.inc
- *
- * The main need for description of this table to views is to join chado data with drupal nodes
- *
- */
-function retrieve_chado_XXX_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_XXX']['table'] = array(
-    'field' => 'nid',
-  );
-  
-  //Relationship Definitions---------------------------------
-  // Note: No joins need to be made from $data['XXX']['table']
-  
-  // Join the chado_XXX table to XXX
-  $data['chado_XXX']['table']['join']['XXX'] = array(
-  	'left_field' => 'XXX_id',
-  	'field' => 'XXX_id',
-  );
-  
-  // Join the node table to chado_XXX
-  $data['node']['table']['join']['chado_XXX'] = array(
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );
-  
-  // Join the node table to XXX
-  $data['node']['table']['join']['XXX'] = array(
-  	'left_table' => 'chado_XXX',
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );  
-
-	return $data;
-}

+ 0 - 211
tripal_phenotype/views/template.table_defn.views.inc

@@ -1,211 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *   - Every instance of XXX should be replaced with the name of your table
- *   - If this is a base table (you want a view where every row is a row from this table)
- *     then change $data['XXX']['table'] to $data['XXX']['table']['base'] 
- *     and $data['XXX']['table']['database'] to $data['XXX']['table']['base']['database']
- *   - Relationships between this table and others: YYY is the table you are trying to join to this
- *     one. You want to join a table to this one if this table contains a foreign key to the other
- *     table. If the join between this table and another is through a linking table
- *     (ie: library-XXX/YYY => library_feature-XY => feature-XXX/YYY) then make the join in both
- *     directions (ie: in the file XXX.views.inc and the file YYY.views.inc
- *   - Create a field definition for each field in this table using the example fields already
- *     listed. Match the type of the database field to the field definition listed below.
- *     (ie: for a text/varchar field from the database use plain_text_field below)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_phenotype.views.inc:tripal_phenotype_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_phenotype.views.inc --in tripal_phenotype_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the XXX table, it's fields and any joins between it and other tables
- * @see tripal_phenotype_views_data() --in tripal_phenotype.views.inc
- *
- * Table: XXX
- * @code
- * XXX-Copy/Paste Table SQL code here-XXX
- * @endcode
- */
- function retrieve_XXX_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-----------------------------------
-  $data['XXX']['table']['group'] = t('Chado XXX');
-  
-  $data['XXX']['table'] = array(
-    'field' => 'primary_id',
-    'title' => t('Chado XXX'),
-    'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
-  );
-  if($database){
-     $data['XXX']['table']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: YYY => XXX
-  // Notice that this relationship tells the primary table to show it's fields to the
-  // table referencing it by a foreign key and thus the relationship is from
-  // primary table to table referenceing it (ie: cvterm => feature)
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_field' => 'foreign key in YYY table',
-    'field' => 'primary key in XXX table',
-  );  
-  
-  //Join: XXX => XY => YYY
-  // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
-  // describe in both feature.views.inc and library.views.inc)
-  $data['XXX']['table']['join']['XY'] = array(
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );  
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_table' => 'XY',
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );
-  $data['XY']['table']['join']['YYY'] = array(
-    'left_field' => 'primary key in YYY table',
-    'field' => 'matching YYY key in the XY table',
-  );
-   
-  //Table Field Definitions----------------------------------
-      
-  //Field: XXX_id (primary key)
-  $data['XXX']['field_name'] = array(
-    'title' => t('XXX Primary Key'),
-    'help' => t('A unique index for every XXX.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  /*.......................................................
-   * Beginning of Example Field definitions
-   * Remove this section when done
-   */
-
-  //Field: plain_text_field (chado datatype)   
-  $data['XXX']['plain_text_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: numeric_field (chado datatype)   
-  $data['XXX']['numeric_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: boolean_field (chado datatype)   
-  $data['XXX']['boolean_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_boolean',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_boolean_operator',
-    ),
-  );
-
-  //Field: unix_timestamp (chado datatype)   
-  $data['XXX']['unix_timestamp'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_date',
-    ),
-  );
-
-  //Field: human_readable_date (chado datatype)   
-  $data['XXX']['human_readable_date'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_readble_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-  );
-   
-   /*
-    * End of Example Field definitions
-    */
-    
-  return $data;
-}

+ 25 - 9
tripal_project/tripal_project.views.inc

@@ -6,35 +6,51 @@
  *  chado/tripal_project tables. Supplementary functions can be found in
  *  ./views/
  *
- *  Documentation on views integration can be found at 
+ *  Documentation on views integration can be found at
  *  http://views2.logrus.com/doc/html/index.html.
  */
 
-require_once('views/project.views.inc');
-require_once('views/project.views.inc');
 /*************************************************************************
  * Implements hook_views_data()
  * Purpose: Describe chado/tripal tables & fields to views
  *
  * @return: a data array which follows the structure outlined in the
  *   views2 documentation for this hook. Essentially, it's an array of table
- *   definitions keyed by chado/tripal table name. Each table definition 
+ *   definitions keyed by chado/tripal table name. Each table definition
  *   includes basic details about the table, fields in that table and
  *   relationships between that table and others (joins)
  */
 function tripal_project_views_data()  {
   $data = array();
-  
-  $data = array_merge($data, retrieve_project_views_data());
-  $data = array_merge($data, retrieve_project_views_data());
-  
+
+  if (module_exists('tripal_views')) {
+    $tables = array(
+      'project'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+
+    $tables = array(
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+  }
+
   return $data;
 }
 
 /*************************************************************************
  * Implements hook_views_handlers()
  * Purpose: Register all custom handlers with views
- *   where a handler describes either "the type of field", 
+ *   where a handler describes either "the type of field",
  *   "how a field should be filtered", "how a field should be sorted"
  *
  * @return: An array of handler definitions

+ 0 - 45
tripal_project/views/README

@@ -1,45 +0,0 @@
-
-This directory contains all additional views code needed to integrate this module with views2.
-
-FILE/FOLDER DESCRIPTIONS
----------------------------
-<chado table name>.views.inc:
-	contains a single function retrieve_<chado table name>_views_data()
-	which describes that table to views. This function is called by
-	tripal_project_views_data() in ../tripal_project.views.inc.
-	For more information on the form of this data array look up the
-	views2 documentation for hook_views_data() 
-	-http://views2.logrus.com/doc/html/index.html
-	
-handlers/
-	Each file contained within this folder defines a views handler. Only custom
-	handlers are included in this folder and each must be described in 
-	hook_views_handlers() in ../tripal_project.views.inc.
-	A views handler does one of the following:
-		1) describe the type of a field and how it should be displayed
-		2) describe a method to sort this field
-		3) describe a method to filter this field
-
-
-STANDARDS TO FOLLOW
----------------------------
-
-1. All table definition files should be named tablename.views.inc
-2. All handlers should be in a handlers sub-directory and follow the naming convention of
-   views handlers (ie: views_handler_field/filter/sort_handlername.inc )
-
-Views Table Definitions:
-- Please use the template files provided whenever you are describing a new table to views.
-   For any table in chado simply copy template.table_defn.views.inc to tablename.views.inc and 
-   follow the instructions listed at the top of the template file.
-- ONLY ONE TABLE DEFINITION PER FILE
-- To join a chado table to it's drupal node simply copy template.node_join.views.inc to 
-   basetablename.views.inc and replace all XXX with basetablename.
-   
-   NOTE: Creating the table definition file is not enough. You also need to call the 
-         retrieve_XXX_views_data() function from ../tripal_project.views.inc:tripal_project_views_data()
-         by adding the following line:
-            $data = array_merge($data, retrieve_XXX_views_data());
-         to the function and including the file directly above the function (blow the function 
-         header by adding:
-            require_once('views/XXX.views.inc');

+ 0 - 98
tripal_project/views/chado_project.views.inc

@@ -1,98 +0,0 @@
-<?php
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_project.views.inc --in tripal_project_views_data()
- *
- *  Note: All chado tables are joined to their drupal nodes through the chado_project linking table. 
- *        This file simply defines this linking table and joins the three tables together.
- *        No modification of project.views.inc is needed.
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
- 
-/**
- * Purpose: this function returns the portion of the data array 
- *   which describes the chado_project drupal table, it's fields and any joins between it 
- *   and other tables
- * @see tripal_project_views_data() --in tripal_project.views.inc
- *
- * The main need for description of this table to views is to join chado data with drupal nodes
- *
- */
-function retrieve_chado_project_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_project']['table'] = array(
-    'field' => 'nid',
-  );
-  
-  //Relationship Definitions---------------------------------
-  // Note: No joins need to be made from $data['project']['table']
-  
-  // Join the chado_project table to project
-  $data['chado_project']['table']['join']['project'] = array(
-  	'left_field' => 'project_id',
-  	'field' => 'project_id',
-  );
-  
-  // Join the node table to chado_project
-  $data['node']['table']['join']['chado_project'] = array(
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );
-  
-  // Join the node table to project
-  $data['node']['table']['join']['project'] = array(
-  	'left_table' => 'chado_project',
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );  
-
-  // Add relationship between chado_project and project
-  $data['chado_project']['project_nid'] = array(
-    'group' => 'project',
-    'title' => 'Project Node',
-    'help' => 'Links Chado project Fields/Data to the Nodes in the current View.',
-    'real field' => 'project_id',
-    'relationship' => array(
-      'handler' => 'views_handler_relationship',
-      'title' => t('Chado => Project'),
-      'label' => t('Chado => Project'),
-      'real field' => 'project_id',
-      'base' => 'project',
-      'base field' => 'project_id'
-    ),
-  );
-
-  // Add node relationship to project
-  $data['chado_project']['project_chado_nid'] = array(
-    'group' => 'project',
-    'title' => 'Project Node',
-    'help' => 'Links Chado project 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;
-}

+ 0 - 251
tripal_project/views/project.views.inc

@@ -1,251 +0,0 @@
-<?php
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_project.views.inc --in tripal_project_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the project table, it's fields and any joins between it and other tables
- * @see tripal_project_views_data() --in tripal_project.views.inc
- *
- * Table: project
- * @code
- * project-Copy/Paste Table SQL code here-project
- * @endcode
- */
- function retrieve_project_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-----------------------------------
-  $data['project']['table']['group'] = t('Chado Project');
-  
-  $data['project']['table']['base'] = array(
-    'field' => 'project_id',
-    'title' => t('Chado Project'),
-    'help' => t('Another way of grouping chado content together.'),
-  );
-  if($database){
-     $data['project']['table']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: YYY => project
-  // Notice that this relationship tells the primary table to show it's fields to the
-  // table referencing it by a foreign key and thus the relationship is from
-  // primary table to table referenceing it (ie: cvterm => feature)
-  /**
-  $data['project']['table']['join']['YYY'] = array(
-    'left_field' => 'foreign key in YYY table',
-    'field' => 'primary key in project table',
-  ); 
-  */
-  
-  //Join: project => XY => YYY
-  // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
-  // describe in both feature.views.inc and library.views.inc)
-  /**
-  $data['project']['table']['join']['XY'] = array(
-    'left_field' => 'matching project key in the XY table',
-    'field' => 'primary key in project table',
-  );  
-  $data['project']['table']['join']['YYY'] = array(
-    'left_table' => 'XY',
-    'left_field' => 'matching project key in the XY table',
-    'field' => 'primary key in project table',
-  );
-  $data['XY']['table']['join']['YYY'] = array(
-    'left_field' => 'primary key in YYY table',
-    'field' => 'matching YYY key in the XY table',
-  );
-  */
-   
-  //Table Field Definitions----------------------------------
-      
-  //Field: project_id (primary key)
-  $data['project']['project_id'] = array(
-    'title' => t('Project Primary Key'),
-    'help' => t('A unique index for every project.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  // Calculated Field: 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
-	if ($database){
-
-  } else {
-    // Add relationship between chado_project and project
-    $data['project']['project_nid'] = array(
-      'group' => 'project',
-      'title' => 'project Node',
-      'help' => 'Links Chado project Fields/Data to the Nodes in the current View.',
-      'real field' => 'project_id',
-      'relationship' => array(
-        'handler' => 'views_handler_relationship',
-        'title' => t('project => Chado'),
-        'label' => t('project => Chado'),
-        'real field' => 'project_id',
-        'base' => 'chado_project',
-        'base field' => 'project_id'
-      ),
-    );
-
-  }
-  //Field: name (varchar -255)   
-  $data['project']['name'] = array(
-    'title' => t('Name'),
-    'help' => t('The name of the project.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-  // if joined to the node table add a "Link to Node" option for the field  
-  if (!$database) {
-    $data['project']['name']['field']['handler'] = 'views_handler_field_node_optional';
-  }
-  
-  //Field: description (varchar -255)   
-  $data['project']['description'] = array(
-    'title' => t('Description'),
-    'help' => t('A short description of the project'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-  
-  /*.......................................................
-   * Beginning of Example Field definitions
-   * Remove this section when done
-
-  //Field: plain_text_field (chado datatype)   
-  $data['project']['plain_text_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: numeric_field (chado datatype)   
-  $data['project']['numeric_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: boolean_field (chado datatype)   
-  $data['project']['boolean_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_boolean',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_boolean_operator',
-    ),
-  );
-
-  //Field: unix_timestamp (chado datatype)   
-  $data['project']['unix_timestamp'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_date',
-    ),
-  );
-
-  //Field: human_readable_date (chado datatype)   
-  $data['project']['human_readable_date'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_readble_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-  );
-   
-    * End of Example Field definitions
-    */
-    
-  return $data;
-}

+ 0 - 84
tripal_project/views/template.node_join.views.inc

@@ -1,84 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *  - simply replace all XXX with the original chado table you want to join to it's drupal nodes.
- *    (ie: If you want to join features to their drupal nodes then XXX=feature)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_project.views.inc:tripal_project_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_project.views.inc --in tripal_project_views_data()
- *
- *  Note: All chado tables are joined to their drupal nodes through the chado_XXX linking table. 
- *        This file simply defines this linking table and joins the three tables together.
- *        No modification of XXX.views.inc is needed.
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
- 
-/**
- * Purpose: this function returns the portion of the data array 
- *   which describes the chado_XXX drupal table, it's fields and any joins between it 
- *   and other tables
- * @see tripal_project_views_data() --in tripal_project.views.inc
- *
- * The main need for description of this table to views is to join chado data with drupal nodes
- *
- */
-function retrieve_chado_XXX_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_XXX']['table'] = array(
-    'field' => 'nid',
-  );
-  
-  //Relationship Definitions---------------------------------
-  // Note: No joins need to be made from $data['XXX']['table']
-  
-  // Join the chado_XXX table to XXX
-  $data['chado_XXX']['table']['join']['XXX'] = array(
-  	'left_field' => 'XXX_id',
-  	'field' => 'XXX_id',
-  );
-  
-  // Join the node table to chado_XXX
-  $data['node']['table']['join']['chado_XXX'] = array(
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );
-  
-  // Join the node table to XXX
-  $data['node']['table']['join']['XXX'] = array(
-  	'left_table' => 'chado_XXX',
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );  
-
-	return $data;
-}

+ 0 - 211
tripal_project/views/template.table_defn.views.inc

@@ -1,211 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *   - Every instance of XXX should be replaced with the name of your table
- *   - If this is a base table (you want a view where every row is a row from this table)
- *     then change $data['XXX']['table'] to $data['XXX']['table']['base'] 
- *     and $data['XXX']['table']['database'] to $data['XXX']['table']['base']['database']
- *   - Relationships between this table and others: YYY is the table you are trying to join to this
- *     one. You want to join a table to this one if this table contains a foreign key to the other
- *     table. If the join between this table and another is through a linking table
- *     (ie: library-XXX/YYY => library_feature-XY => feature-XXX/YYY) then make the join in both
- *     directions (ie: in the file XXX.views.inc and the file YYY.views.inc
- *   - Create a field definition for each field in this table using the example fields already
- *     listed. Match the type of the database field to the field definition listed below.
- *     (ie: for a text/varchar field from the database use plain_text_field below)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_project.views.inc:tripal_project_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_project.views.inc --in tripal_project_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the XXX table, it's fields and any joins between it and other tables
- * @see tripal_project_views_data() --in tripal_project.views.inc
- *
- * Table: XXX
- * @code
- * XXX-Copy/Paste Table SQL code here-XXX
- * @endcode
- */
- function retrieve_XXX_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-----------------------------------
-  $data['XXX']['table']['group'] = t('Chado XXX');
-  
-  $data['XXX']['table'] = array(
-    'field' => 'primary_id',
-    'title' => t('Chado XXX'),
-    'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
-  );
-  if($database){
-     $data['XXX']['table']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: YYY => XXX
-  // Notice that this relationship tells the primary table to show it's fields to the
-  // table referencing it by a foreign key and thus the relationship is from
-  // primary table to table referenceing it (ie: cvterm => feature)
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_field' => 'foreign key in YYY table',
-    'field' => 'primary key in XXX table',
-  );  
-  
-  //Join: XXX => XY => YYY
-  // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
-  // describe in both feature.views.inc and library.views.inc)
-  $data['XXX']['table']['join']['XY'] = array(
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );  
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_table' => 'XY',
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );
-  $data['XY']['table']['join']['YYY'] = array(
-    'left_field' => 'primary key in YYY table',
-    'field' => 'matching YYY key in the XY table',
-  );
-   
-  //Table Field Definitions----------------------------------
-      
-  //Field: XXX_id (primary key)
-  $data['XXX']['field_name'] = array(
-    'title' => t('XXX Primary Key'),
-    'help' => t('A unique index for every XXX.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  /*.......................................................
-   * Beginning of Example Field definitions
-   * Remove this section when done
-   */
-
-  //Field: plain_text_field (chado datatype)   
-  $data['XXX']['plain_text_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: numeric_field (chado datatype)   
-  $data['XXX']['numeric_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: boolean_field (chado datatype)   
-  $data['XXX']['boolean_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_boolean',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_boolean_operator',
-    ),
-  );
-
-  //Field: unix_timestamp (chado datatype)   
-  $data['XXX']['unix_timestamp'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_date',
-    ),
-  );
-
-  //Field: human_readable_date (chado datatype)   
-  $data['XXX']['human_readable_date'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_readble_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-  );
-   
-   /*
-    * End of Example Field definitions
-    */
-    
-  return $data;
-}

+ 25 - 0
tripal_pub/tripal_pub.views.inc

@@ -22,6 +22,31 @@
  */
 function tripal_pub_views_data()  {
   $data = array();
+
+  if (module_exists('tripal_views')) {
+    $tables = array(
+      'pub'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+        
+    $tables = array(
+      'pub_dbxref',
+      'pub_relationship',
+      'pubauthor',
+      'pubprop'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+  }
   
   return $data;
 }

+ 0 - 45
tripal_pub/views/README

@@ -1,45 +0,0 @@
-
-This directory contains all additional views code needed to integrate this module with views2.
-
-FILE/FOLDER DESCRIPTIONS
----------------------------
-<chado table name>.views.inc:
-	contains a single function retrieve_<chado table name>_views_data()
-	which describes that table to views. This function is called by
-	tripal_pub_views_data() in ../tripal_pub.views.inc.
-	For more information on the form of this data array look up the
-	views2 documentation for hook_views_data() 
-	-http://views2.logrus.com/doc/html/index.html
-	
-handlers/
-	Each file contained within this folder defines a views handler. Only custom
-	handlers are included in this folder and each must be described in 
-	hook_views_handlers() in ../tripal_pub.views.inc.
-	A views handler does one of the following:
-		1) describe the type of a field and how it should be displayed
-		2) describe a method to sort this field
-		3) describe a method to filter this field
-
-
-STANDARDS TO FOLLOW
----------------------------
-
-1. All table definition files should be named tablename.views.inc
-2. All handlers should be in a handlers sub-directory and follow the naming convention of
-   views handlers (ie: views_handler_field/filter/sort_handlername.inc )
-
-Views Table Definitions:
-- Please use the template files provided whenever you are describing a new table to views.
-   For any table in chado simply copy template.table_defn.views.inc to tablename.views.inc and 
-   follow the instructions listed at the top of the template file.
-- ONLY ONE TABLE DEFINITION PER FILE
-- To join a chado table to it's drupal node simply copy template.node_join.views.inc to 
-   basetablename.views.inc and replace all XXX with basetablename.
-   
-   NOTE: Creating the table definition file is not enough. You also need to call the 
-         retrieve_XXX_views_data() function from ../tripal_pub.views.inc:tripal_pub_views_data()
-         by adding the following line:
-            $data = array_merge($data, retrieve_XXX_views_data());
-         to the function and including the file directly above the function (blow the function 
-         header by adding:
-            require_once('views/XXX.views.inc');

+ 0 - 84
tripal_pub/views/template.node_join.views.inc

@@ -1,84 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *  - simply replace all XXX with the original chado table you want to join to it's drupal nodes.
- *    (ie: If you want to join features to their drupal nodes then XXX=feature)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_pub.views.inc:tripal_pub_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_pub.views.inc --in tripal_pub_views_data()
- *
- *  Note: All chado tables are joined to their drupal nodes through the chado_XXX linking table. 
- *        This file simply defines this linking table and joins the three tables together.
- *        No modification of XXX.views.inc is needed.
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
- 
-/**
- * Purpose: this function returns the portion of the data array 
- *   which describes the chado_XXX drupal table, it's fields and any joins between it 
- *   and other tables
- * @see tripal_pub_views_data() --in tripal_pub.views.inc
- *
- * The main need for description of this table to views is to join chado data with drupal nodes
- *
- */
-function retrieve_chado_XXX_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_XXX']['table'] = array(
-    'field' => 'nid',
-  );
-  
-  //Relationship Definitions---------------------------------
-  // Note: No joins need to be made from $data['XXX']['table']
-  
-  // Join the chado_XXX table to XXX
-  $data['chado_XXX']['table']['join']['XXX'] = array(
-  	'left_field' => 'XXX_id',
-  	'field' => 'XXX_id',
-  );
-  
-  // Join the node table to chado_XXX
-  $data['node']['table']['join']['chado_XXX'] = array(
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );
-  
-  // Join the node table to XXX
-  $data['node']['table']['join']['XXX'] = array(
-  	'left_table' => 'chado_XXX',
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );  
-
-	return $data;
-}

+ 0 - 211
tripal_pub/views/template.table_defn.views.inc

@@ -1,211 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *   - Every instance of XXX should be replaced with the name of your table
- *   - If this is a base table (you want a view where every row is a row from this table)
- *     then change $data['XXX']['table'] to $data['XXX']['table']['base'] 
- *     and $data['XXX']['table']['database'] to $data['XXX']['table']['base']['database']
- *   - Relationships between this table and others: YYY is the table you are trying to join to this
- *     one. You want to join a table to this one if this table contains a foreign key to the other
- *     table. If the join between this table and another is through a linking table
- *     (ie: library-XXX/YYY => library_feature-XY => feature-XXX/YYY) then make the join in both
- *     directions (ie: in the file XXX.views.inc and the file YYY.views.inc
- *   - Create a field definition for each field in this table using the example fields already
- *     listed. Match the type of the database field to the field definition listed below.
- *     (ie: for a text/varchar field from the database use plain_text_field below)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_pub.views.inc:tripal_pub_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_pub.views.inc --in tripal_pub_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the XXX table, it's fields and any joins between it and other tables
- * @see tripal_pub_views_data() --in tripal_pub.views.inc
- *
- * Table: XXX
- * @code
- * XXX-Copy/Paste Table SQL code here-XXX
- * @endcode
- */
- function retrieve_XXX_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-----------------------------------
-  $data['XXX']['table']['group'] = t('Chado XXX');
-  
-  $data['XXX']['table'] = array(
-    'field' => 'primary_id',
-    'title' => t('Chado XXX'),
-    'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
-  );
-  if($database){
-     $data['XXX']['table']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: YYY => XXX
-  // Notice that this relationship tells the primary table to show it's fields to the
-  // table referencing it by a foreign key and thus the relationship is from
-  // primary table to table referenceing it (ie: cvterm => feature)
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_field' => 'foreign key in YYY table',
-    'field' => 'primary key in XXX table',
-  );  
-  
-  //Join: XXX => XY => YYY
-  // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
-  // describe in both feature.views.inc and library.views.inc)
-  $data['XXX']['table']['join']['XY'] = array(
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );  
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_table' => 'XY',
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );
-  $data['XY']['table']['join']['YYY'] = array(
-    'left_field' => 'primary key in YYY table',
-    'field' => 'matching YYY key in the XY table',
-  );
-   
-  //Table Field Definitions----------------------------------
-      
-  //Field: XXX_id (primary key)
-  $data['XXX']['field_name'] = array(
-    'title' => t('XXX Primary Key'),
-    'help' => t('A unique index for every XXX.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  /*.......................................................
-   * Beginning of Example Field definitions
-   * Remove this section when done
-   */
-
-  //Field: plain_text_field (chado datatype)   
-  $data['XXX']['plain_text_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: numeric_field (chado datatype)   
-  $data['XXX']['numeric_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: boolean_field (chado datatype)   
-  $data['XXX']['boolean_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_boolean',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_boolean_operator',
-    ),
-  );
-
-  //Field: unix_timestamp (chado datatype)   
-  $data['XXX']['unix_timestamp'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_date',
-    ),
-  );
-
-  //Field: human_readable_date (chado datatype)   
-  $data['XXX']['human_readable_date'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_readble_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-  );
-   
-   /*
-    * End of Example Field definitions
-    */
-    
-  return $data;
-}

+ 31 - 6
tripal_stock/tripal_stock.views.inc

@@ -28,15 +28,40 @@
  *
  * @ingroup tripal_stock_views
  */
-require_once('views/stock.views.inc');
-require_once('views/chado_stock.views.inc');
-require_once('views/misc_tables.views.inc');
 function tripal_stock_views_data()  {
   $data = array();
 
-  $data = array_merge($data, retrieve_stock_views_data());
-  $data = array_merge($data, retrieve_chado_stock_views_data());
-  $data = array_merge($data, retrieve_stock_misc_tables_views_data());
+  if (module_exists('tripal_views')) {
+    $tables = array(
+      'stock',
+      'stockcollection'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,TRUE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+
+    $tables = array(
+      'stock_cvterm',
+      'stock_dbxref',
+      'stock_genotype',
+      'stock_pub',
+      'stock_relationship',
+      'stock_relationship_pub',
+      'stockcollection_stock',
+      'stockcollectionprop',
+      'stockprop',
+      'stockprop_pub'
+    );
+    foreach ($tables as $tablename) {
+      if (!tripal_views_is_integrated($tablename, 10)) {
+        $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename,FALSE);
+        tripal_views_integration_add_entry($table_integration_array);
+      }
+    }
+  }
 
   return $data;
 }

+ 0 - 45
tripal_stock/views/README

@@ -1,45 +0,0 @@
-
-This directory contains all additional views code needed to integrate this module with views2.
-
-FILE/FOLDER DESCRIPTIONS
----------------------------
-<chado table name>.views.inc:
-	contains a single function retrieve_<chado table name>_views_data()
-	which describes that table to views. This function is called by
-	tripal_stock_views_data() in ../tripal_stock.views.inc.
-	For more information on the form of this data array look up the
-	views2 documentation for hook_views_data() 
-	-http://views2.logrus.com/doc/html/index.html
-	
-handlers/
-	Each file contained within this folder defines a views handler. Only custom
-	handlers are included in this folder and each must be described in 
-	hook_views_handlers() in ../tripal_stock.views.inc.
-	A views handler does one of the following:
-		1) describe the type of a field and how it should be displayed
-		2) describe a method to sort this field
-		3) describe a method to filter this field
-
-
-STANDARDS TO FOLLOW
----------------------------
-
-1. All table definition files should be named tablename.views.inc
-2. All handlers should be in a handlers sub-directory and follow the naming convention of
-   views handlers (ie: views_handler_field/filter/sort_handlername.inc )
-
-Views Table Definitions:
-- Please use the template files provided whenever you are describing a new table to views.
-   For any table in chado simply copy template.table_defn.views.inc to tablename.views.inc and 
-   follow the instructions listed at the top of the template file.
-- ONLY ONE TABLE DEFINITION PER FILE
-- To join a chado table to it's drupal node simply copy template.node_join.views.inc to 
-   basetablename.views.inc and replace all XXX with basetablename.
-   
-   NOTE: Creating the table definition file is not enough. You also need to call the 
-         retrieve_XXX_views_data() function from ../tripal_stock.views.inc:tripal_stock_views_data()
-         by adding the following line:
-            $data = array_merge($data, retrieve_XXX_views_data());
-         to the function and including the file directly above the function (blow the function 
-         header by adding:
-            require_once('views/XXX.views.inc');

+ 0 - 102
tripal_stock/views/chado_stock.views.inc

@@ -1,102 +0,0 @@
-<?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
- *
- * The main need for description of this table to views is to join chado data with drupal nodes
- *
- * @see tripal_stock_views_data() --in tripal_stock.views.inc
- *
- * @ingroup tripal_stock_views
- */
-function retrieve_chado_stock_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_stock']['table'] = array(
-    'field' => 'stock_id',
-    'group' => 'Chado Stock',
-  );
-
-  $data['chado_stock']['nid'] = array(
-    'title' => t('Stock Node ID'),
-    'help' => t('The node ID for this analysis'),
-    'field' => array(
-     	'handler' => 'views_handler_field_numeric',
- 		  'click sortable' => TRUE,
-    ),
-    'filter' => array(
-     	'handler' => 'views_handler_filter_numeric',
-    ),
-    'sort' => array(
-     	'handler' => 'views_handler_sort',
-    ),
-  );
-  
-  // Note: No joins need to be made from $data['stock']['table']
-  
-  // Join the chado stock table to stock
-  $data['chado_stock']['table']['join']['stock'] = array(
-  	'left_field' => 'stock_id',
-  	'field' => 'stock_id',
-  );
-  
-  // Join the node table to chado stock
-  $data['node']['table']['join']['chado_stock'] = array(
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );
-  
-  // Join the node table to stock
-  $data['node']['table']['join']['stock'] = array(
-  	'left_table' => 'chado_stock',
-  	'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;
-}

+ 0 - 37
tripal_stock/views/misc_tables.views.inc

@@ -1,37 +0,0 @@
-<?php
-
-/**
- * Purpose: Allows the stock module to add fields to other module views
- *
- *   For example, a field counting the number of stocks associted with a given organism would be
- *   added to the organism view as follows:
- *   @code
-      $data['organism']['num_stocks'] = array(
-        'title' => 'Number of stocks',
-        'help' => 'Provides a count of the number of stocks associated with a given organism',
-        'field' => array(
-          'handler' => 'views_handler_field_chado_count',
-          'table_to_query' => 'stock',
-        ),
-      ); 
- *   @endcode
- *
- * @ingroup tripal_stock_views
- */
-function retrieve_stock_misc_tables_views_data() {
-  $data = array();
- 
-  // Table: Organism--------------------------------------------------------------------------------
-  // Calculated Field: Number of stocks (Count -Int)
-  // Provides the number of stocks for a given organism
-  $data['organism']['num_stocks'] = array(
-    'title' => 'Number of Stocks',
-    'help' => 'Provides a count of the number of stocks associated with a given organism',
-    'field' => array(
-      'handler' => 'views_handler_field_chado_count',
-      'table_to_query' => 'stock',
-    ),
-  );  
-  
-  return $data;
-}

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

@@ -1,290 +0,0 @@
-<?php
-
-/**
- * Purpose: this function returns the portion of the data array 
- *   which describes the stock table, it's fields and any joins between it and other tables
- * @see tripal_stock_views_data() --in tripal_stock.views.inc
- *
- * @todo add better support for is_obsolete -through a field handler
- * @todo Add support for the following tables: stock_cvterm, stock_pub, stock_genotype
- * @todo Add join to node table within if <chado/drupal same db>; also addd if not around nid field
- *
- * BASE TABLE: stock
- * @code
-      create table stock (
-        stock_id serial not null,
-        primary key (stock_id),
-        dbxref_id int,
-        foreign key (dbxref_id) references dbxref (dbxref_id) on delete set null INITIALLY DEFERRED,
-        organism_id int,
-        foreign key (organism_id) references organism (organism_id) on delete cascade INITIALLY DEFERRED,
-        name varchar(255),
-        uniquename text not null,
-        description text,
-        type_id int not null,
-        foreign key (type_id) references cvterm (cvterm_id) on delete cascade INITIALLY DEFERRED,
-        is_obsolete boolean not null default 'false',
-        constraint stock_c1 unique (organism_id,uniquename,type_id)
-      );
- * @endcode
- *
- * @ingroup tripal_stock_views
- */
-function retrieve_stock_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
-  $data['stock']['table']['group'] = t('Chado Stock');
-  $data['stock']['table']['base'] = array(
-    'field' => 'stock_id',
-    'title' => t('Chado Stock'),
-    'help' => t('Chado Stocks are a record of any material upon which an experiment can be done. For example, a DNA sample, an individual or a population.'),
-  );
-  if($database){
-     $data['stock']['table']['base']['database'] = $database;
-  }
-
-	// Define relationships between this table and others
-  $data['stock']['table']['join'] = array(
-    'organism' => array(
-      'left_field' => 'organism_id',
-      'field' => 'organism_id',
-    ),
-  ); 
-
-	// Table Field Definitions----------------------
-  // Field: feature_id (primary key)
-  $data['stock']['stock_id'] = array(
-    'title' => 'Stock ID',
-    'help' => 'The primary key of a stock',
-    'field' => array(
-     	'handler' => 'views_handler_field_numeric',
- 		  'click sortable' => TRUE,
-    ),
-    'filter' => array(
-     	'handler' => 'views_handler_filter_numeric',
-    ),
-    'sort' => array(
-     	'handler' => 'views_handler_sort',
-    ),
-  );
-  
-  // Calculated Field: 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
-	if ($database){
-  	$data['stock']['stock_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_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)
-  $data['stock']['uniquename'] = array(
-    'title' => t('Unique Name'),
-    'help' => t('A unique name for this stock.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-  // if joined to the node table add a "Link to Node" option for the field  
-  if (!$database) {
-    $data['stock']['uniquename']['field']['handler'] = 'views_handler_field_node_optional';
-  }
-  
-  //Field: name (varchar 255)
-  $data['stock']['name'] = array(
-    'title' => t('Name'),
-    'help' => t('The human-readable name of this stock.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-  // if joined to the node table add a "Link to Node" option for the field  
-  if (!$database) {
-    $data['stock']['name']['field']['handler'] = 'views_handler_field_node_optional';
-  }
-  
-  //Field: description (varchar 255)
-  $data['stock']['description'] = array(
-    'title' => t('Description'),
-    'help' => t('Provides a short description for a given stock.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: is_obsolete (boolean t/f)
-  $data['stock']['is_obsolete'] = array(
-    'title' => t('Is Obsolete?'),
-    'help' => t('A yes/no field indicating whether a given stock is obsolete or not.'),
-    'field' => array(
-      'handler' => 'views_handler_field_chado_tf_boolean',
-      'click sortable' => TRUE,
-    ),
-    'filter' => array(
-       'handler' => 'views_handler_filter_chado_boolean',
-       'label' => t('Is Obsolete?'),
-       'type' => 'yes-no',    
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-  );
-
-	//Calculated Field: stock properties
-	// uses a custom field handler which pulls results from the view
-	// actual query performed in chado_stock_views_views_pre_render	(&$view) -file:tripal_stock.views.inc
-	$data['stock']['properties'] = array(
-    'title' => t('Stock Properties'),
-    'help' => t('Properties of the current stock.'),
-    'field' => array(
-      'title' => t('Properties'),
-      'help' => t('Display a given type of properties associated with a stock.'),
-      'handler' => 'views_handler_field_stockprop_by_type',
-    ),
-    'filter' => array(
-    	'title' => t('Properties'),
-    	'help' => t('Filter by a given property type or value.'),
-    	'handler' => 'views_handler_filter_stockprop_id',
-    ),
-    'argument' => array(
-    	'title' => t('Properties'),
-    	'help' => t('Allow a property to be supplied in the path'),
-    	'handler' => 'views_handler_argument_stockprop_id',
-    ),
-  );
-
-	//Calculated Field: stock properties (ALL)
-	// uses a custom field handler which pulls results from the view
-	// actual query performed in chado_stock_views_views_pre_render	(&$view) -file:tripal_stock.views.inc
-	$data['stock']['all_properties'] = array(
-  	'title' => t('All Stock Properties'),
-  	'help' => t('Properties of the current stock.'),
-  	'field' => array(
-    	'title' => t('All Properties'),
-    	'help' => t('Display all properties associated with a stock.'),
-    	'handler' => 'views_handler_field_stockprop_all',
-  	),
-	);
-	
-	//Calculated Field: stock relationships
-	// uses a custom field handler which pulls results from the view
-	// actual query performed in chado_stock_views_views_pre_render	(&$view) -file:tripal_stock.views.inc
-	$data['stock']['relationships'] = array(
-    'title' => t('Stock Relationships'),
-    'help' => t('Relationships including the current stock.'),
-    'field' => array(
-      'title' => t('Relationships'),
-      'help' => t('Display a given type of relationships including the current stock.'),
-      'handler' => 'views_handler_field_stockrel_by_type',
-    ),
-    'filter' => array(
-    	'handler' => 'views_handler_filter_stock_relationship_id'
-    ),
-  );
-
-	//Calculated Field: stock relationships (ALL)
-	// uses a custom field handler which pulls results from the view
-	// actual query performed in chado_stock_views_views_pre_render	(&$view) -file:tripal_stock.views.inc
-	$data['stock']['all_relationships'] = array(
-  	'title' => t('All Stock Relationships'),
-  	'help' => t('Relationships including the current stock.'),
-  	'field' => array(
-    	'title' => t('All Relationships'),
-    	'help' => t('Display all relationships including the stock.'),
-    	'handler' => 'views_handler_field_stockrel_all',
-  	),
-	);
-	
-	//Calculated Field: stock dbxrefs 
-	// uses a custom field handler which pulls results from the view
-	// actual query performed in chado_stock_views_views_pre_render	(&$view) -file:tripal_stock.views.inc
-	$data['stock']['dbxref'] = array(
-    'title' => t('Stock Database References'),
-    'help' => t('Database References associated with the current stock.'),
-    'field' => array(
-      'title' => t('Database References'),
-      'help' => t('Display database references from a given database for the current stock.'),
-      'handler' => 'views_handler_field_stock_dbxref_by_type',
-    ),
-    'filter' => array(
-    	'title' => t('Database References'),
-    	'help' => t('Filter by a given database reference type and/or value.'),
-    	'handler' => 'views_handler_filter_stock_dbxref_id',
-    ),
-  );
-
-	//Calculated Field: stock dbxrefs (ALL)
-	// uses a custom field handler which pulls results from the view
-	// actual query performed in chado_stock_views_views_pre_render	(&$view) -file:tripal_stock.views.inc
-	$data['stock']['all_dbxref'] = array(
-  	'title' => t('All Stock Database References'),
-  	'help' => t('Database References associated with the current stock.'),
-  	'field' => array(
-    	'title' => t('All Database References'),
-    	'help' => t('Display all database references for the current stock.'),
-    	'handler' => 'views_handler_field_stock_dbxref_all',
-  	),
-	);
-  return $data;
-}

+ 0 - 84
tripal_stock/views/template.node_join.views.inc

@@ -1,84 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *  - simply replace all XXX with the original chado table you want to join to it's drupal nodes.
- *    (ie: If you want to join features to their drupal nodes then XXX=feature)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_stock.views.inc:tripal_stock_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_stock.views.inc --in tripal_stock_views_data()
- *
- *  Note: All chado tables are joined to their drupal nodes through the chado_XXX linking table. 
- *        This file simply defines this linking table and joins the three tables together.
- *        No modification of XXX.views.inc is needed.
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
- 
-/**
- * Purpose: this function returns the portion of the data array 
- *   which describes the chado_XXX drupal table, it's fields and any joins between it 
- *   and other tables
- * @see tripal_stock_views_data() --in tripal_stock.views.inc
- *
- * The main need for description of this table to views is to join chado data with drupal nodes
- *
- */
-function retrieve_chado_XXX_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_XXX']['table'] = array(
-    'field' => 'nid',
-  );
-  
-  //Relationship Definitions---------------------------------
-  // Note: No joins need to be made from $data['XXX']['table']
-  
-  // Join the chado_XXX table to XXX
-  $data['chado_XXX']['table']['join']['XXX'] = array(
-  	'left_field' => 'XXX_id',
-  	'field' => 'XXX_id',
-  );
-  
-  // Join the node table to chado_XXX
-  $data['node']['table']['join']['chado_XXX'] = array(
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );
-  
-  // Join the node table to XXX
-  $data['node']['table']['join']['XXX'] = array(
-  	'left_table' => 'chado_XXX',
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );  
-
-	return $data;
-}

+ 0 - 211
tripal_stock/views/template.table_defn.views.inc

@@ -1,211 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *   - Every instance of XXX should be replaced with the name of your table
- *   - If this is a base table (you want a view where every row is a row from this table)
- *     then change $data['XXX']['table'] to $data['XXX']['table']['base'] 
- *     and $data['XXX']['table']['database'] to $data['XXX']['table']['base']['database']
- *   - Relationships between this table and others: YYY is the table you are trying to join to this
- *     one. You want to join a table to this one if this table contains a foreign key to the other
- *     table. If the join between this table and another is through a linking table
- *     (ie: library-XXX/YYY => library_feature-XY => feature-XXX/YYY) then make the join in both
- *     directions (ie: in the file XXX.views.inc and the file YYY.views.inc
- *   - Create a field definition for each field in this table using the example fields already
- *     listed. Match the type of the database field to the field definition listed below.
- *     (ie: for a text/varchar field from the database use plain_text_field below)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_stock.views.inc:tripal_stock_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_stock.views.inc --in tripal_stock_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the XXX table, it's fields and any joins between it and other tables
- * @see tripal_stock_views_data() --in tripal_stock.views.inc
- *
- * Table: XXX
- * @code
- * XXX-Copy/Paste Table SQL code here-XXX
- * @endcode
- */
- function retrieve_XXX_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-----------------------------------
-  $data['XXX']['table']['group'] = t('Chado XXX');
-  
-  $data['XXX']['table'] = array(
-    'field' => 'primary_id',
-    'title' => t('Chado XXX'),
-    'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
-  );
-  if($database){
-     $data['XXX']['table']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: YYY => XXX
-  // Notice that this relationship tells the primary table to show it's fields to the
-  // table referencing it by a foreign key and thus the relationship is from
-  // primary table to table referenceing it (ie: cvterm => feature)
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_field' => 'foreign key in YYY table',
-    'field' => 'primary key in XXX table',
-  );  
-  
-  //Join: XXX => XY => YYY
-  // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
-  // describe in both feature.views.inc and library.views.inc)
-  $data['XXX']['table']['join']['XY'] = array(
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );  
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_table' => 'XY',
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );
-  $data['XY']['table']['join']['YYY'] = array(
-    'left_field' => 'primary key in YYY table',
-    'field' => 'matching YYY key in the XY table',
-  );
-   
-  //Table Field Definitions----------------------------------
-      
-  //Field: XXX_id (primary key)
-  $data['XXX']['field_name'] = array(
-    'title' => t('XXX Primary Key'),
-    'help' => t('A unique index for every XXX.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  /*.......................................................
-   * Beginning of Example Field definitions
-   * Remove this section when done
-   */
-
-  //Field: plain_text_field (chado datatype)   
-  $data['XXX']['plain_text_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: numeric_field (chado datatype)   
-  $data['XXX']['numeric_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: boolean_field (chado datatype)   
-  $data['XXX']['boolean_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_boolean',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_boolean_operator',
-    ),
-  );
-
-  //Field: unix_timestamp (chado datatype)   
-  $data['XXX']['unix_timestamp'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_date',
-    ),
-  );
-
-  //Field: human_readable_date (chado datatype)   
-  $data['XXX']['human_readable_date'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_readble_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-  );
-   
-   /*
-    * End of Example Field definitions
-    */
-    
-  return $data;
-}

+ 160 - 7
tripal_views/tripal_views.api.inc

@@ -30,8 +30,44 @@ function tripal_views_get_lightest_priority_setup($table_name) {
   }
 }
 
+/** 
+ * Check to see if this table already has an integration record with the given priority
+ *
+ * @param $table_name
+ *   The name of the table to check for integration
+ * @param $priority (optional)
+ *   The priority of record to check for
+ *
+ * @return
+ *  If the table is already integrated, the setup_id of the existing integration 
+ *  record is returned (If priority is not specified this will be the lightest record);
+ *  Otherwise the table is not already integrated and FALSE is returned.
+ */
+function tripal_views_is_integrated($table_name, $priority = NULL) {
+  
+  if ($priority) {
+    $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name='%s' AND priority=%d";
+    $setup = db_fetch_object(db_query($sql, $table_name, $priority));
+  } else {
+    $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name='%s' ORDER BY priority ASC";
+    $setup = db_fetch_object(db_query($sql, $table_name));  
+  }
+  if ($setup) {
+    return $setup->setup_id;  
+  } else {
+    return FALSE;
+  }
+}
+
 /**
  * Checks if you are dealing with the lightest priority setup for a given table
+ *
+ * @param $setup_id
+ *   The ID of the setup to check (is this setup the lightest one?)
+ * @param $table_name
+ *   The name of the table associated with this setup
+ *
+ * @return TRUE is this is the lightest priority; FALSE otherwise
  */
 function tripal_views_is_lightest_priority_setup($setup_id, $table_name) {
 
@@ -62,6 +98,7 @@ function tripal_views_is_lightest_priority_setup($setup_id, $table_name) {
     'type' => 'chado', //either chado or mview depending on tablename
     'description' => 'Create a listing of features.', //description seen when creating a view of this type
     'priority' => 10, //For Base tripal modules: 10; custom modules: 9 to 0;
+    'base_table' => TRUE //either TRUE or FALSE depending on whether the current table should show up in the add view list
     'fields' => array(
       'feature_id' => array(
         'name' => 'feature_id', //field name in database
@@ -95,6 +132,7 @@ function tripal_views_integration_add_entry($defn_array) {
     'name' => $defn_array['name'],
     'comment' => $defn_array['description'],
     'priority' => $defn_array['priority'],
+    'base_table' => ($defn_array['base_table']) ? 1 : 0,
   );
   if ($defn_array['type'] == 'mview') {
       $mview = db_fetch_object(db_query("SELECT mview_id FROM {tripal_mviews} WHERE mv_table='%s'", $defn_array['table']));
@@ -103,8 +141,13 @@ function tripal_views_integration_add_entry($defn_array) {
         return FALSE;
       }
   }
-  $status = drupal_write_record('tripal_views', $view_record);
-
+  if ($view_record['name'] && $view_record['comment']) {
+    $status = drupal_write_record('tripal_views',$view_record);
+  } else {
+    $status = FALSE;
+    drupal_set_message('Unable to integrate '.$defn_array['table'].' table due to a missing name or comment field.', 'error');
+  }
+  
   if ($status) {
 
     // Insert Field Definitions
@@ -116,8 +159,13 @@ function tripal_views_integration_add_entry($defn_array) {
         'description' => $field['description'],
         'type' => $field['type'],
       );
-      $status = drupal_write_record('tripal_views_field', $field_record);
-
+      if ($view_record['setup_id'] && $field['name'] && $field['title'] && $field['description'] && $field['type']) {
+        $status = drupal_write_record('tripal_views_field',$field_record);
+      } else {
+        drupal_set_message('Unable to integrate '.$field['name'].' field due to a missing required fields.', 'error');
+        $status = FALSE;
+      }
+      
       if ($status) {
 
         // Insert Handler Definitions
@@ -129,7 +177,11 @@ function tripal_views_integration_add_entry($defn_array) {
             'handler_name' => $handler['name'],
             'arguments' => serialize($handler)
           );
-          $status = drupal_write_record('tripal_views_handlers', $handler_record);
+          if ($view_record['setup_id'] && $field['name'] && $handler_type && $handler['name'] && $handler) {
+            $status = drupal_write_record('tripal_views_handlers',$handler_record);
+          } else {
+            $status = FALSE;
+          }
           if (!$status) {
             drupal_set_message(t('Unable to integrate %handler_type handler: %handler_name', array('%handler_type' => $handler_type, '%handler_name' => $handler['name'])), 'error');
             $no_errors = FALSE;
@@ -156,7 +208,11 @@ function tripal_views_integration_add_entry($defn_array) {
             $join_record['handler'] = 'views_join';
           }
 
-          $status = drupal_write_record('tripal_views_join', $join_record);
+          if ($view_record['setup_id'] && $defn_array['table'] && $field['name'] && $join['table'] && $join['field']) {
+            $status = drupal_write_record('tripal_views_join',$join_record);
+          } else {
+            $status = FALSE;
+          }
           if (!$status) {
             drupal_set_message(
               t(
@@ -231,4 +287,101 @@ function tripal_views_integration_remove_entry_by_setup_id($setup_id) {
     db_query('DELETE FROM {tripal_views_handlers} WHERE setup_id=%d', $setup_id);
     db_query('DELETE FROM {tripal_views_join} WHERE setup_id=%d', $setup_id);
 
-}
+}
+
+/**
+ * Returns the array needed to integrate a given chado table with views
+ *
+ * @param $tablename
+ *   The table to generate the tripal views integration array for
+ * @return
+ *   The tripal views integration array which is the parameter for 
+ *   tripal_views_integration_add_entry($defn_array)
+ */
+function tripal_views_get_integration_array_for_chado_table ($table_name, $base_table = TRUE) {
+
+  // Get the schema for this table (via the chado schema api)
+  $schema = module_invoke_all('chado_'.$table_name.'_schema');
+  
+  // Base definition array
+  $defn_array = array(
+    'table' => $table_name,
+    'type' => 'chado',
+    'name' => ucwords(str_replace('_',' ',$table_name)),
+    'description' => ($schema['description']) ? $schema['description'] : ' ',
+    'priority' => 10,
+    'base_table' => $base_table,
+    'fields' => array(),
+  );
+  
+  // Add fields
+  if (!isset($schema['fields'])) { 
+    $schema['fields'] = array();
+    drupal_set_message('There are no fields defined for '.$table_name.' in the Chado Schema API.','warning');
+  }
+  foreach ($schema['fields'] as $field_name => $field_schema) {
+    
+    // Base field definition
+    if (!empty($field_name) && !empty($field_schema['type'])) {
+      $defn_array['fields'][$field_name] = array(
+        'name' => $field_name,
+        'title' => ucwords(str_replace('_',' ',$field_name)),
+        'type' => $field_schema['type'],
+        'description' => ($field_schema['description']) ? $field_schema['description'] : ' ',
+        'handlers' => array(),
+        'joins' => array()
+      );
+      
+      // Add handlers based on type
+      if (preg_match('/^int/',$field_schema['type'])) {
+        $defn_array['fields'][$field_name]['handlers'] = array(
+          'field' => array('name' => 'chado_views_handler_field_numeric'),
+          'filter' => array('name' => 'chado_views_handler_filter_numeric'),
+          'sort' => array('name' => 'chado_views_handler_sort'),
+        );
+      } elseif (preg_match('/^serial/',$field_schema['type'])) {
+        $defn_array['fields'][$field_name]['handlers'] = array(
+          'field' => array('name' => 'chado_views_handler_field_numeric'),
+          'filter' => array('name' => 'chado_views_handler_filter_numeric'),
+          'sort' => array('name' => 'chado_views_handler_sort'),
+        );
+        $defn_array['fields'][$field_name]['type'] = 'int';
+      } elseif (preg_match('/^varchar/',$field_schema['type'])) {
+        $defn_array['fields'][$field_name]['handlers'] = array(
+          'field' => array('name' => 'chado_views_handler_field'),
+          'filter' => array('name' => 'chado_views_handler_filter_string'),
+          'sort' => array('name' => 'chado_views_handler_sort'),
+        );
+      } elseif (preg_match('/^text/',$field_schema['type'])) {
+        $defn_array['fields'][$field_name]['handlers'] = array(
+          'field' => array('name' => 'chado_views_handler_field'),
+          'filter' => array('name' => 'chado_views_handler_filter_string'),
+          'sort' => array('name' => 'chado_views_handler_sort'),
+        );
+      } else {
+        $defn_array['fields'][$field_name]['handlers'] = array(
+          'field' => array('name' => 'chado_views_handler_field'),
+          'filter' => array('name' => 'chado_views_handler_filter_string'),
+          'sort' => array('name' => 'chado_views_handler_sort'),
+        );
+      }
+    }
+  }
+  
+  // Add Joins to fields
+  if (!isset($schema['foreign keys'])) {
+    $schema['foreign keys'] = array();
+    drupal_set_message('There are no foreign keys defined for '.$table_name.' in the Chado Schema API.','warning');
+  }
+  foreach ($schema['foreign keys'] as $foreign_key_schema) {
+    foreach ($foreign_key_schema['columns'] as $left_field => $right_field) {
+      $defn_array['fields'][$left_field]['joins'][ $foreign_key_schema['table'] ] = array(
+        'table' => $foreign_key_schema['table'],
+        'field' => $right_field,
+        'handler' => 'views_handler_join_chado_aggregtor'
+      );
+    }
+  }
+  
+  return $defn_array;
+}

+ 8 - 4
tripal_views/tripal_views.install

@@ -74,10 +74,14 @@ function tripal_views_update_6040() {
   // Add handler to tripal_views_join
   db_add_field($ret, 'tripal_views_join', 'handler', array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''));
 
-  // Add tripal_views_field to keep track of fields for views integration
-  $schema = tripal_views_views_schema();
-  db_create_table(&$ret, 'tripal_views_field', $schema['tripal_views_field']);
-
+	// Add tripal_views_field to keep track of fields for views integration
+	$schema = tripal_views_views_schema();
+	db_create_table(&$ret, 'tripal_views_field', $schema['tripal_views_field']);
+	
+	// Add base_table TRUE/FALSE to tripal_views
+	db_add_field($ret, 'tripal_views', 'base_table', array('type' => 'int', 'not null ' => TRUE,
+			'default' => 1));
+	
   return $ret;
 }
 

+ 69 - 50
tripal_views/tripal_views.views.inc

@@ -438,19 +438,22 @@ function tripal_views_views_data() {
     $setup_id = $tvi_row->setup_id;
     $mview_id = $tvi_row->mview_id;
 
-    // holds the base table name and fields
-    $base_table = '';
-    $base_fields = array();
-    $type_prefix = '';
-
-    // populate the base table name and fields.  If an $mview_id is given
-    // then get the materialized view info, otherwise get the Chado table info
-    if ($mview_id) {
-      $type_prefix = 'MView';
-      // get the base table name from the materialized view
-      $sql = "SELECT name, mv_specs FROM {tripal_mviews} WHERE mview_id = %d";
-      $mview_table = db_fetch_object(db_query($sql, $mview_id));
-      $base_table = $mview_table->name;
+      // holds the base table name and fields
+      $base_table = '';
+      $base_fields = array();
+      $type_prefix = '';
+      
+      // indicated whether the current table is a base table or not
+      $is_base_table = $tvi_row->base_table;
+      
+      // populate the base table name and fields.  If an $mview_id is given
+      // then get the materialized view info, otherwise get the Chado table info
+      if($mview_id){
+         $type_prefix = 'MView';
+         // get the base table name from the materialized view
+         $sql = "SELECT name, mv_specs FROM {tripal_mviews} WHERE mview_id = %d";
+         $mview_table = db_fetch_object(db_query($sql,$mview_id));
+         $base_table = $mview_table->name;
 
       // get the columns in this materialized view.  They are separated by commas
       // where the first word is the column name and the rest is the type
@@ -505,45 +508,60 @@ function tripal_views_views_data() {
       }
     }
 
-    // Setup the base table info in the data array
-    $data[$base_table]['table']['group'] = t("$type_prefix: $tvi_row->name");
-    $data[$base_table]['table']['base'] = array(
-      'group' => "$type_prefix: $tvi_row->name",
-      'title' => "$type_prefix: $tvi_row->name",
-      'help'  => $tvi_row->comment,
-    );
-    // first add the fields
-    foreach ($base_fields as $column_name => $base_field) {
-      $data[$base_table][$column_name] = array(
-        'title' => t($base_field['name']),
-        'help' => t($base_field['help']),
-        'field' => array(
-          'click sortable' => TRUE,
-        ),
-      );
-
-
-      // now add the handlers
-      $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = %d AND column_name = '%s'";
-      $handlers = db_query($sql, $setup_id, $column_name);
-      while ($handler = db_fetch_object($handlers)) {
-        $data[$base_table][$column_name][$handler->handler_type]['handler'] = $handler->handler_name;
-      };
+      // Setup the base table info in the data array
+      $data[$base_table]['table']['group'] = t("$type_prefix $tvi_row->name");
+      
+      if ($is_base_table) {
+        $data[$base_table]['table']['base'] = array(
+          'group' => "$type_prefix $tvi_row->name",
+          'title' => "$type_prefix $tvi_row->name",
+          'help'  => $tvi_row->comment,
+        );
+      } else {
+        $data[$base_table]['table'] = array(
+          'group' => "$type_prefix $tvi_row->name",
+          'title' => "$type_prefix $tvi_row->name",
+          'help'  => $tvi_row->comment,
+        );
+      }
+      
+      // first add the fields
+      foreach ($base_fields as $column_name => $base_field){
+        $data[$base_table][$column_name] = array(
+           'title' => t($base_field['name']),
+           'help' => t($base_field['help']),
+           'field' => array(
+              'click sortable' => TRUE,
+           ),
+        );
+        
+        
+        // now add the handlers
+        $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = %d AND column_name = '%s'";
+        $handlers = db_query($sql,$setup_id,$column_name);
+        while($handler = db_fetch_object($handlers)){
+           $data[$base_table][$column_name][$handler->handler_type]['handler'] = $handler->handler_name;
+        };
     }
 
-    // now add the joins
-    $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
-    $joins = db_query($sql, $setup_id);
-    while ($join = db_fetch_object($joins)) {
-      $left_table = $join->left_table;
-      $left_field = $join->left_field;
-      $base_field = $join->base_field;
-
-      // add join entry
-      $data[$base_table]['table']['join'][$left_table] = array(
-        'left_field' => $left_field,
-        'field' => $base_field,
-      );
+     // now add the joins
+     $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
+     $joins = db_query($sql,$setup_id);
+     if (!isset($joins)) { $joins = array(); }
+     while($join = db_fetch_object($joins)){               
+        $left_table = $join->left_table;
+        $left_field = $join->left_field;
+        $base_field = $join->base_field; 
+        $handler = $join->handler;
+      
+        // add join entry
+        $data[$base_table]['table']['join'][$left_table] = array(
+          'left_field' => $left_field,
+          'field' => $base_field,
+        );
+        if ($handler) {
+          $data[$base_table]['table']['join'][$left_table]['handler'] = $handler;
+        }
 
       // check to see if the join table is one that correlates with Drupal nodes
       // if so, there will be a chado_<table_name> table in the Drupal database
@@ -560,6 +578,7 @@ function tripal_views_views_data() {
 
   return $data;
 }
+
 /**
  *
  * @ingroup tripal_views

+ 157 - 86
tripal_views/tripal_views_integration.inc

@@ -69,35 +69,97 @@ function tripal_views_description_page() {
  *
  * @ingroup tripal_views_integration
  */
-function tripal_views_integration_setup_list() {
-
-  $header = array('', 'Drupal Views Type Name', 'Table Name', 'Legacy Mview', 'Priority', 'Comment', '');
-  $rows = array();
-
-  // get the list of materialized views
-  $tviews = db_query('SELECT * FROM {tripal_views} ORDER BY table_name, priority');
-  while ($tview = db_fetch_object($tviews)) {
-    $rows[] = array(
-      l(t('Edit'), "admin/tripal/views/integration/edit/" . $tview->setup_id) ,
-      $tview->name,
-      $tview->table_name,
-      ($tview->mview_id) ? 'Yes' : 'No',
-      $tview->priority,
-      $tview->comment,
-      l(t('Delete'), "admin/tripal/views/integration/delete/" . $tview->setup_id),
-    );
-  }
-  $rows[] = array(
-    'data' => array(
-      array(
-        'data' => l(t('Add a new entry'), "admin/tripal/views/integration/new") . " | " .
-                  l(t("Create View"), 'admin/build/views/add'),
-        'colspan' => 7
-      ),
-    )
-  );
-
-  return theme('table', $header, $rows);
+function tripal_views_integration_setup_list(){
+   $output = '';
+
+   $output .= '<h3>'.l('Add a new entry',"admin/tripal/views/integration/new") . " | " .
+                         l("Create Materialized View",'admin/build/views/add').'</h3>';
+                         
+   $output .= '<p>The following tables list the views integration setups available. If '
+    .'there is more then one setup for a given table, then the setup with the lightest ' 
+    .'priority will be used. For example, if you have created a custom setup for the '
+    .'feature chado table and your setup has a priority of -5 then your setup will be '
+    .'used instead of the default feature integration because -5 is lighter then 10.'
+    .'Priorities use the Drupal -10 to +10 scale where a record with -10 has a '
+    .'greater priority then one with 0 and both have a greater priority then one with +10.</p>';
+      
+   
+   // Start with materialized views           
+   $output .= '<br /><h3>Materialized Views</h3>';           
+   $header = array('', 'Drupal Views Type Name', 'Table Name', 'Is Legacy?', 'Priority', 'Comment','');
+   $rows = array();
+
+   // get the list of materialized views
+   $tviews = db_query('SELECT tv.name, tv.table_name, tc.table_id, tv.priority, tv.comment '
+   									.'FROM {tripal_views} tv '
+   									.'LEFT JOIN {tripal_custom_tables} tc ON tc.table_name=tv.table_name '
+   									.'WHERE tv.mview_id IS NOT NULL '
+   									.'ORDER BY tv.table_name ASC, tv.priority ASC');
+   while($tview = db_fetch_object($tviews)){
+         $rows[] = array(
+            l('Edit',"admin/tripal/views/integration/edit/".$tview->setup_id) ,
+            $tview->name, 
+            $tview->table_name,
+            ($tview->table_id) ? 'No' : 'Yes',  
+            $tview->priority,
+            $tview->comment,
+            l('Delete',"admin/tripal/views/integration/delete/".$tview->setup_id),
+         );         
+   }
+   
+   $output .= theme('table', $header, $rows);
+		
+	 // Now list non-mview custom tables
+   $output .= '<br /><h3>Custom Tables</h3>';           
+   $header = array('', 'Drupal Views Type Name', 'Table Name', 'Priority', 'Comment','');
+   $rows = array();
+
+   // get the list of chado tables
+   $tviews = db_query('SELECT tv.name, tv.table_name, tv.priority, tv.comment '
+   									.'FROM {tripal_views} tv '
+   									.'LEFT JOIN {tripal_custom_tables} tc ON tc.table_name=tv.table_name '
+   									.'WHERE mview_id IS NULL AND tc.table_id IS NOT NULL '
+   									.'ORDER BY table_name ASC, priority ASC');
+   while($tview = db_fetch_object($tviews)){
+         $rows[] = array(
+            l('Edit',"admin/tripal/views/integration/edit/".$tview->setup_id) ,
+            $tview->name, 
+            $tview->table_name,  
+            $tview->priority,
+            $tview->comment,
+            l('Delete',"admin/tripal/views/integration/delete/".$tview->setup_id),
+         );         
+   }
+   
+   if ($rows) {
+	   $output .= theme('table', $header, $rows);
+	 } else {
+	   $output .= '<p>There are currently no non-Materialized View Custom Tables defined.</p>';
+	 }
+   // Now list chado tables
+   $output .= '<br /><h3>Chado Tables</h3>';           
+   $header = array('', 'Drupal Views Type Name', 'Table Name', 'Priority', 'Comment','');
+   $rows = array();
+
+   // get the list of chado tables
+   $tviews = db_query('SELECT tv.name, tv.table_name, tv.priority, tv.comment '
+   									.'FROM {tripal_views} tv '
+   									.'LEFT JOIN {tripal_custom_tables} tc ON tc.table_name=tv.table_name '
+   									.'WHERE mview_id IS NULL AND tc.table_id IS NULL '
+   									.'ORDER BY table_name ASC, priority ASC');
+   while($tview = db_fetch_object($tviews)){
+         $rows[] = array(
+            l('Edit',"admin/tripal/views/integration/edit/".$tview->setup_id) ,
+            $tview->name, 
+            $tview->table_name,  
+            $tview->priority,
+            $tview->comment,
+            l('Delete',"admin/tripal/views/integration/delete/".$tview->setup_id),
+         );         
+   }
+   
+   $output .= theme('table', $header, $rows);
+   return $output;
 }
 
 /**
@@ -156,46 +218,56 @@ function tripal_views_integration_form(&$form_state, $setup_id = NULL) {
     $form_state['storage']['mview_id'] = $mview_id;
     $form_state['storage']['table_name'] = $table_name;
 
-    // get the default field name/description
-    $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=%d";
-    $query = db_query($sql, $setup_id);
-    $default_fields = array();
-    while ($field = db_fetch_object($query)) {
-      $default_fields[$field->column_name]['name'] = $field->name;
-      $default_fields[$field->column_name]['description'] = $field->description;
-    }
+      // get the default field name/description
+      $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=%d";
+      $query = db_query($sql,$setup_id);
+      $default_fields = array();
+      while ($field = db_fetch_object($query)) {
+        $default_fields[$field->column_name]['name'] = $field->name;
+        $default_fields[$field->column_name]['description'] = $field->description;
+      }
+      
+      // get the default join settings and handlers
+      $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
+      $query = db_query($sql,$setup_id);
+      $default_joins = array();
+      while ($join = db_fetch_object($query)){
+         $default_joins[$join->base_field]['left_table'] = $join->left_table;
+         $default_joins[$join->base_field]['left_field'] = $join->left_field;
+      }
 
-    // get the default join settings and handlers
-    $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
-    $query = db_query($sql, $setup_id);
-    $default_joins = array();
-    while ($join = db_fetch_object($query)) {
-      $default_joins[$join->base_field]['left_table'] = $join->left_table;
-      $default_joins[$join->base_field]['left_field'] = $join->left_field;
-    }
-    // get the default handlers
-    $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = %d";
-    $query = db_query($sql, $setup_id);
-    $default_handlers = array();
-    while ($handler = db_fetch_object($query)) {
-      $default_handlers[$handler->column_name][$handler->handler_type]['handler_name'] = $handler->handler_name;
-      $default_handlers[$handler->column_name][$handler->handler_type]['arguments'] = $handler->arguments;
-    }
-    // add in the setup_id for the form so we know this is an update not an insert
-    $form['setup_id'] = array(
-       '#type' => 'hidden',
-       '#value' => $setup_id,
-    );
-  }
-  // add a fieldset for the MView & Chado table selectors
-  $form['base_table_type'] = array(
-   '#type' => 'fieldset',
-   '#title' => 'Base Table',
-   '#description' => 'Please select either a materialized view or a Chado table for integration with '.
-                     'Drupal Views.  In Drupal Views terminology, the selected table becomes the "base table". '.
-                     'After you select a table from either list, the fields from that table will appear below '.
-                     'and you can specify other tables to join with and handlers.',
-  );
+      // get the default handlers
+      $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = %d";
+      $query = db_query($sql,$setup_id);
+      $default_handlers = array();
+      while ($handler = db_fetch_object($query)){
+         $default_handlers[$handler->column_name][$handler->handler_type]['handler_name'] = $handler->handler_name;
+         $default_handlers[$handler->column_name][$handler->handler_type]['arguments'] = $handler->arguments;
+      }
+      
+      // get the default join handlers
+      $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
+      $query = db_query($sql,$setup_id);
+      while ($handler = db_fetch_object($query)){
+         $default_handlers[$handler->base_field]['join']['handler_name'] = $handler->handler;
+         //$default_handlers[$handler->base_field]['join']['arguments'] = $handler->arguments;
+      }   
+      
+      // add in the setup_id for the form so we know this is an update not an insert
+      $form['setup_id'] = array(
+         '#type' => 'hidden',
+         '#value' => $setup_id,
+      );    
+   }
+   // add a fieldset for the MView & Chado table selectors
+   $form['base_table_type'] = array(
+     '#type' => 'fieldset',
+     '#title' => 'Base Table',
+     '#description' => 'Please select either a materialized view or a Chado table for integration with '.
+                       'Drupal Views.  In Drupal Views terminology, the selected table becomes the "base table". '.
+                       'After you select a table from either list, the fields from that table will appear below '.
+                       'and you can specify other tables to join with and handlers.',
+   );
 
   // build the form element for the Chado tables
   $chado_tables = tripal_core_get_chado_tables();
@@ -762,7 +834,6 @@ function tripal_views_integration_form_validate($form, &$form_state) {
   // TODO: do we need to require that a handler be set for each field and each type of handler?
 }
 
-
 /**
  * Purpose: inserts or updates the record in the tripal views integration
  *   tables.  This function is only called if validation is passed.
@@ -864,24 +935,24 @@ function tripal_views_integration_form_submit($form, &$form_state) {
     $left_table = $form_state['values']["fields_join_$table_id-$i"];
     $left_column = $form_state['values']["fields_join_column_$table_id-$i"];
 
-    if ($left_column) {
-      if ($mview_id) {
-        $base_table = $mview->mv_table;
+      if($left_column){
+         if($mview_id){
+            $base_table = $mview->mv_table;
+         } else {
+            $base_table = $table_name;
+         }
+         $view_join_record = array(
+           'setup_id' => $tripal_views_record['setup_id'],
+           'base_table' => $base_table,
+           'base_field' => $key,
+           'left_table' => $left_table,
+           'left_field' => $left_column,
+           'handler' => $form_state['values']["fields_join_handler_$table_id-$i"],
+         );
+         
+         // write the new joins to the database
+         drupal_write_record('tripal_views_join', $view_join_record);
       }
-      else {
-        $base_table = $table_name;
-      }
-      $view_join_record = array(
-        'setup_id' => $tripal_views_record['setup_id'],
-        'base_table' => $base_table,
-        'base_field' => $key,
-        'left_table' => $left_table,
-        'left_field' => $left_column,
-      );
-
-      // write the new joins to the database
-      drupal_write_record('tripal_views_join', $view_join_record);
-    }
 
     // add the hanlders
     $handlers = array('filter', 'field', 'sort', 'argument', 'join', 'relationship');

+ 0 - 0
tripal_stock/views/handlers/views_handler_argument_stockprop_id.inc → tripal_views/views/handlers/views_handler_argument_stockprop_id.inc


+ 0 - 0
tripal_natural_diversity/views/handlers/views_handler_field_chado_relationship_all.inc → tripal_views/views/handlers/views_handler_field_chado_relationship_all.inc


+ 0 - 0
tripal_natural_diversity/views/handlers/views_handler_field_chado_relationship_by_type.inc → tripal_views/views/handlers/views_handler_field_chado_relationship_by_type.inc


+ 0 - 0
tripal_stock/views/handlers/views_handler_field_computed_stock_nid.inc → tripal_views/views/handlers/views_handler_field_computed_stock_nid.inc


+ 0 - 0
tripal_stock/views/handlers/views_handler_field_stock_dbxref_all.inc → tripal_views/views/handlers/views_handler_field_stock_dbxref_all.inc


+ 0 - 0
tripal_stock/views/handlers/views_handler_field_stock_dbxref_by_type.inc → tripal_views/views/handlers/views_handler_field_stock_dbxref_by_type.inc


+ 0 - 0
tripal_stock/views/handlers/views_handler_field_stockprop_all.inc → tripal_views/views/handlers/views_handler_field_stockprop_all.inc


+ 0 - 0
tripal_stock/views/handlers/views_handler_field_stockprop_by_type.inc → tripal_views/views/handlers/views_handler_field_stockprop_by_type.inc


+ 0 - 0
tripal_stock/views/handlers/views_handler_field_stockrel_all.inc → tripal_views/views/handlers/views_handler_field_stockrel_all.inc


+ 0 - 0
tripal_stock/views/handlers/views_handler_field_stockrel_by_type.inc → tripal_views/views/handlers/views_handler_field_stockrel_by_type.inc


+ 0 - 0
tripal_stock/views/handlers/views_handler_filter_stock_dbxref_id.inc → tripal_views/views/handlers/views_handler_filter_stock_dbxref_id.inc


+ 0 - 0
tripal_stock/views/handlers/views_handler_filter_stock_relationship_id.inc → tripal_views/views/handlers/views_handler_filter_stock_relationship_id.inc


+ 0 - 0
tripal_stock/views/handlers/views_handler_filter_stockprop_id.inc → tripal_views/views/handlers/views_handler_filter_stockprop_id.inc


+ 177 - 83
tripal_views/views/handlers/views_handler_join_chado_aggregator.inc

@@ -11,7 +11,9 @@
         $data['analysisprop']['table']['join']['analysis'] = array(
           'left_field' => 'analysis_id',
           'field' => 'analysis_id',
-          'handler' => 'views_handler_join_chado_aggregator'
+          'handler' => 'views_handler_join_chado_aggregator',
+          'pre-aggregated' => TRUE | FALSE //whether the table is already aggregated (contains arrays)
+          'table_aggregated' => CURRENT | LEFT //the table which has many records for each record in the other
         );
  *   @endcode
  */
@@ -40,100 +42,176 @@ class views_handler_join_chado_aggregator extends views_join {
    */
   function join($table, &$query) {
     $output = array();
-
+    
     // Create the table SQL (used in join) -------
     // query creating one-to-one table using array_agg
-    $table_desc = module_invoke_all('chado_' . $this->definition['table'] . '_schema');
-    $select_fields[ $this->definition['table'] ] = $table_desc['fields'];
-
-    // Add joins to tables with a foreign key in this table
-    // (ie: add join to cvterm if this table has a type_id
-    $joins = array();
-    foreach ($table_desc['foreign keys'] as $defn) {
-      if ($defn['table'] != $this->left_table) {
-        foreach ( $defn['columns'] as $left => $right) {
-          $left = $this->definition['table'] .'.'. $left;
-          $right = $defn['table'] .'.'. $right;
-          $joins[] = "LEFT JOIN $defn[table] $defn[table] ON $left=$right";
-        }
-
-        // Fields to be selected from joined table
-        $join_table = module_invoke_all('chado_' . $defn['table'] . '_schema');
-        $select_fields[ $defn['table'] ] = $join_table['fields'];
+    
+    // Only aggregate each field if it the join table hadn't been pre-aggregated
+    // Example where it might be pre-aggregated: Materialized view
+    if (!$this->definition['pre-aggregated']) {
+      // Determine Order BY's for aggregates
+      $order_by = array();
+      if (!is_array($this->sort)) { $this->sort = array(); }
+      foreach ($this->sort as $s) {
+        $order_by[] = $s['table'].'.'.$s['field'].' '.$s['order'];
       }
-    }
-
-    // Determine Order BY's for aggregates
-    $order_by = array();
-    foreach ($this->sort as $s) {
-      $order_by[] = $s['table'] . '.' . $s['field'] . ' ' . $s['order'];
-    }
-
-
-    // Fields to be selected
-    foreach ($select_fields as $table => $table_fields) {
-      foreach ($table_fields as $fname => $f) {
-        $alias = '';
-        if ($table != $this->definition['table']) {
-          $alias = $table .'_';
+        
+      // get table description (if defined via schema api)
+      $table_desc = module_invoke_all('chado_'.$this->definition['table'].'_schema');
+      $select_fields[ $this->definition['table'] ] = $table_desc['fields'];
+      
+      if (!empty($table_desc)) {
+        // Add joins to tables with a foreign key in this table
+        // (ie: add join to cvterm if this table has a type_id
+        $joins = array();
+        foreach($table_desc['foreign keys'] as $defn) {
+          if ($defn['table'] != $this->left_table) {
+            foreach( $defn['columns'] as $left => $right) {
+              $left = $this->definition['table'] .'.'. $left;
+              $right = $defn[table] .'.'. $right;
+              $joins[] = "LEFT JOIN $defn[table] $defn[table] ON $left=$right";
+            }
+            
+            // Fields to be selected from joined table
+            $join_table = module_invoke_all('chado_'.$defn['table'].'_schema');
+            $select_fields[ $defn['table'] ] = $join_table['fields'];
+          } 
         }
-
-        if ($fname != $this->definition['field']) {
-          // Add sort to aggregate field if postgreSQL 9.0+
-          if ($this->postgresql_9up && !empty($order_by)) {
-            $fields[] = 'array_agg(' . $table . '.' . $fname . ' ORDER BY ' . implode(',', $order_by) . ') as ' . $alias . $fname;
+        
+        // Fields to be selected
+        foreach ($select_fields as $table => $table_fields) {
+          foreach ($table_fields as $fname => $f) {
+            $alias = '';
+            if ($table != $this->definition['table']) {
+              $alias = $table .'_';
+            }
+            
+            if ($fname != $this->definition['field']) {
+              // Add sort to aggregate field if postgreSQL 9.0+
+              if ($this->postgresql_9up && !empty($order_by)) {
+                $fields[] = 'array_agg('.$table.'.'.$fname.' ORDER BY '.implode(',',$order_by).') as '.$alias.$fname;
+              } else {
+                $fields[] = 'array_agg('.$table.'.'.$fname.') as '.$alias.$fname;
+              }
+              $composite_field_parts[] = "'".$alias.$fname."::' ||".$table.'.'.$fname;
+            } else {
+              $fields[] = $fname;
+              $composite_field_parts[] = "'".$alias.$fname."::' ||".$table.'.'.$fname;
+            }
           }
-          else {
-            $fields[] = 'array_agg(' . $table . '.' . $fname . ') as ' . $alias . $fname;
-          }
-          $composite_field_parts[] = "'" . $alias . $fname . "::' ||" . $table . '.' . $fname;
         }
-        else {
-          $fields[] = $fname;
-          $composite_field_parts[] = "'" . $alias . $fname . "::' ||" . $table . '.' . $fname;
+      
+      // There is no definition in schema api
+      // then use postgresql select
+      } else {
+        
+        // No known foreign key reelationships
+        $joins = array();
+        
+        // Fields to be selected
+        $sql = "SELECT 
+                  attname as column, 
+                  format_type(atttypid, atttypmod) as datatype 
+                FROM pg_attribute, pg_type 
+                WHERE typname='nd_genotype_experiment' 
+                  AND attrelid=typrelid 
+                  AND attname NOT IN ('cmin','cmax','ctid','oid','tableoid','xmin','xmax')";
+        $previous_db = tripal_db_set_active('chado');
+        $resource = db_query($sql);
+        tripal_db_set_active($previous_db);
+        while ($r = db_fetch_object($resource)) {
+          $table = $this->definition['table'];
+          $alias = ''; //no alias needed if table is current table (only option if no schema api definition)
+          $fname = $r->column;
+          
+          if ($fname != $this->definition['field']) {
+            // Add sort to aggregate field if postgreSQL 9.0+
+            if ($this->postgresql_9up && !empty($order_by)) {
+              $fields[] = 'array_agg('.$table.'.'.$fname.' ORDER BY '.implode(',',$order_by).') as '.$alias.$fname;
+            } else {
+              $fields[] = 'array_agg('.$table.'.'.$fname.') as '.$alias.$fname;
+            }
+            $composite_field_parts[] = "'".$alias.$fname."::' ||".$table.'.'.$fname;
+          } else {
+            $fields[] = $fname;
+            $composite_field_parts[] = "'".$alias.$fname."::' ||".$table.'.'.$fname;
+          }
         }
+        
       }
-    }
-
-    // composite field
-    // (combines all other fields before aggregating)
-    // Add sort to aggregate field if postgreSQL 9.0+
-    if ($this->postgresql_9up && !empty($order_by)) {
-      $composite_field = "array_agg('{'||" . implode(" || ',' || ", $composite_field_parts) . "||'}' ORDER BY " . implode(',', $order_by) . ") as all";
-    }
-    else {
-      $composite_field = "array_agg('{'||" . implode(" || ',' || ", $composite_field_parts) . "||'}') as all";
-    }
-    $fields[] = $composite_field;
-
-    // SQL to use in the join
-    $sql = 'SELECT ' . implode(', ', $fields)
-      .' FROM ' . $this->definition['table']
-      .' ' . implode(' ', $joins);
-
-    if (!empty($this->filter)) {
-      $sql .= ' WHERE ' . implode(', ', $this->filter);
-    }
+      
+      // composite field 
+      // (combines all other fields before aggregating)
+      // Add sort to aggregate field if postgreSQL 9.0+
+      if ($this->postgresql_9up && !empty($order_by)) {
+        $composite_field = "array_agg('{'||".implode(" || ',' || ",$composite_field_parts)."||'}' ORDER BY ".implode(',',$order_by).") as all";
+      } else {
+        $composite_field = "array_agg('{'||".implode(" || ',' || ",$composite_field_parts)."||'}') as all";
+      }
+      $fields[] = $composite_field;
+        
+      // SQL to use in the join
+      $sql = 'SELECT '.implode(', ',$fields)
+        .' FROM '.$this->definition['table']
+        .' '.implode(' ',$joins);
+   
+      if (!empty($this->filter)) {
+        $sql .= ' WHERE '.implode(', ', $this->filter);
+      }
+      
+      $sql .= ' GROUP BY '.$this->definition['field'];
+      
+      // Create the join (full SQL) ----------------
+      $output[] = $this->create_single_join(
+        $query,
+        array(
+          'table' => $this->definition['table'],
+          'field' => $this->definition['field'],
+          'table_sql' => $sql,
+          'is_drupal' => FALSE,
+        ),
+        array(
+          'table' => $this->definition['left_table'],
+          'field' => $this->definition['left_field'],
+        ),
+        'LEFT'
+      );
+    
+    // Otherwise the table has been pre-aggregated
+    // Then only need to do a regular join with any in where
+    } else {
 
-    $sql .= ' GROUP BY ' . $this->definition['field'];
+      // Create the join
 
-    // Create the join (full SQL) ----------------
-    $output[] = $this->create_single_join(
-      $query,
-      array(
+      $current_table_spec = array(
         'table' => $this->definition['table'],
         'field' => $this->definition['field'],
-        'table_sql' => $sql,
         'is_drupal' => FALSE,
-      ),
-      array(
+      );
+      $left_table_spec = array(
         'table' => $this->definition['left_table'],
         'field' => $this->definition['left_field'],
-      ),
-      'LEFT'
-    );
-
-    return implode("\n", $output);
+      );
+      
+      switch ($this->definition['table_aggregated']) {
+        default:
+        case 'CURRENT':
+          $current_table_spec['pre-aggregated'] = TRUE;
+        break;
+        case 'LEFT':
+          $left_table_spec['pre-aggregated'] = TRUE;
+        break;
+      }
+      
+      $output[] = $this->create_single_join(
+        $query,
+        $current_table_spec,
+        $left_table_spec,
+        'LEFT'
+      );
+    }
+    
+    return implode("\n",$output);
   }
 
   /**
@@ -150,6 +228,12 @@ class views_handler_join_chado_aggregator extends views_join {
       }
       $right_field = "$right[alias].$right_spec[field]";
 
+      // Add any() around field if already aggregated
+      if ($right_spec['pre-aggregated']) {
+        $right_field = "any(".$right_field.")";
+      }
+      
+      // Add drupal { } around table 
       if ($right_spec['is_drupal']) {
         $right_table = '{' . $right_spec['table'] . '}';
       }
@@ -170,9 +254,19 @@ class views_handler_join_chado_aggregator extends views_join {
       $left_field = $this->left_spec['field'];
     }
 
-    $output = " $join_type JOIN ($right_spec[table_sql]) $right[alias] ON $left_field = $right_field";
-
+    // Add any() around field if already aggregated
+    if ($left_spec['pre-aggregated']) {
+      $left_field = "any(".$left_field.")";
+    }
+    
+    // Concatenate parts together to form join sql
+    if (!empty($right_spec[table_sql])) {
+      $output = " $join_type JOIN ($right_spec[table_sql]) $right[alias] ON $left_field = $right_field";
+    } else {
+      $output = " $join_type JOIN $right_spec[table] $right[alias] ON $left_field = $right_field";
+    }
+    
     return $output;
   }
 
-}
+}