Browse Source

Added Views Integration for tripal_organism & tripal_library

laceysanderson 14 years ago
parent
commit
248c5d815c

+ 0 - 1
tripal_core/views_handlers/views_handler_field_feature_nid.inc

@@ -3,7 +3,6 @@
 class views_handler_field_feature_nid extends views_handler_field_numeric {
 	function construct() {
 		parent::construct();
-		$this->additional_fields['feature'] = 'feature_id';   
 	}
 
 	function query() { 

+ 1 - 2
tripal_core/views_handlers/views_handler_field_library_nid.inc

@@ -2,8 +2,7 @@
 
 class views_handler_field_library_nid extends views_handler_field_numeric {
  function construct() {
-   parent::construct();
-   $this->additional_fields['library_id'] = 'library_id';   
+   parent::construct(); 
  }
 
  function query() { 

+ 1 - 2
tripal_core/views_handlers/views_handler_field_organism_nid.inc

@@ -2,8 +2,7 @@
 
 class views_handler_field_organism_nid extends views_handler_field_numeric {
  function construct() {
-   parent::construct();
-   $this->additional_fields['organism_id'] = 'organism_id';   
+   parent::construct(); 
  }
 
  function query() { 

+ 0 - 1
tripal_core/views_handlers/views_handler_field_stock_nid.inc

@@ -3,7 +3,6 @@
 class views_handler_field_stock_nid extends views_handler_field_numeric {
  function construct() {
    parent::construct();
-   $this->additional_fields['stock'] = 'stock_id';   
  }
 
  function query() { 

+ 14 - 4
tripal_cv/views/cv.views.inc

@@ -38,7 +38,20 @@ function retrieve_cv_views_data() {
 
   // Table Field Definitions----------------------
   // Field: cv_id (primary key)
-  //   mentioned as index above but not displayable in a view  
+  $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(
@@ -65,9 +78,6 @@ function retrieve_cv_views_data() {
        'handler' => 'views_handler_field',
        'click sortable' => TRUE,
      ),
-     'sort' => array(
-       'handler' => 'views_handler_sort',
-     ),
      'filter' => array(
        'handler' => 'views_handler_filter_string',
      ),

+ 14 - 4
tripal_cv/views/cvterm.views.inc

@@ -52,7 +52,20 @@ function retrieve_cvterm_views_data() {
 
  // Table Field Definitions----------------------
  // Field: cvterm_id (primary key)
- //   mentioned as index above but not displayable in a view
+ $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
@@ -84,9 +97,6 @@ function retrieve_cvterm_views_data() {
        'handler' => 'views_handler_field',
        'click sortable' => TRUE,
      ),
-     'sort' => array(
-       'handler' => 'views_handler_sort',
-     ),
      'filter' => array(
        'handler' => 'views_handler_filter_string',
      ),

+ 14 - 1
tripal_db/views/db.views.inc

@@ -39,7 +39,20 @@ function retrieve_db_views_data() {
   
   // Table Field Definitions----------------------
   // Field: db_id (primary key)
-  //   mentioned as index above but not displayable in a view
+  $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(

+ 14 - 4
tripal_db/views/dbxref.views.inc

@@ -48,7 +48,20 @@ function retrieve_dbxref_views_data() {
 
   // Table Field Definitions----------------------
   // Field: dbxref_id (primary key)
-  //   mentioned as index above but not displayable in a view
+  $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
@@ -99,9 +112,6 @@ function retrieve_dbxref_views_data() {
       'handler' => 'views_handler_field',
       'click sortable' => TRUE,
     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
     'filter' => array(
       'handler' => 'views_handler_filter_string',
     ),

+ 13 - 0
tripal_library/tripal_library.module

@@ -123,6 +123,19 @@ function tripal_library_menu() {
 
    return $items;
 }
+
+/*************************************************************************
+ * Implements hook_views_api()
+ * Purpose: Essentially this hook tells drupal that there is views support for
+ *  for this module which then includes tripal_db.views.inc where all the
+ *  views integration code is
+ */ 
+function tripal_library_views_api() {
+   return array(
+      'api' => 2.0,
+   );
+}
+
 /*******************************************************************************
  * Dynamic addition/removal of menu item
  */

+ 83 - 0
tripal_library/tripal_library.views.inc

@@ -0,0 +1,83 @@
+<?php
+
+/**
+ *  @file
+ *  This file contains the basic functions for views integration of
+ *  chado/tripal organism tables. Supplementary functions can be found in
+ *  ./views/
+ *
+ *  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 
+ *   includes basic details about the table, fields in that table and
+ *   relationships between that table and others (joins)
+ */
+require_once('views/library.views.inc');
+function tripal_library_views_data()  {
+  $data = array();
+  
+  $data = array_merge($data, retrieve_library_views_data());
+  
+  return $data;
+}
+
+/*************************************************************************
+ * Implements hook_views_handlers()
+ * Purpose: Register all custom handlers with views
+ *   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
+ */
+function tripal_library_views_handlers() {
+ return array(
+   'info' => array(
+     'path' => drupal_get_path('module', 'tripal_library') . '/views/handlers',
+   ),
+   'handlers' => array(
+     'views_handler_field_library_nid' => array(
+       'parent' => 'views_handler_field_numeric',
+     ),
+     'views_handler_field_tf_boolean' => array(
+       'parent' => 'views_handler_field',
+     ),
+     'views_handler_field_readable_date' => array(
+       'parent' => 'views_handler_field',
+     ),
+   ),
+ );
+}
+
+/**
+ * Implements hook_views_pre_render
+ * Purpose: Intercepts the view after the query has been executed
+ *   All the results are stored in $view->result
+ *   Looking up the NID here ensures the query is only executed once
+ *   for all features in the table.
+ */
+function tripal_library_views_pre_render	(&$view) {
+	if (preg_match('/library/', $view->base_table)) {
+		
+		// retrieve the library_id for each record in the views current page
+		$library_ids = array();
+		foreach ($view->result as $row_num => $row) {
+			$library_ids[$row_num] = $row->library_id;
+		}
+
+		// Using the list of library_ids from the view
+		// lookup the NIDs from drupal
+		// and add that to the results of the view
+		$sql = "SELECT nid, library_id FROM chado_library WHERE library_id IN (".implode(',',$library_ids).")";
+		$resource = db_query($sql);
+		while ($r = db_fetch_object($resource)) {
+			$key = array_search($r->library_id, $library_ids);
+			$view->result[$key]->nid = $r->nid;
+		}
+	}
+}

+ 22 - 0
tripal_library/views/README

@@ -0,0 +1,22 @@
+This folder contains all supplementary code needed for views integration
+of the chado library and related tables.
+
+File 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 module>_views_data() in ../<tripal module>.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/
+	A folder which contains symbolic links to tripal_core/views_handlers/ files.
+	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 module>.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

+ 1 - 0
tripal_library/views/handlers/views_handler_field_library_nid.inc

@@ -0,0 +1 @@
+../../../tripal_core/views_handlers/views_handler_field_library_nid.inc

+ 1 - 0
tripal_library/views/handlers/views_handler_field_readable_date.inc

@@ -0,0 +1 @@
+../../../tripal_core/views_handlers/views_handler_field_readable_date.inc

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

@@ -0,0 +1,168 @@
+<?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
+ *
+ * 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
+ */
+function retrieve_library_views_data() {
+  
+  // 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',                                                                                                                                                                          
+	  'database' => 'chado'
+	);
+	
+	// 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' => 'feature_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',
+	  ),
+	  'library' => array(
+	    'left_field' => 'library_id',
+	    'field' => 'library_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',
+	  ),
+	);
+	
+	// Field: Node ID (foreign key)
+	$data['library']['nid'] = array(
+	  'title' => 'Node ID',
+	  'help' => 'The node ID for the current library',
+	  'field' => array(
+	    'handler' => 'views_handler_field_library_nid',
+	  ),
+	);
+	
+	// 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_string',
+	  ),
+	  'argument' => array(
+	    'handler' => 'views_handler_argument_string',
+	  ),
+	);
+	
+	// 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',
+	  ),
+	);
+	
+	// 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_boolean_operator',
+	    '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;
+	
+}

+ 6 - 5
tripal_organism/tripal_organism.module

@@ -1033,13 +1033,14 @@ function tripal_organisms_cleanup($dummy = NULL, $job_id = NULL) {
    return '';
 }
 
-/*******************************************************************************
- *  This function customizes the field for the VIEWS module
- */
-   
+/*************************************************************************
+ * Implements hook_views_api()
+ * Purpose: Essentially this hook tells drupal that there is views support for
+ *  for this module which then includes tripal_db.views.inc where all the
+ *  views integration code is
+ */ 
 function tripal_organism_views_api() {
    return array(
       'api' => 2.0,
-      'path' => drupal_get_path('module', 'tripal_organism') . '/views'
    );
 }

+ 77 - 0
tripal_organism/tripal_organism.views.inc

@@ -0,0 +1,77 @@
+<?php
+
+/**
+ *  @file
+ *  This file contains the basic functions for views integration of
+ *  chado/tripal organism tables. Supplementary functions can be found in
+ *  ./views/
+ *
+ *  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 
+ *   includes basic details about the table, fields in that table and
+ *   relationships between that table and others (joins)
+ */
+require_once('views/organism.views.inc');
+function tripal_organism_views_data()  {
+  $data = array();
+  
+  $data = array_merge($data, retrieve_organism_views_data());
+  
+  return $data;
+}
+
+/*************************************************************************
+ * Implements hook_views_handlers()
+ * Purpose: Register all custom handlers with views
+ *   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
+ */
+function tripal_organism_views_handlers() {
+ return array(
+   'info' => array(
+     'path' => drupal_get_path('module', 'tripal_organism') . '/views/handlers',
+   ),
+   'handlers' => array(
+     'views_handler_field_organism_nid' => array(
+       'parent' => 'views_handler_field_numeric',
+     ),
+   ),
+ );
+}
+
+/**
+ * Implements hook_views_pre_render
+ * Purpose: Intercepts the view after the query has been executed
+ *   All the results are stored in $view->result
+ *   Looking up the NID here ensures the query is only executed once
+ *   for all organisms in the table.
+ */
+function tripal_organism_views_pre_render	(&$view) {
+	if (preg_match('/organism/', $view->base_table)) {
+		
+		// retrieve the organism_id for each record in the views current page
+		$organism_ids = array();
+		foreach ($view->result as $row_num => $row) {
+			$organism_ids[$row_num] = $row->organism_id;
+		}
+
+		// Using the list of organism_ids from the view
+		// lookup the NIDs from drupal
+		// and add that to the results of the view
+		$sql = "SELECT nid, organism_id FROM chado_organism WHERE organism_id IN (".implode(',',$organism_ids).")";
+		$resource = db_query($sql);
+		while ($r = db_fetch_object($resource)) {
+			$key = array_search($r->organism_id, $organism_ids);
+			$view->result[$key]->nid = $r->nid;
+		}
+	}
+}

+ 22 - 0
tripal_organism/views/README

@@ -0,0 +1,22 @@
+This folder contains all supplementary code needed for views integration
+of the chado organism and related tables.
+
+File 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 module>_views_data() in ../<tripal module>.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/
+	A folder which contains symbolic links to tripal_core/views_handlers/ files.
+	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 module>.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

+ 1 - 0
tripal_organism/views/handlers/views_handler_field_organism_nid.inc

@@ -0,0 +1 @@
+../../../tripal_core/views_handlers/views_handler_field_organism_nid.inc

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

@@ -0,0 +1,171 @@
+<?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
+ *
+ * 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
+ */
+function retrieve_organism_views_data() {
+
+  // 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',                                                                                                                                                                          
+    'database' => 'chado'
+  );
+
+  // 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',
+     ),
+  );
+
+  // 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
+  $data['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_organism_nid',
+    ),    
+  );
+
+  // 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',
+     ),
+  );
+
+  // 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',
+     ),
+  );
+
+  // 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',
+     ),
+  );
+
+  return $data;
+
+}

+ 0 - 139
tripal_organism/views/tripal_organism.views.inc

@@ -1,139 +0,0 @@
-<?php
-/*******************************************************************************
- *  This function provides data for the VIEWS module. The function generates
- *  a new field 'Tripal organism: Common name' when adding a 'Node' view type. 
- */
-
-function tripal_organism_views_data() {
-   //Delete the custom table that provides data for the cutom view if exists
-   if (db_table_exists('tripal_organism_views_common_name')) {
-      $sql = "DROP TABLE {tripal_organism_views_common_name}";
-      db_query ($sql);
-   }
-   
-   // Create the custom table. After created, it will be deleted only when the 
-   // tripal_organism module is uninstalled.
-   drupal_install_schema('tripal_organism_views_common_name');
-   
-   // Populate the custom table
-   // Get organism_id from chado_organism table
-   $sql = 'SELECT nid, organism_id FROM {chado_organism}';
-   $result = db_query($sql);
-   
-   //Retrieve common_names from chado database using the organism_id
-   $sql = 'SELECT common_name FROM {organism} WHERE organism_id=%d';
-   $previous_db = tripal_db_set_active ('chado');
-   $common_names = array ();
-   while ($org = db_fetch_object($result)) {     
-      $common_name = db_result(db_query ($sql, $org->organism_id));
-      $common_names [$org->nid] = $common_name;
-   }
-   tripal_db_set_active ($previous_db);
-   
-   // Insert common_name and nid to the custom table
-   $sql = "INSERT INTO {tripal_organism_views_common_name} (nid, common_name) VALUES (%d, '%s')";
-   foreach ($common_names as $nid => $common_name) {
-      db_query($sql, $nid, $common_name);
-   }
-   
-   // The following describes our custom table to the Views module
-   $data['tripal_organism_views_common_name'] = array(
-      // This table section is needed for each custom view created
-      'table' => array(
-         'group' => 'Tripal organism',
-         'join' => array(
-            'node' => array(
-               'left_field' => 'nid',
-               'field' => 'nid',        
-            ),
-         ),
-      ),
-      // Describe the column 'common_name' to show as a field in the Views
-      'common_name' => array(
-         'title' => t('Common name'),
-         // The help that appears on the UI,
-         'help' => t('The common name of an organism.'),
-         // Information for displaying the nid
-         'field' => array(
-            'handler' => 'views_handler_field_node',
-            'click sortable' => TRUE,
-         ),
-         // Information for accepting a common_name as a filter
-         'filter' => array(
-            'handler' => 'views_handler_filter_numeric',
-         ),
-         // Information for sorting on a common_name.
-         'sort' => array(
-            'handler' => 'views_handler_sort',
-         ),        
-      ),
-   );
-   return $data;  
-}
-
-/*******************************************************************************
- * The table schema generated to provide data for the Views module. The table
- * will be created when the Views module calls to hook_view_data(). It will
- * be deleted only when the tripal_organism module is uninstalled.
- */
-function tripal_organism_views_common_name_schema() {
-
-   $schema['tripal_organism_views_common_name'] = array(
-      'fields' => array(
-         'nid' => array(
-            'type' => 'int',
-            'unsigned' => TRUE,
-            'not null' => TRUE,
-            'default' => 0
-         ),
-         'common_name' => array(
-            'type' => 'varchar',
-            'length' => 255,
-            'not null' => TRUE,
-            'default' => 'NA',
-            'description' => t('To provide common name for the Views module')
-         ),
-      ),
-  );
-  return $schema;
-}
-
-//  Experimental codes that don't create extra tables in Drupal database
-/*
-function tripal_organism_views_data() {
-
-   // Make Chado 'Organism' as a base table, so it can show as a Views type
-   $data['organism'] = array(
-      // This table section is needed for each custom view created
-      'table' => array(
-         'group' => 'Tripal',
-         'base' => array(
-            'field' => 'organism_id',
-            'title' => t('Tripal Organism'),
-            'help' => t('Tripal Organism'),
-            'database' => 'chado',
-         ),
-      ),
-      // Describe the columns of organism table to the Views so it knows how to make the query
-      'common_name' => array(
-         'title' => t('Common Name'),
-         'help' => t('Showing the common name of an organism.'), // The help that appears on the UI,
-         // Information for displaying the nid
-         'field' => array(
-            'handler' => 'views_handler_field',
-            'click sortable' => TRUE,
-         ),
-         // Information for accepting a common_name as a filter
-         'filter' => array(
-            'handler' => 'views_handler_filter_string',
-         ),
-         // Information for sorting on a common_name.
-         'sort' => array(
-            'handler' => 'views_handler_sort',
-         ),        
-      ),
-   );
-
-   return $data;  
-}
-*/