Browse Source

Tripal Natural Diverstiy Views Integration -added support for experiment, geolocation,reagent; also moved around stock handlers (Part I)

laceysanderson 14 years ago
parent
commit
65ea3d9ecc
33 changed files with 533 additions and 1560 deletions
  1. 8 5
      tripal_core/views/handlers/views_handler_field_cvterm_name.inc
  2. 9 1
      tripal_core/views/handlers/views_handler_field_node_optional.inc
  3. 0 81
      tripal_core/views/handlers/views_handler_field_stock_dbxref_all.inc
  4. 0 151
      tripal_core/views/handlers/views_handler_field_stock_dbxref_by_type.inc
  5. 0 65
      tripal_core/views/handlers/views_handler_field_stockprop_all.inc
  6. 0 132
      tripal_core/views/handlers/views_handler_field_stockprop_by_type.inc
  7. 0 72
      tripal_core/views/handlers/views_handler_field_stockrel_all.inc
  8. 0 282
      tripal_core/views/handlers/views_handler_filter_stockprop_id.inc
  9. 4 0
      tripal_cv/views/cvterm.views.inc
  10. 6 0
      tripal_feature/views/feature.views.inc
  11. 87 0
      tripal_natural_diversity/tripal_natural_diversity.api.inc
  12. 2 0
      tripal_natural_diversity/tripal_natural_diversity.module
  13. 17 1
      tripal_natural_diversity/tripal_natural_diversity.views.inc
  14. 101 0
      tripal_natural_diversity/views/handlers/views_handler_field_chado_relationship_all.inc
  15. 1 1
      tripal_natural_diversity/views/handlers/views_handler_field_chado_relationship_by_type.inc
  16. 93 0
      tripal_natural_diversity/views/nd_experiment.views.inc
  17. 2 1
      tripal_natural_diversity/views/nd_experimentprop.views.inc
  18. 1 1
      tripal_natural_diversity/views/nd_geolocation.views.inc
  19. 127 0
      tripal_natural_diversity/views/nd_geolocationprop.views.inc
  20. 38 127
      tripal_natural_diversity/views/nd_reagent.views.inc
  21. 0 205
      tripal_natural_diversity/views/nd_reagent_relationship.views.inc
  22. 28 108
      tripal_natural_diversity/views/nd_reagentprop.views.inc
  23. 9 0
      tripal_stock/tripal_stock.module
  24. 0 65
      tripal_stock/views/handlers/views_handler_argument_stockprop_id.inc
  25. 0 17
      tripal_stock/views/handlers/views_handler_field_computed_stock_nid.inc
  26. 0 1
      tripal_stock/views/handlers/views_handler_field_stock_dbxref_all.inc
  27. 0 1
      tripal_stock/views/handlers/views_handler_field_stock_dbxref_by_type.inc
  28. 0 1
      tripal_stock/views/handlers/views_handler_field_stockprop_all.inc
  29. 0 1
      tripal_stock/views/handlers/views_handler_field_stockprop_by_type.inc
  30. 0 1
      tripal_stock/views/handlers/views_handler_field_stockrel_all.inc
  31. 0 1
      tripal_stock/views/handlers/views_handler_field_stockrel_by_type.inc
  32. 0 238
      tripal_stock/views/handlers/views_handler_filter_stock_dbxref_id.inc
  33. 0 1
      tripal_stock/views/handlers/views_handler_filter_stockprop_id.inc

+ 8 - 5
tripal_core/views/handlers/views_handler_field_cvterm_name.inc

@@ -7,13 +7,16 @@ class views_handler_field_cvterm_name extends views_handler_field {
    * Add join to the cvterm table and cvterm.name field to the query
    */
   function query() {
-  
+      
     // if this table isn't a base table
     // if it is this can be done by describing a join between base table and cvterm
     if (!preg_match('/^'.$this->view->base_table.'$/', $this->table)) {
 
       //Want to add join: LEFT JOIN cvterm nd_experimentprop_cvterm ON nd_experimentprop.type_id = nd_experimentprop_cvterm.cvterm_id
-      //===============================================================
+      //===============================================================      
+
+      $this->query->ensure_table($this->table);
+      
       // add to table_queue--------------------------------------------
       $cvterm_join['table'] = 'cvterm';
       $cvterm_join['num'] = 1;
@@ -31,14 +34,14 @@ class views_handler_field_cvterm_name extends views_handler_field {
       $cvterm_join['join']->definition['left_table'] = $this->table;
       $cvterm_join['join']->definition['left_field'] = 'type_id';
 
-      $this->query->table_queue['cvterm'] = $cvterm_join;
+      $this->query->table_queue[$cvterm_join['alias']] = $cvterm_join;
 
       // add to table--------------------------------------------------
       $this->query->tables[$this->view->base_table][$this->table.'_cvterm'] = array(
         'count' => 1,
         'alias' => $this->table.'_cvterm',
-      );
-      
+      );    
+
       //Want to add field: nd_experimentprop_cvterm.name as nd_experimentprop_type
       //===============================================================
       $field_alias = $this->table.'_cvterm_name';

+ 9 - 1
tripal_core/views/handlers/views_handler_field_node_optional.inc

@@ -57,7 +57,14 @@ class views_handler_field_node_optional extends views_handler_field_node {
       $drupal_node_table_join['alias'] = $drupal_node_table_alias;
       $drupal_node_table_join['relationship'] = $this->options[table];
 
-      $drupal_node_table_join['join'] = clone($this->query->table_queue['node']['join']);
+      if ($this->query->table_queue['node']['join']) {
+        $drupal_node_table_join['join'] = clone($this->query->table_queue['node']['join']);
+      } else {
+        $drupal_node_table_join['join'] = clone($this->query->table_queue[$drupal_chado_table_name]['join']);
+      }
+      $drupal_node_table_join['join']->table = 'node';
+      $drupal_node_table_join['join']->field = 'nid';
+      $drupal_node_table_join['join']->left_field = 'nid';
       $drupal_node_table_join['join']->left_table = $drupal_chado_table_name;
       $drupal_node_table_join['join']->definition['left_table'] = $drupal_chado_table_name;
       
@@ -78,6 +85,7 @@ class views_handler_field_node_optional extends views_handler_field_node {
     } else {
       $this->aliases['nid'] = 'node_nid';
     }
+
   }
 
   /**

+ 0 - 81
tripal_core/views/handlers/views_handler_field_stock_dbxref_all.inc

@@ -1,81 +0,0 @@
-<?php
-// $Id: views_handler_field_term_node_tid.inc,v 1.4 2009/07/01 23:07:14 merlinofchaos Exp $
-
-/**
- * Field handler for terms.
- */
-class views_handler_field_stock_dbxref_all extends views_handler_field_prerender_list {
-  function init(&$view, $options) {
-    parent::init($view, $options);
-  }
-
-  /**
-   * Add this term to the query
-   */
-  function query() {
-    $this->add_additional_fields();
-  }
-
-	function pre_render($values) {
-		$this->aliases['dbxref'] = 'dbxref';
-		$this->aliases['stock_id'] = 'stock_id';
-		$this->field_alias = $this->aliases['stock_id'];
-		
-		//for each stock in this view page
-		foreach ($values as $result) {
-			if (!empty($result->{$this->aliases['dbxref']})) {
-				
-				// all dbxrefs including the current stock
-				$dbxrefs = $result->{$this->aliases['dbxref']};
-				foreach ($dbxrefs as $dbxref) {			
-					// Add dbxref to the list of items to be rendered
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['stock_id'] = $dbxref->stock_id;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['stock_dbxref_id'] = $dbxref->stock_dbxref_id;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['dbxref_id'] = $dbxref->dbxref_id;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['is_current'] = $dbxref->is_current;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['db_id'] = $dbxref->db_id;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['db_name'] = $dbxref->db_name;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['urlprefix'] = $dbxref->urlprefix;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['accession'] = $dbxref->accession;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['version'] = $dbxref->version;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['description'] = $dbxref->description;
-				}
-			}
-		}
-	}
-
-  function render_item($count, $item) {
-		if (!empty($item['urlprefix'])) {
-			return l($item['accession'],$item['urlprefix'].$item['accession']).' ('.$item['db_name'].')';
-		} else {
-			return $item['accession'].' ('.$item['db_name'].')';
-		}
-  }
-
-  function document_self_tokens(&$tokens) {
-    $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = t('The Stock ID.');
-		$tokens['[' . $this->options['id'] . '-stock_dbxref_id' . ']'] = t('Stock Database Reference ID');
-		$tokens['[' . $this->options['id'] . '-dbxref_id' . ']'] = t('Database Reference ID');
-		$tokens['[' . $this->options['id'] . '-is_current' . ']'] = t('Is Current');
-		$tokens['[' . $this->options['id'] . '-db_id' . ']'] = t('Database ID');
-		$tokens['[' . $this->options['id'] . '-db_name' . ']'] = t('Database Name');
-		$tokens['[' . $this->options['id'] . '-urlprefix' . ']'] = t('URL Prefix');
-		$tokens['[' . $this->options['id'] . '-accession' . ']'] = t('Accession');
-		$tokens['[' . $this->options['id'] . '-version' . ']'] = t('Version');
-		$tokens['[' . $this->options['id'] . '-description' . ']'] = t('Description');
-  }
-
-  function add_self_tokens(&$tokens, $item) {
-    $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = $item['stock_id'];
-		$tokens['[' . $this->options['id'] . '-stock_dbxref_id' . ']'] = $item['stock_dbxref_id'];
-		$tokens['[' . $this->options['id'] . '-dbxref_id' . ']'] =  $item['dbxref_id'];
-		$tokens['[' . $this->options['id'] . '-is_current' . ']'] = $item['is_current'];
-		$tokens['[' . $this->options['id'] . '-db_id' . ']'] = $item['db_id'];
-		$tokens['[' . $this->options['id'] . '-db_name' . ']'] = $item['db_name'];
-		$tokens['[' . $this->options['id'] . '-urlprefix' . ']'] = $item['urlprefix'];
-		$tokens['[' . $this->options['id'] . '-accession' . ']'] = $item['accession'];
-		$tokens['[' . $this->options['id'] . '-version' . ']'] = $item['version'];
-		$tokens['[' . $this->options['id'] . '-description' . ']'] = $item['description'];
-  }
-}
-

+ 0 - 151
tripal_core/views/handlers/views_handler_field_stock_dbxref_by_type.inc

@@ -1,151 +0,0 @@
-<?php
-// $Id: views_handler_field_term_node_tid.inc,v 1.4 2009/07/01 23:07:14 merlinofchaos Exp $
-
-/**
- * Field handler for terms.
- */
-class views_handler_field_stock_dbxref_by_type extends views_handler_field_prerender_list {
-  function init(&$view, $options) {
-    parent::init($view, $options);
-
-    // Boolean to determine whether
-    //    TRUE =>  value (property type)      -more than one property type displayed
-    //    FALSE => or just value is rendered  -only 1 porperty type is displayed    
-    $this->display_type = TRUE;
-
-  }
-
-  function option_definition() {
-    $options = parent::option_definition();
-    $options['stockprop_type_ids'] = array('default' => array());
-		$options['display_options'] = array('default' => array('accession','db_name','link'));
-    return $options;
-  }
-
-  /**
-   * Provide "link to term" option.
-   */
-  function options_form(&$form, &$form_state) {
-    parent::options_form($form, $form_state);
-
-		$form['display_options'] = array(
-			'#type' => 'checkboxes',
-			'#title' => t('Display DB Reference Parts'),
-			'#description' => t('Check each part of the database reference you want displayed where the parts '
-				.'of a database relationship are: <Accession> (<Datbase Name>). You can also specify whether the accession '
-				.'should be linked to the record in the database by checking "Link to External Record".'),
-			'#options' => array(
-				'accession' => 'Accession',
-				'db_name' => 'Database Name',
-				'link' => 'Link to External Record',
-			),
-			'#default_value' => array($this->options['display_options']['accession'], $this->options['display_options']['db_name'], $this->options['display_options']['link']),
-		);
-		
-    $db_options = tripal_db_get_db_options();
-	  $db_options[0] = 'Select a Database';
-	  ksort($db_options);
-    $form['db_ids'] = array(
-      '#type' => 'checkboxes',
-      '#title' => t('Database'),
-      '#options' => $db_options,
-      '#default_value' => $this->options['db_ids'],
-    );
-  }
-
-  /**
-   * Add this term to the query
-   */
-  function query() {
-    $this->add_additional_fields();
-  }
-
-	function pre_render($values) {
-		$this->aliases['dbxref'] = 'dbxref';
-		$this->aliases['stock_id'] = 'stock_id';
-		$this->field_alias = $this->aliases['stock_id'];
-		
-		//for each stock in this view page
-		foreach ($values as $result) {
-			if (!empty($result->{$this->aliases['dbxref']})) {
-				
-				// all dbxrefs including the current stock
-				$dbxrefs = $result->{$this->aliases['dbxref']};
-				foreach ($dbxrefs as $dbxref) {
-							
-					// perform filtering
-					if (!empty($this->options['db_ids'])) {
-						$dbs2keep = array_filter($this->options['db_ids']);
-						if (!in_array($dbxref->db_id, $dbs2keep)) {
-							continue;
-						}
-					}
-					
-					// Add dbxref to the list of items to be rendered
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['stock_id'] = $dbxref->stock_id;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['stock_dbxref_id'] = $dbxref->stock_dbxref_id;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['dbxref_id'] = $dbxref->dbxref_id;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['is_current'] = $dbxref->is_current;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['db_id'] = $dbxref->db_id;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['db_name'] = $dbxref->db_name;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['urlprefix'] = $dbxref->urlprefix;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['accession'] = $dbxref->accession;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['version'] = $dbxref->version;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['description'] = $dbxref->description;				}
-			}
-		}
-	}
-
-  function render_item($count, $item) {
-		$text = array();
-		if ($this->options['display_options']['link']) {
-			if ($this->options['display_options']['accession']) {
-				$text[] = l($item['accession'],$item['urlprefix'].$item['accession']);
-			} else {
-				$text[] = l('External Record',$item['urlprefix'].$item['accession']);
-			}	
-		} else {
-			if ($this->options['display_options']['accession']) {
-				$text[] = $item['accession'];
-			}
-		}
-		
-		
-		if ($this->options['display_options']['db_name']) {
-			$text[] = $item['db_name'];
-		}
-		
-		if (sizeof($text) > 1) {
-			return $text[0].' ('.$text[1].')';
-		} else {
-			return $text[0];
-		}
-  }
-
-  function document_self_tokens(&$tokens) {
-    $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = t('The Stock ID.');
-		$tokens['[' . $this->options['id'] . '-stock_dbxref_id' . ']'] = t('Stock Database Reference ID');
-		$tokens['[' . $this->options['id'] . '-dbxref_id' . ']'] = t('Database Reference ID');
-		$tokens['[' . $this->options['id'] . '-is_current' . ']'] = t('Is Current');
-		$tokens['[' . $this->options['id'] . '-db_id' . ']'] = t('Database ID');
-		$tokens['[' . $this->options['id'] . '-db_name' . ']'] = t('Database Name');
-		$tokens['[' . $this->options['id'] . '-urlprefix' . ']'] = t('URL Prefix');
-		$tokens['[' . $this->options['id'] . '-accession' . ']'] = t('Accession');
-		$tokens['[' . $this->options['id'] . '-version' . ']'] = t('Version');
-		$tokens['[' . $this->options['id'] . '-description' . ']'] = t('Description');
-  }
-
-  function add_self_tokens(&$tokens, $item) {
-    $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = $item['stock_id'];
-		$tokens['[' . $this->options['id'] . '-stock_dbxref_id' . ']'] = $item['stock_dbxref_id'];
-		$tokens['[' . $this->options['id'] . '-dbxref_id' . ']'] =  $item['dbxref_id'];
-		$tokens['[' . $this->options['id'] . '-is_current' . ']'] = $item['is_current'];
-		$tokens['[' . $this->options['id'] . '-db_id' . ']'] = $item['db_id'];
-		$tokens['[' . $this->options['id'] . '-db_name' . ']'] = $item['db_name'];
-		$tokens['[' . $this->options['id'] . '-urlprefix' . ']'] = $item['urlprefix'];
-		$tokens['[' . $this->options['id'] . '-accession' . ']'] = $item['accession'];
-		$tokens['[' . $this->options['id'] . '-version' . ']'] = $item['version'];
-		$tokens['[' . $this->options['id'] . '-description' . ']'] = $item['description'];
-  }
-}
-

+ 0 - 65
tripal_core/views/handlers/views_handler_field_stockprop_all.inc

@@ -1,65 +0,0 @@
-<?php
-// $Id: views_handler_field_term_node_tid.inc,v 1.4 2009/07/01 23:07:14 merlinofchaos Exp $
-
-/**
- * Field handler for terms.
- */
-class views_handler_field_stockprop_all extends views_handler_field_prerender_list {
-  function init(&$view, $options) {
-    parent::init($view, $options);
-  }
-
-  /**
-   * Add this term to the query
-   */
-  function query() {
-    $this->add_additional_fields();
-  }
-
-	function pre_render($values) {
-		$this->aliases['properties'] = 'properties';
-		$this->aliases['stock_id'] = 'stock_id';
-		$this->field_alias = $this->aliases['stock_id'];
-		
-		//for each stock in this view page
-		foreach ($values as $result) {
-			if (!empty($result->{$this->aliases['properties']})) {
-				
-				// all properties for the current stock
-				$properties = $result->{$this->aliases['properties']};
-				foreach ($properties as $property) {					
-					// Add property to the list of items to be rendered
-					$this->items[$property->stock_id][$property->stockprop_id]['stock_id'] = $property->stock_id;
-					$this->items[$property->stock_id][$property->stockprop_id]['stockprop_id'] = $property->stockprop_id;
-					$this->items[$property->stock_id][$property->stockprop_id]['type_id'] = $property->type_id;
-					$this->items[$property->stock_id][$property->stockprop_id]['type_name'] = check_plain($property->type_name);
-					$this->items[$property->stock_id][$property->stockprop_id]['value'] = check_plain($property->value);
-					$this->items[$property->stock_id][$property->stockprop_id]['rank'] = $property->rank;
-				}
-			}
-		}
-	}
-
-  function render_item($count, $item) {
-		return $item['value'].' ('.$item['type_name'].')';
-  }
-
-  function document_self_tokens(&$tokens) {
-    $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = t('The Stock ID.');
-    $tokens['[' . $this->options['id'] . '-stockprop_id' . ']'] = t('The Property ID.');
-    $tokens['[' . $this->options['id'] . '-type_id' . ']'] = t('The Property Type ID.');
-    $tokens['[' . $this->options['id'] . '-type_name' . ']'] = t('The Property Type.');
-    $tokens['[' . $this->options['id'] . '-value' . ']'] = t('The Value of the Property.');
-    $tokens['[' . $this->options['id'] . '-rank' . ']'] = t('The Rank of the Property.');
-  }
-
-  function add_self_tokens(&$tokens, $item) {
-    $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = $item['stock_id'];
-    $tokens['[' . $this->options['id'] . '-stockprop_id' . ']'] = $item['stockprop_id'];
-    $tokens['[' . $this->options['id'] . '-type_id' . ']'] = $item['type_id'];
-    $tokens['[' . $this->options['id'] . '-type_name' . ']'] = $item['type_name'];
-    $tokens['[' . $this->options['id'] . '-value' . ']'] = $item['value'];
-    $tokens['[' . $this->options['id'] . '-rank' . ']'] = $item['rank'];
-  }
-}
-

+ 0 - 132
tripal_core/views/handlers/views_handler_field_stockprop_by_type.inc

@@ -1,132 +0,0 @@
-<?php
-// $Id: views_handler_field_term_node_tid.inc,v 1.4 2009/07/01 23:07:14 merlinofchaos Exp $
-
-/**
- * Field handler for terms.
- */
-class views_handler_field_stockprop_by_type extends views_handler_field_prerender_list {
-  function init(&$view, $options) {
-    parent::init($view, $options);    
-  }
-
-  function option_definition() {
-    $options = parent::option_definition();
-    $options['stockprop_type_ids'] = array('default' => array());
-    $options['stockprop_display_options'] = array('default' => array('type', 'value'));
-    return $options;
-  }
-
-  /**
-   * Provide "link to term" option.
-   */
-  function options_form(&$form, &$form_state) {
-    parent::options_form($form, $form_state);
-
-    $form['stockprop_display_options'] = array(
-      '#prefix' => '<div><div id="edit-options-display_options">',
-      '#suffix' => '</div></div>',
-      '#type' => 'checkboxes',
-      '#title' => t('Display Relationship Parts'),
-      '#description' => t('Check each part of the property you want displayed where the parts '
-        .'of a property are: <type> and <value>. '
-        .'For example, with the property temperature 54 degrees Celcius the type=temperature and the value=54 degrees Celcius. '
-        .'Thus, if you checked only value then "54 degrees Celcius" would be displayed.'),
-      '#options' => array(
-        'type' => 'Type',
-        'value' => 'Value',
-      ),
-      '#default_value' => array($this->options['stockprop_display_options']['type'], $this->options['stockprop_display_options']['value']),
-    );
-    
-    $options = tripal_cv_get_cvterm_options( variable_get('chado_stock_prop_types_cv', 'null') );
-    $form['stockprop_type_ids'] = array(
-      '#prefix' => '<div><div id="edit-options-stockprop_type_ids">',
-      '#suffix' => '</div></div>',
-      '#type' => 'checkboxes',
-      '#title' => t('Property Types'),
-      '#options' => $options,
-      '#default_value' => $this->options['stockprop_type_ids'],
-    );
-  }
-  
-  /**
-   * Add this term to the query
-   */
-  function query() {
-    $this->add_additional_fields();
-  }
-
-  function pre_render($values) {
-    $this->aliases['properties'] = 'properties';
-    $this->aliases['stock_id'] = 'stock_id';
-    $this->field_alias = $this->aliases['stock_id'];
-    
-    //for each stock in this view page
-    foreach ($values as $result) {
-      if (!empty($result->{$this->aliases['properties']})) {
-        
-        // all properties for the current stock
-        $properties = $result->{$this->aliases['properties']};
-        foreach ($properties as $property) {
-          // perform filtering
-          if (!empty($this->options['stockprop_type_ids'])) {
-            $types2keep = array_filter($this->options['stockprop_type_ids']);
-            if (!in_array($property->type_id, $types2keep)) {
-              continue;
-            }
-          }
-          
-          // Add property to the list of items to be rendered
-          $this->items[$property->stock_id][$property->stockprop_id]['stock_id'] = $property->stock_id;
-          $this->items[$property->stock_id][$property->stockprop_id]['stockprop_id'] = $property->stockprop_id;
-          $this->items[$property->stock_id][$property->stockprop_id]['type_id'] = $property->type_id;
-          $this->items[$property->stock_id][$property->stockprop_id]['type_name'] = check_plain($property->type_name);
-          $this->items[$property->stock_id][$property->stockprop_id]['value'] = check_plain($property->value);
-          $this->items[$property->stock_id][$property->stockprop_id]['rank'] = $property->rank;
-        }
-      }
-    }
-  }
-
-  function render_item($count, $item) {
-    $text = array();
-    
-    if ($this->options['stockprop_display_options']['value']) {
-      if ($item['value']) {
-        $text[] =  $item['value'];
-      } else {
-        //display checkmark image
-        $image_path = drupal_get_path('module','tripal_core').'/images/checkmark.gif';
-        $text[] = '<img border="0" src="'.url($image_path).'" alt="checkmark" />';
-      }
-    } 
-    if ($this->options['stockprop_display_options']['type']) {
-      $text[] = $item['type_name'];
-    }
-  
-    if (sizeof($text) > 1) {
-      return $text[0].' ('.$text[1].')';
-    } else {
-      return $text[0];
-    }
-  }
-
-  function document_self_tokens(&$tokens) {
-    $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = t('The Stock ID.');
-    $tokens['[' . $this->options['id'] . '-stockprop_id' . ']'] = t('The Property ID.');
-    $tokens['[' . $this->options['id'] . '-type_id' . ']'] = t('The Property Type ID.');
-    $tokens['[' . $this->options['id'] . '-type_name' . ']'] = t('The Property Type.');
-    $tokens['[' . $this->options['id'] . '-value' . ']'] = t('The Value of the Property.');
-    $tokens['[' . $this->options['id'] . '-rank' . ']'] = t('The Rank of the Property.');
-  }
-
-  function add_self_tokens(&$tokens, $item) {
-    $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = $item['stock_id'];
-    $tokens['[' . $this->options['id'] . '-stockprop_id' . ']'] = $item['stockprop_id'];
-    $tokens['[' . $this->options['id'] . '-type_id' . ']'] = $item['type_id'];
-    $tokens['[' . $this->options['id'] . '-type_name' . ']'] = $item['type_name'];
-    $tokens['[' . $this->options['id'] . '-value' . ']'] = $item['value'];
-    $tokens['[' . $this->options['id'] . '-rank' . ']'] = $item['rank'];
-  }
-}
-

+ 0 - 72
tripal_core/views/handlers/views_handler_field_stockrel_all.inc

@@ -1,72 +0,0 @@
-<?php
-// $Id: views_handler_field_term_node_tid.inc,v 1.4 2009/07/01 23:07:14 merlinofchaos Exp $
-
-/**
- * Field handler for terms.
- */
-class views_handler_field_stockrel_all extends views_handler_field_prerender_list {
-  function init(&$view, $options) {
-    parent::init($view, $options);
-  }
-
-  /**
-   * Add this term to the query
-   */
-  function query() {
-    $this->add_additional_fields();
-  }
-
-	function pre_render($values) {
-		$this->aliases['relationships'] = 'relationships';
-		$this->aliases['stock_id'] = 'stock_id';
-		$this->field_alias = $this->aliases['stock_id'];
-		
-		//for each stock in this view page
-		foreach ($values as $result) {
-			if (!empty($result->{$this->aliases['relationships']})) {
-				
-				// all relationships including the current stock
-				$relationships = $result->{$this->aliases['relationships']};
-				foreach ($relationships as $relationship) {			
-					// Add relationship to the list of items to be rendered
-					$this->items[$relationship->stock_id][$relationship->stock_relationship_id]['stock_id'] = $relationship->stock_id;
-					$this->items[$relationship->stock_id][$relationship->stock_relationship_id]['stock_relationship_id'] = $relationship->stock_relationship_id;
-					$this->items[$relationship->stock_id][$relationship->stock_relationship_id]['subject_id'] = $relationship->subject_id;
-					$this->items[$relationship->stock_id][$relationship->stock_relationship_id]['subject_name'] = $relationship->subject_name;
-					$this->items[$relationship->stock_id][$relationship->stock_relationship_id]['object_id'] = $relationship->object_id;
-					$this->items[$relationship->stock_id][$relationship->stock_relationship_id]['object_name'] = $relationship->object_name;
-					$this->items[$relationship->stock_id][$relationship->stock_relationship_id]['type_id'] = $relationship->type_id;
-					$this->items[$relationship->stock_id][$relationship->stock_relationship_id]['type_name'] = $relationship->type_name;
-				}
-			}
-		}
-	}
-
-  function render_item($count, $item) {
-		return $item['subject_name'].' '.$item['type_name'].' '.$item['object_name'];
-  }
-
-  function document_self_tokens(&$tokens) {
-    $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = t('The Stock ID.');
-		$tokens['[' . $this->options['id'] . '-stock_relationship_id' . ']'] = t('Relationship ID');
-		$tokens['[' . $this->options['id'] . '-subject_id' . ']'] = t('Subject ID');
-		$tokens['[' . $this->options['id'] . '-subject_name' . ']'] = t('Subject Name');
-		$tokens['[' . $this->options['id'] . '-object_id' . ']'] = t('Object ID');
-		$tokens['[' . $this->options['id'] . '-object_name' . ']'] = t('Object Name');
-		$tokens['[' . $this->options['id'] . '-type_id' . ']'] = t('Type ID');
-		$tokens['[' . $this->options['id'] . '-type_name' . ']'] = t('Type Name');
-  }
-
-  function add_self_tokens(&$tokens, $item) {
-    $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = $item['stock_id'];
-		$tokens['[' . $this->options['id'] . '-stock_relationship_id' . ']'] = $item['stock_relationship_id'];
-		$tokens['[' . $this->options['id'] . '-subject_id' . ']'] = $item['subject_id'];
-		$tokens['[' . $this->options['id'] . '-subject_name' . ']'] = $item['subject_name'];
-		$tokens['[' . $this->options['id'] . '-object_id' . ']'] = $item['object_id'];
-		$tokens['[' . $this->options['id'] . '-object_name' . ']'] = $item['object_name'];
-		$tokens['[' . $this->options['id'] . '-type_id' . ']'] = $item['type_id'];
-		$tokens['[' . $this->options['id'] . '-type_name' . ']'] = $item['type_name'];
-
-  }
-}
-

+ 0 - 282
tripal_core/views/handlers/views_handler_filter_stockprop_id.inc

@@ -1,282 +0,0 @@
-<?php
-
-/**
- * Filter by stockprop type id
- */
-class views_handler_filter_stockprop_id extends views_handler_filter {
-
-  function init(&$view, $options) {
-    parent::init($view, $options);
-    $this->type = $this->options['type'];
-  }
-
-  function options_form(&$form, &$form_state) {
-    if ($this->can_expose()) {
-      $this->show_expose_button($form, $form_state);
-    }
-
-    $form['op_val_start'] = array('#value' => '<div class="clear-block">');
-
-    $this->types_form($form, $form_state);
-
-    $this->show_operator_form($form, $form_state);
-    $form['operator']['#prefix'] = '<div class="views-right-70">';
-    $this->show_value_form($form, $form_state);
-    $form['op_val_end'] = array('#value' => '</div>');
-
-    if ($this->can_expose()) {
-      $this->show_expose_form($form, $form_state);
-    }
-
-  }
-
-  function options_validate(&$form, &$form_state) {
-    parent::options_validate(&$form, &$form_state);
-
-    if (preg_match('/NULL/',$form_state['values']['options']['operator'])) {
-      $value = $form_state['values']['options']['value'];
-      if (!empty($value)) {
-        drupal_set_message('The Value ('.$value.') will be IGNORED when the Operator is set to "Is Present" or Is Absent".', 'warning');
-      }
-    } else {
-      $value = $form_state['values']['options']['value'];
-      if (empty($value)) {
-        form_error($form['value'], t('Value required. The value will be used in conjunction with the operator. For example, if the '
-				   .'operator="Is equal to" and the value="2010" then only properties with a value of 2010 and the type specified will be displayed.'));
-      }
-    }
-
-    if (empty($form_state['values']['options']['type'])) {
-      drupal_set_message('No Property Type was choosen. As such, any property type whose value '
-      			     .$form_state['values']['options']['operator'].' '.$form_state['values']['options']['value'].' will be displayed', 'warning');
-    }
-  }
-
-	function query () {
-		if (preg_match('/IS NOT NULL/', $this->options['operator'])) {
-			$new_where_sql = "stock.stock_id IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=".$this->type.")";
-		} elseif (preg_match('/IS NULL/', $this->options['operator'])) {
-			$new_where_sql = "stock.stock_id NOT IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=".$this->type.")";
-		} else {
-			$new_where_sql = "stock.stock_id IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=".$this->type." AND stockprop.value".$this->operator."'".$this->value."')";
-		}
-		$this->query->add_where($this->options['group'], $new_where_sql);
-	}
-	
-  function types_form(&$form, &$form_state) {
-    $previous_db = tripal_db_set_active('chado');
-    $result = db_query("SELECT cvt.cvterm_id as type_id, cvt.name FROM cvterm cvt WHERE cvt.cvterm_id IN (SELECT type_id FROM stockprop)");
-    tripal_db_set_active($previous_db);
-
-    $types = array();
-    while ($r = db_fetch_object($result)) { $types[$r->type_id] = $r->name; }
-
-    $form['type'] = array(
-      '#type' => count($options) < 10 ? 'radios' : 'select',
-      '#title' => t('Property Types'),
-      '#options' => $types,
-      '#default_value' => $this->type,
-      '#prefix' => '<div class="views-left-30">',
-      '#suffix' => '</div>',
-    );
-
-  }
-
-  function value_form(&$form, &$form_state) {
-    parent::value_form(&$form, &$form_state);
-	
-		if ($this->options['expose']['display_type'] == 'select') {
-		
-			// Get options
-			$previous_db = tripal_db_set_active('chado');
-			$resource = db_query("SELECT value FROM stockprop WHERE type_id=".$this->type." ORDER BY value");
-		 tripal_db_set_active($previous_db);
-			while ($r = db_fetch_object($resource)) {
-				$options[$r->value] = $r->value;
-			}
-			$form['value'] = array(
-        '#type' => 'select',
-        '#title' => $this->options['label'],
-        '#options' => $options,
-        '#default_value' => $this->value,
-      );
-		} else {
-			$form['value'] = array(
-  	    '#type' => 'textfield',
-    	  '#title' => t('Value'),
-      	'#default_value' => $this->value,
-    	);
-    }
-  }
-
-  function operator_options() {
-    return array(
-      '=' => t('Is equal to'),
-      '!=' => t('Is not equal to'),
-      '~' => t('Contains'),
-      '!~' => t('Does not contain'),
-      'IS NOT NULL' => t('Is Present (Not Empty)'),
-      'IS NULL' => t('Is Absent (Empty)'),
-    );
-  }
-
- /**
-  * Render our chunk of the exposed filter form when selecting
-  */
-  function exposed_form(&$form, &$form_state) {
-    if (empty($this->options['exposed'])) {
-      return;
-    }
-
-    if (!empty($this->options['expose']['use_type']) && !empty($this->options['expose']['type'])) {
-      $type = $this->options['expose']['type'];
-      $form[$type] = array(
-        '#type' => 'select',
-        '#title' => t('Property Types'),
-        '#options' => $this->type_options(),
-        '#default_value' => $this->type,  
-      );
-
-      if (isset($form[$type]['#title'])) {
-        unset($form[$type]['#title']);
-      }
-    }
-
-    if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator'])) {
-      $operator = $this->options['expose']['operator'];
-      $this->operator_form($form, $form_state);
-      $form[$operator] = $form['operator'];
-
-      if (isset($form[$operator]['#title'])) {
-        unset($form[$operator]['#title']);
-      }
-
-      $this->exposed_translate($form[$operator], 'operator');
-
-      unset($form['operator']);
-    }
-
-    if (!empty($this->options['expose']['identifier'])) {
-      $value = $this->options['expose']['identifier'];
-      $this->value_form($form, $form_state);
-      $form[$value] = $form['value'];
-
-      if (isset($form[$value]['#title']) && !empty($form[$value]['#type']) && $form[$value]['#type'] != 'checkbox') {
-        unset($form[$value]['#title']);
-      }
-
-      $this->exposed_translate($form[$value], 'value');
-
-      if (!empty($form['#type']) && ($form['#type'] == 'checkboxes' || ($form['#type'] == 'select' && !empty($form['#multiple'])))) {
-        unset($form[$value]['#default_value']);
-      }
-
-      if (!empty($form['#type']) && $form['#type'] == 'select' && empty($form['#multiple'])) {
-        $form[$value]['#default_value'] = 'All';
-      }
-
-      if ($value != 'value') {
-        unset($form['value']);
-      }
-    }
-  }
-
-  function expose_form_left(&$form, &$form_state) {
-    $form['expose']['label'] = array(
-      '#type' => 'textfield',
-      '#default_value' => $this->options['expose']['label'],
-      '#title' => t('Label'),
-      '#size' => 40,
-    );
-
-    $form['expose']['identifier'] = array(
-      '#type' => 'textfield',
-      '#default_value' => $this->options['expose']['identifier'],
-      '#title' => t('Filter identifier'),
-      '#size' => 40,
-      '#description' => t('This will appear in the URL after the ? to identify this filter. Cannot be blank.'),
-    );
-    
-    $form['expose']['display_type'] = array(
-    	'#type' => 'radios',
-    	'#default_value' => $this->options['expose']['display_type'],
-    	'#title' => t('Display Type'),
-    	'#description' => t('This will change the form item type of the exposed value form. ie: it can be used to let the user select the property value from a select box rather than a textfield.'),
-			'#options' => array(
-				'textfield' => 'Text Field',
-				'select' => 'Drop Down',
-			),
-    );
-  }
-
-  function expose_form_right(&$form, &$form_state) {
-    if (!empty($form['type']['#type'])) {
-      $form['expose']['use_type'] = array(
-        '#type' => 'checkbox',
-        '#title' => t('Unlock Property Type'),
-        '#description' => t('When checked, the property type will be exposed to the user'),
-        '#default_value' => !empty($this->options['expose']['use_type']),
-      );
-      $form['expose']['type'] = array(
-        '#type' => 'textfield',
-        '#default_value' => $this->options['expose']['type'],
-        '#title' => t('Property Type identifier'),
-        '#size' => 40,
-        '#description' => t('This will appear in the URL after the ? to identify this property type.'),
-        '#process' => array('views_process_dependency'),
-        '#dependency' => array(
-          'edit-options-expose-use-type' => array(1)
-        ),
-      );
-    }
-    else {
-      $form['expose']['type'] = array(
-        '#type' => 'value',
-        '#value' => '',
-      );
-    }
-
-    $form['expose']['identifier'] = array(
-      '#type' => 'textfield',
-      '#default_value' => $this->options['expose']['identifier'],
-      '#title' => t('Filter identifier'),
-      '#size' => 40,
-      '#description' => t('This will appear in the URL after the ? to identify this filter. Cannot be blank.'),
-    );
-
-    if (!empty($form['operator']['#type'])) {
-      $form['expose']['use_operator'] = array(
-        '#type' => 'checkbox',
-        '#title' => t('Unlock operator'),
-        '#description' => t('When checked, the operator will be exposed to the user'),
-        '#default_value' => !empty($this->options['expose']['use_operator']),
-      );
-      $form['expose']['operator'] = array(
-        '#type' => 'textfield',
-        '#default_value' => $this->options['expose']['operator'],
-        '#title' => t('Operator identifier'),
-        '#size' => 40,
-        '#description' => t('This will appear in the URL after the ? to identify this operator.'),
-        '#process' => array('views_process_dependency'),
-        '#dependency' => array(
-          'edit-options-expose-use-operator' => array(1)
-        ),
-      );
-    }
-    else {
-      $form['expose']['operator'] = array(
-        '#type' => 'value',
-        '#value' => '',
-      );
-    }
-    
-    $form['expose']['optional'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Optional'),
-      '#description' => t('This exposed filter is optional and will have added options to allow it not to be set.'),
-      '#default_value' => $this->options['expose']['optional'],
-    );
-  }
-  
-  
-}

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

@@ -48,6 +48,10 @@ function retrieve_cvterm_views_data() {
        'left_field' => 'type_id',
        'field' => 'cvterm_id',
      ),
+     'nd_reagent' => array(
+       'left_field' => 'type_id',
+       'field' => 'cvterm_id',
+     ),
    );
 
  // Table Field Definitions----------------------

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

@@ -57,6 +57,12 @@
 		$data['feature']['table']['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)

+ 87 - 0
tripal_natural_diversity/tripal_natural_diversity.api.inc

@@ -0,0 +1,87 @@
+<?php
+
+function tripal_natural_diversity_chado_nd_reagent_schema () {
+  $description = array();
+  
+  $description = array(
+    'table' => 'nd_reagent',
+    'fields' => array(
+      'nd_reagent_id' => array(
+        'type' => 'serial',
+        'not null' => '1',
+      ),
+      'type_id' => array(
+        'type' => 'int',
+        'not null' => '1',
+      ),
+      'feature_id' => array(
+        'type' => 'int',
+      ),
+    ),
+    'primary key' => array(
+      '0' => 'nd_reagent_id',
+    ),
+    'foreign keys' => array(
+      'feature' => array(
+        'table' => 'feature',
+        'columns' => array(
+          'feature_id' => 'feature_id',
+        ),
+      ),
+      'cvterm' => array(
+        'table' => 'cvterm',
+        'columns' => array(
+          'type_id' => 'cvterm_id',
+        ),
+      ),
+    ),
+  );
+  
+  return $description;
+}
+
+function tripal_natural_diversity_chado_nd_reagent_relationship_schema () {
+  $description = array();
+  
+  $description = array(
+    'table' => 'nd_reagent_relationship',
+    'fields' => array(
+      'nd_reagent_relationship_id' => array(
+        'type' => 'serial',
+        'not null' => '1',
+      ),
+      'subject_reagent_id' => array(
+        'type' => 'int',
+        'not null' => '1',
+      ),
+      'type_id' => array(
+        'type' => 'int',
+        'not null' => '1',
+      ),
+      'object_reagent_id' => array(
+        'type' => 'int',
+        'not null' => '1',
+      ),
+    ),
+    'primary key' => array(
+      '0' => 'nd_reagent_relationship_id',
+    ),
+    'foreign keys' => array(
+      'nd_reagent' => array(
+        'table' => 'feature',
+        'columns' => array(
+          'subject_reagent_id' => 'nd_reagent_id',
+          'object_reagent_id' => 'nd_reagent_id',
+        ),
+      ),
+      'cvterm' => array(
+        'table' => 'cvterm',
+        'columns' => array(
+          'type_id' => 'cvterm_id',
+        ),
+      ),
+    ),
+  );
+  
+  return $description;
+}

+ 2 - 0
tripal_natural_diversity/tripal_natural_diversity.module

@@ -1,5 +1,7 @@
 <?php
 
+require_once('tripal_natural_diversity.api.inc');
+
 /**
  *  @file
  * This file contains the basic functions needed for this drupal module.

+ 17 - 1
tripal_natural_diversity/tripal_natural_diversity.views.inc

@@ -23,12 +23,23 @@
 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());
   
   return $data;
 }
@@ -47,7 +58,12 @@ function tripal_natural_diversity_views_handlers() {
      'path' => drupal_get_path('module', 'tripal_natural_diversity') . '/views/handlers',
    ),
    'handlers' => array(
-
+		'views_handler_field_chado_relationship_all' => array(
+       'parent' => 'views_handler_field_prerender_list',
+     ),
+		'views_handler_field_chado_relationship_by_type' => array(
+       'parent' => 'views_handler_field_prerender_list',
+     ),
    ),
  );
 }

+ 101 - 0
tripal_natural_diversity/views/handlers/views_handler_field_chado_relationship_all.inc

@@ -0,0 +1,101 @@
+<?php
+// $Id: views_handler_field_term_node_tid.inc,v 1.4 2009/07/01 23:07:14 merlinofchaos Exp $
+
+/**
+ * Field handler for terms.
+ */
+class views_handler_field_chado_relationship_all extends views_handler_field_prerender_list {
+  function init(&$view, $options) {
+    parent::init($view, $options);
+  }
+
+  function query() {
+    // not sure why this is needed since nothing is added to the query...
+    $this->add_additional_fields();
+  }
+
+	function pre_render($values) {
+		$this->aliases['relationships'] = 'relationships';
+		$this->aliases['primary_id'] = $this->view->base_table.'_id';
+		$this->field_alias = $this->aliases['primary_id'];
+		$relationship_tablename = $this->view->base_table.'_relationship';
+		$this->aliases['relationship_primary_id'] = $relationship_tablename . '_id';
+		$table_desc = module_invoke_all('chado_'.$relationship_tablename.'_schema');
+		foreach($table_desc['foreign keys'][$this->view->base_table]['columns'] as $k => $v) {
+		  if (preg_match('/subject/',$k)) { $subject_id = $k; }
+		  if (preg_match('/object/', $k)) { $object_id = $k; }
+		}
+		$this->aliases['subject_id'] = $subject_id;
+		$this->aliases['object_id'] = $object_id;
+		  
+    //Add values for all if possible
+    if (!$this->view->result[0]->relationships) {
+      //get base table primary keys
+      $primary_ids = array();
+		  foreach ($this->view->result as $row_num => $row) {
+			  $primary_ids[$row_num] = $row->{$this->aliases['primary_id']};
+		  }
+		
+		  //generate results from db
+      $sql = "SELECT ".$relationship_tablename.".*, cvterm.name as type_name, "
+					."subject_parent.name as subject_name, object_parent.name as object_name "
+					."FROM ".$relationship_tablename." "
+					."LEFT JOIN ".$this->view->base_table." subject_parent ON "
+					  .$relationship_tablename.".".$subject_id."=subject_parent.".$this->aliases['primary_id']." "
+					."LEFT JOIN ".$this->view->base_table." object_parent ON "
+					  .$relationship_tablename.".".$object_id."=object_parent.".$this->aliases['primary_id']." "
+					."LEFT JOIN cvterm cvterm ON "
+					  .$relationship_tablename.".type_id = cvterm.cvterm_id "
+					."WHERE ".$relationship_tablename.".".$subject_id." IN (".implode(',',$primary_ids).") "
+					."OR ".$relationship_tablename.".".$object_id." IN (".implode(',',$primary_ids).") ";
+			$previous_db = tripal_db_set_active('chado');
+			$resource = db_query($sql);
+			tripal_db_set_active($previous_db);
+			
+			//add results to views results
+			while ($r = db_fetch_object($resource)) {
+				if (in_array($r->{$subject_id}, $primary_ids)) {
+					$key = array_search($r->{$subject_id}, $primary_ids);
+					$r->{$this->aliases['primary_id']} = $r->{$subject_id};
+					$this->view->result[$key]->relationships[] = clone $r;
+				}
+				if (in_array($r->{$object_id}, $primary_ids)) {
+					$key = array_search($r->{$object_id}, $primary_ids);
+					$r->{$this->aliases['primary_id']} = $r->{$object_id};
+					$this->view->result[$key]->relationships[] = clone $r;
+				}
+			} //end of while
+    }// end of if add values
+
+		//for each stock in this view page, add the values
+		foreach ($values as $result) {
+			if (!empty($result->{$this->aliases['relationships']})) {
+				
+				// all relationships including the current stock
+				$relationships = $result->{$this->aliases['relationships']};
+				foreach ($relationships as $relationship) {			
+					// Add relationship to the list of items to be rendered
+					// Note: $this->aliases['primary_id'] = base table primary key
+					
+					$elements = array(
+					  $this->aliases['primary_id'] => $relationship->{$this->aliases['primary_id']},
+					  $this->aliases['relationship_primary_id'] => $relationship->{$this->aliases['relationship_primary_id']},
+					  'subject_id' => $relationship->{$this->aliases['subject_id']},
+					  'subject_name' => $relationship->subject_name,
+					  'object_id' => $relationship->{$this->aliases['object_id']},
+            'object_name' => $relationship->object_name,
+            'type_id' => $relationship->type_id,
+            'type_name' => $relationship->type_name,
+					);
+					$this->items[$relationship->{$this->aliases['primary_id']}][$relationship->{$this->aliases['relationship_primary_id']}] = $elements;
+				}
+			}
+		}
+	}
+
+  function render_item($count, $item) {
+		return $item['subject_name'].' '.$item['type_name'].' '.$item['object_name'];
+  }
+
+}
+

+ 1 - 1
tripal_core/views/handlers/views_handler_field_stockrel_by_type.inc → tripal_natural_diversity/views/handlers/views_handler_field_chado_relationship_by_type.inc

@@ -4,7 +4,7 @@
 /**
  * Field handler for terms.
  */
-class views_handler_field_stockrel_by_type extends views_handler_field_prerender_list {
+class views_handler_field_chado_relationship_by_type extends views_handler_field_prerender_list {
   function init(&$view, $options) {
     parent::init($view, $options);
 

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

@@ -52,6 +52,9 @@
 
   
   //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',
@@ -67,6 +70,96 @@
     '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)

+ 2 - 1
tripal_natural_diversity/views/nd_experimentprop.views.inc

@@ -121,6 +121,7 @@
     'argument' => array(
       'handler' => 'views_handler_argument_string',
     ),
-  );    
+  );  
+  
   return $data;
 }

+ 1 - 1
tripal_natural_diversity/views/nd_geolocation.views.inc

@@ -51,7 +51,7 @@
     'left_field' => 'nd_geolocation_id',
     'field' => 'nd_geolocation_id',
   );  
-   
+  
   //Table Field Definitions----------------------------------
       
   //Field: nd_geolocation_id (primary key)

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

@@ -0,0 +1,127 @@
+<?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;
+}

+ 38 - 127
tripal_natural_diversity/views/nd_reagent.views.inc

@@ -1,31 +1,4 @@
 <?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *   - Every instance of nd_reagent 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['nd_reagent']['table'] to $data['nd_reagent']['table']['base'] 
- *     and $data['nd_reagent']['table']['database'] to $data['nd_reagent']['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-nd_reagent/YYY => library_feature-XY => feature-nd_reagent/YYY) then make the join in both
- *     directions (ie: in the file nd_reagent.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_nd_reagent_views_data() function from ../tripal_natural_diversity.views.inc:tripal_natural_diversity_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_nd_reagent_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/nd_reagent.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
  
 /**
  *  @file
@@ -67,44 +40,21 @@
   //Basic table definition-----------------------------------
   $data['nd_reagent']['table']['group'] = t('Chado ND Reagent');
   
-  $data['nd_reagent']['table'] = array(
+  $data['nd_reagent']['table']['base'] = array(
     'field' => 'nd_reagent_id',
-    'title' => t('Chado ND Reagent'),
-    'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
+    'title' => t('Chado Natural Diversity Reagent'),
+    'help' => t('Reagents used in Natural Diversity Experiments.'),
   );
   if($database){
-     $data['nd_reagent']['table']['database'] = $database;
+     $data['nd_reagent']['table']['base']['database'] = $database;
   }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: nd_reagent => YYY
-  $data['nd_reagent']['table']['join']['YYY'] = array(
-    'left_field' => 'primary key in YYY table',
-    'field' => 'foreign key in nd_reagent table',
-  );  
-  
-  //Join: nd_reagent => XY => YYY
-  $data['nd_reagent']['table']['join']['XY'] = array(
-    'left_field' => 'matching nd_reagent key in the XY table',
-    'field' => 'foreign key in nd_reagent table',
-  );  
-  $data['nd_reagent']['table']['join']['YYY'] => array(
-    'left_table' => 'XY',
-    'left_field' => 'matching nd_reagent key in the XY table',
-    'field' => 'foreign key in nd_reagent table',
-  );
-  $data['XY']['table']['join']['YYY'] = array(
-    'left_field' => 'foreign key in YYY table',
-    'field' => 'matching YYY key in the XY table',
-  );
    
   //Table Field Definitions----------------------------------
       
   //Field: nd_reagent_id (primary key)
-  $data['nd_reagent']['field_name'] = array(
-    'title' => t('nd_reagent Primary Key'),
-    'help' => t('A unique index for every nd_reagent.'),
+  $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,
@@ -117,15 +67,10 @@
     ),
   );
 
-  /*.......................................................
-   * Beginning of Example Field definitions
-   * Remove this section when done
-   */
-
-  //Field: plain_text_field (chado datatype)   
-  $data['nd_reagent']['plain_text_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
+  //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,
@@ -141,70 +86,36 @@
     ),
   );
 
-  //Field: numeric_field (chado datatype)   
-  $data['nd_reagent']['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['nd_reagent']['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['nd_reagent']['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: 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',
+  	),
+	);
 
-  //Field: human_readable_date (chado datatype)   
-  $data['nd_reagent']['human_readable_date'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
+	//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(
-      'handler' => 'views_handler_field_readble_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
+      'title' => t('Relationships'),
+      'help' => t('Display a given type of relationships including the current reagent.'),
+      'handler' => 'views_handler_field_chado_relationship_by_type',
     ),
   );
-   
-   /*
-    * End of Example Field definitions
-    *......................................................./
-    
   return $data;
 }

+ 0 - 205
tripal_natural_diversity/views/nd_reagent_relationship.views.inc

@@ -1,205 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *   - Every instance of nd_reagent_relationship 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['nd_reagent_relationship']['table'] to $data['nd_reagent_relationship']['table']['base'] 
- *     and $data['nd_reagent_relationship']['table']['database'] to $data['nd_reagent_relationship']['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-nd_reagent_relationship/YYY => library_feature-XY => feature-nd_reagent_relationship/YYY) then make the join in both
- *     directions (ie: in the file nd_reagent_relationship.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_nd_reagent_relationship_views_data() function from ../tripal_natural_diversity.views.inc:tripal_natural_diversity_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_nd_reagent_relationship_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/nd_reagent_relationship.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 nd_reagent_relationship 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_relationship
- * @code
- * nd_reagent_relationship-Copy/Paste Table SQL code here-nd_reagent_relationship
- * @endcode
- */
- function retrieve_nd_reagent_relationship_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_relationship']['table']['group'] = t('Chado nd_reagent_relationship');
-  
-  $data['nd_reagent_relationship']['table'] = array(
-    'field' => 'primary_id',
-    'title' => t('Chado nd_reagent_relationship'),
-    'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
-  );
-  if($database){
-     $data['nd_reagent_relationship']['table']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: nd_reagent_relationship => YYY
-  $data['nd_reagent_relationship']['table']['join']['YYY'] = array(
-    'left_field' => 'primary key in YYY table',
-    'field' => 'foreign key in nd_reagent_relationship table',
-  );  
-  
-  //Join: nd_reagent_relationship => XY => YYY
-  $data['nd_reagent_relationship']['table']['join']['XY'] = array(
-    'left_field' => 'matching nd_reagent_relationship key in the XY table',
-    'field' => 'foreign key in nd_reagent_relationship table',
-  );  
-  $data['nd_reagent_relationship']['table']['join']['YYY'] => array(
-    'left_table' => 'XY',
-    'left_field' => 'matching nd_reagent_relationship key in the XY table',
-    'field' => 'foreign key in nd_reagent_relationship table',
-  );
-  $data['XY']['table']['join']['YYY'] = array(
-    'left_field' => 'foreign key in YYY table',
-    'field' => 'matching YYY key in the XY table',
-  );
-   
-  //Table Field Definitions----------------------------------
-      
-  //Field: nd_reagent_relationship_id (primary key)
-  $data['nd_reagent_relationship']['field_name'] = array(
-    'title' => t('nd_reagent_relationship Primary Key'),
-    'help' => t('A unique index for every nd_reagent_relationship.'),
-    '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['nd_reagent_relationship']['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['nd_reagent_relationship']['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['nd_reagent_relationship']['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['nd_reagent_relationship']['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['nd_reagent_relationship']['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;
-}

+ 28 - 108
tripal_natural_diversity/views/nd_reagentprop.views.inc

@@ -1,31 +1,4 @@
 <?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *   - Every instance of nd_reagentprop 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['nd_reagentprop']['table'] to $data['nd_reagentprop']['table']['base'] 
- *     and $data['nd_reagentprop']['table']['database'] to $data['nd_reagentprop']['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-nd_reagentprop/YYY => library_feature-XY => feature-nd_reagentprop/YYY) then make the join in both
- *     directions (ie: in the file nd_reagentprop.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_nd_reagentprop_views_data() function from ../tripal_natural_diversity.views.inc:tripal_natural_diversity_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_nd_reagentprop_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/nd_reagentprop.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
  
 /**
  *  @file
@@ -59,47 +32,30 @@
     $database = 'chado';
   }
    
-  //Basic table definition-----------------------------------
-  $data['nd_reagentprop']['table']['group'] = t('Chado nd_reagentprop');
-  
+  //Basic table definition-----------------------------------  
   $data['nd_reagentprop']['table'] = array(
     'field' => 'primary_id',
-    'title' => t('Chado nd_reagentprop'),
-    'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
+    '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 => YYY
-  $data['nd_reagentprop']['table']['join']['YYY'] = array(
-    'left_field' => 'primary key in YYY table',
-    'field' => 'foreign key in nd_reagentprop table',
-  );  
-  
-  //Join: nd_reagentprop => XY => YYY
-  $data['nd_reagentprop']['table']['join']['XY'] = array(
-    'left_field' => 'matching nd_reagentprop key in the XY table',
-    'field' => 'foreign key in nd_reagentprop table',
-  );  
-  $data['nd_reagentprop']['table']['join']['YYY'] => array(
-    'left_table' => 'XY',
-    'left_field' => 'matching nd_reagentprop key in the XY table',
-    'field' => 'foreign key in nd_reagentprop table',
-  );
-  $data['XY']['table']['join']['YYY'] = array(
-    'left_field' => 'foreign key in YYY table',
-    'field' => 'matching YYY key in the XY table',
+  //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']['field_name'] = array(
-    'title' => t('nd_reagentprop Primary Key'),
-    'help' => t('A unique index for every nd_reagentprop.'),
+  $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,
@@ -111,16 +67,10 @@
       'handler' => 'views_handler_filter_numeric',
     ),
   );
-
-  /*.......................................................
-   * Beginning of Example Field definitions
-   * Remove this section when done
-   */
-
-  //Field: plain_text_field (chado datatype)   
-  $data['nd_reagentprop']['plain_text_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
+  //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,
@@ -136,10 +86,10 @@
     ),
   );
 
-  //Field: numeric_field (chado datatype)   
-  $data['nd_reagentprop']['numeric_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
+  //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,
@@ -152,54 +102,24 @@
     ),
   );
 
-  //Field: boolean_field (chado datatype)   
-  $data['nd_reagentprop']['boolean_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
+  //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_boolean',
+      'handler' => 'views_handler_field_cvterm_name',
       'click sortable' => TRUE,
      ),
     'sort' => array(
       'handler' => 'views_handler_sort',
     ),
     'filter' => array(
-      'handler' => 'views_handler_filter_boolean_operator',
-    ),
-  );
-
-  //Field: unix_timestamp (chado datatype)   
-  $data['nd_reagentprop']['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',
+      'handler' => 'views_handler_filter_string',
     ),
-  );
-
-  //Field: human_readable_date (chado datatype)   
-  $data['nd_reagentprop']['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',
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
     ),
-  );
-   
-   /*
-    * End of Example Field definitions
-    *......................................................./
+  );  
     
   return $data;
 }

+ 9 - 0
tripal_stock/tripal_stock.module

@@ -942,3 +942,12 @@ function chado_stock_delete($node) {
   );
   tripal_db_set_active($previous_db);
 }
+
+/**************************************************************************
+ * @section 
+ **************************************************************************/
+
+function tripal_stock_preprocess_node_chado_stock (&$variables) {
+	$variables['testing1'] = 'test';
+	drupal_set_message('here');
+}

+ 0 - 65
tripal_stock/views/handlers/views_handler_argument_stockprop_id.inc

@@ -1,65 +0,0 @@
-<?php
-
-class views_handler_argument_stockprop_id extends views_handler_argument_string {
-
-	function options_form(&$form, &$form_state) {
-    parent::options_form($form, $form_state);   
-    unset($form['glossary']);
-    unset($form['limit']);
-    unset($form['add_table']);
-    unset($form['require_value']);
-    
-    //get options & display as options
-	  $previous_db = tripal_db_set_active('chado');
-    $result = db_query("SELECT cvt.cvterm_id as type_id, cvt.name FROM cvterm cvt WHERE cvt.cvterm_id IN (SELECT type_id FROM stockprop)");
-    tripal_db_set_active($previous_db);
-    $types = array();
-    while ($r = db_fetch_object($result)) { $types[$r->type_id] = $r->name; }
-		$form['stockprop_type_id'] = array(
-			'#type' => 'radios',
-			'#title' => t('Property Types'),
-			'#options' => $types,
-			'#default_value' => $this->options['stockprop_type_id'],
-			'#required' => TRUE,
-			'#description' => t('Select the type of property represented by this argument.'),
-		);
-		
-		$operators = array(
-      '=' => t('Is equal to'),
-      '!=' => t('Is not equal to'),
-      '~' => t('Contains'),
-      '!~' => t('Does not contain'),
-      'IS NOT NULL' => t('Is Present (Not Empty)'),
-      'IS NULL' => t('Is Absent (Empty)'),		
-		);
-		$form['operator'] = array(
-			'#type' => 'radios',
-			'#title' => 'Operator',
-			'#description' => t('Specify how to compare the argument with the property values.'),
-			'#options' => $operators,
-			'#default_value' => $this->options['operator'],
-			'#required' => TRUE,
-		);
-  }
-  
-  /**
-   * Build the query based upon the formula
-   */
-	function query() {
-    $argument = $this->argument;
-    if (!empty($this->options['transform_dash'])) {
-      $argument = strtr($argument, '-', ' ');
-    }
-    
-		if (preg_match('/IS NOT NULL/', $this->options['operator'])) {
-			$new_where_sql = "stock.stock_id IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=".$this->options['stockprop_type_id'].")";
-		} elseif (preg_match('/IS NULL/', $this->options['operator'])) {
-			$new_where_sql = "stock.stock_id NOT IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=".$this->options['stockprop_type_id'].")";
-		} else {
-			$new_where_sql = "stock.stock_id IN (SELECT stockprop.stock_id FROM stockprop "
-							. "WHERE stockprop.type_id=".$this->options['stockprop_type_id']." AND stockprop.value".$this->options['operator']."'".$argument."')";
-		}
-		$this->query->add_where($this->options['group'], $new_where_sql);
-  }
-
-}

+ 0 - 17
tripal_stock/views/handlers/views_handler_field_computed_stock_nid.inc

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

+ 0 - 1
tripal_stock/views/handlers/views_handler_field_stock_dbxref_all.inc

@@ -1 +0,0 @@
-../../../tripal_core/views/handlers/views_handler_field_stock_dbxref_all.inc

+ 0 - 1
tripal_stock/views/handlers/views_handler_field_stock_dbxref_by_type.inc

@@ -1 +0,0 @@
-../../../tripal_core/views/handlers/views_handler_field_stock_dbxref_by_type.inc

+ 0 - 1
tripal_stock/views/handlers/views_handler_field_stockprop_all.inc

@@ -1 +0,0 @@
-../../../tripal_core/views/handlers/views_handler_field_stockprop_all.inc

+ 0 - 1
tripal_stock/views/handlers/views_handler_field_stockprop_by_type.inc

@@ -1 +0,0 @@
-../../../tripal_core/views/handlers/views_handler_field_stockprop_by_type.inc

+ 0 - 1
tripal_stock/views/handlers/views_handler_field_stockrel_all.inc

@@ -1 +0,0 @@
-../../../tripal_core/views/handlers/views_handler_field_stockrel_all.inc

+ 0 - 1
tripal_stock/views/handlers/views_handler_field_stockrel_by_type.inc

@@ -1 +0,0 @@
-../../../tripal_core/views/handlers/views_handler_field_stockrel_by_type.inc

+ 0 - 238
tripal_stock/views/handlers/views_handler_filter_stock_dbxref_id.inc

@@ -1,238 +0,0 @@
-<?php
-// $Id$
-
-
-class views_handler_filter_stock_dbxref_id extends views_handler_filter {
-
-  function init(&$view, $options) {
-    parent::init($view, $options);
-    $this->db = $this->options['db'];
-  }
-  
-  function options_form(&$form, &$form_state) {
-    if ($this->can_expose()) {
-      $this->show_expose_button($form, $form_state);
-    }
-
-    $form['op_val_start'] = array('#value' => '<div class="clear-block">');
-
-    $this->types_form($form, $form_state);
-
-    $this->show_operator_form($form, $form_state);
-    $form['operator']['#prefix'] = '<div class="views-right-70">';
-    $this->show_value_form($form, $form_state);
-    $form['op_val_end'] = array('#value' => '</div>');
-
-    if ($this->can_expose()) {
-      $this->show_expose_form($form, $form_state);
-    }
-
-  }
-
-	function query () {
-		$this-> db = array_filter($this->db);
-		
-		if (preg_match('/IS NOT NULL/', $this->options['operator'])) {
-			$new_where_sql = "stock.stock_id IN "
-			."(SELECT stock_dbxref.stock_id FROM stock_dbxref, dbxref WHERE stock_dbxref.dbxref_id=dbxref.dbxref_id AND dbxref.db_id IN (".implode(', ',$this->db)."))";
-			$this->query->add_where($this->options['group'], $new_where_sql);
-		} elseif (preg_match('/IS NULL/', $this->options['operator'])) {
-			$new_where_sql = "stock.stock_id NOT IN "
-			."(SELECT stock_dbxref.stock_id FROM stock_dbxref, dbxref WHERE stock_dbxref.dbxref_id=dbxref.dbxref_id AND dbxref.db_id IN (".implode(', ',$this->db)."))";
-			$this->query->add_where($this->options['group'], $new_where_sql);
-		} else {
-			if (!empty($this->value)) {
-				$new_where_sql = "stock.stock_id IN "
-					."(SELECT stock_dbxref.stock_id FROM stock_dbxref, dbxref WHERE stock_dbxref.dbxref_id=dbxref.dbxref_id "
-					."AND dbxref.db_id IN (".implode(', ',$this->db).") AND dbxref.accession".$this->operator."'".$this->value."')";
-				$this->query->add_where($this->options['group'], $new_where_sql);
-			}
-		}
-	}
-  
-  /////////// Form Parts/////////////////////////
-  function types_form(&$form, &$form_state) {
-  
-    $db_options = tripal_db_get_db_options();
-	  ksort($db_options);
-    $form['db'] = array(
-      '#type' => 'checkboxes',
-      '#title' => t('Databases'),
-      '#options' => $db_options,
-      '#default_value' => $this->db,
-      '#prefix' => '<div class="views-left-30">',
-      '#suffix' => '</div>',
-    );
-
-  }
-
-  function value_form(&$form, &$form_state) {
-    parent::value_form(&$form, &$form_state);
-    
-		$form['value'] = array(
-  	  '#type' => 'textfield',
-    	'#title' => t('Accession'),
-      '#default_value' => $this->value,
-    );
-  }
-
-  function operator_options() {
-    return array(
-      '=' => t('Is equal to'),
-      '!=' => t('Is not equal to'),
-      '~' => t('Contains'),
-      '!~' => t('Does not contain'),
-      'IS NOT NULL' => t('Is Present (Not Empty)'),
-      'IS NULL' => t('Is Absent (Empty)'),
-    );
-  }
-
- /**
-  * Render our chunk of the exposed filter form when selecting
-  */
-  function exposed_form(&$form, &$form_state) {
-    if (empty($this->options['exposed'])) {
-      return;
-    }
-
-    if (!empty($this->options['expose']['use_type']) && !empty($this->options['expose']['type'])) {
-      $type = $this->options['expose']['type'];
-      $form[$type] = array(
-        '#type' => 'select',
-        '#title' => t('Database References'),
-        '#options' => $this->type_options(),
-        '#default_value' => $this->type,  
-      );
-
-      if (isset($form[$type]['#title'])) {
-        unset($form[$type]['#title']);
-      }
-    }
-
-    if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator'])) {
-      $operator = $this->options['expose']['operator'];
-      $this->operator_form($form, $form_state);
-      $form[$operator] = $form['operator'];
-
-      if (isset($form[$operator]['#title'])) {
-        unset($form[$operator]['#title']);
-      }
-
-      $this->exposed_translate($form[$operator], 'operator');
-
-      unset($form['operator']);
-    }
-
-    if (!empty($this->options['expose']['identifier'])) {
-      $value = $this->options['expose']['identifier'];
-      $this->value_form($form, $form_state);
-      $form[$value] = $form['value'];
-
-      if (isset($form[$value]['#title']) && !empty($form[$value]['#type']) && $form[$value]['#type'] != 'checkbox') {
-        unset($form[$value]['#title']);
-      }
-
-      $this->exposed_translate($form[$value], 'value');
-
-      if (!empty($form['#type']) && ($form['#type'] == 'checkboxes' || ($form['#type'] == 'select' && !empty($form['#multiple'])))) {
-        unset($form[$value]['#default_value']);
-      }
-
-      if (!empty($form['#type']) && $form['#type'] == 'select' && empty($form['#multiple'])) {
-        $form[$value]['#default_value'] = 'All';
-      }
-
-      if ($value != 'value') {
-        unset($form['value']);
-      }
-    }
-  }
-
-  function expose_form_left(&$form, &$form_state) {
-    $form['expose']['label'] = array(
-      '#type' => 'textfield',
-      '#default_value' => $this->options['expose']['label'],
-      '#title' => t('Label'),
-      '#size' => 40,
-    );
-
-    $form['expose']['identifier'] = array(
-      '#type' => 'textfield',
-      '#default_value' => $this->options['expose']['identifier'],
-      '#title' => t('Filter identifier'),
-      '#size' => 40,
-      '#description' => t('This will appear in the URL after the ? to identify this filter. Cannot be blank.'),
-    );
-
-  }
-
-  function expose_form_right(&$form, &$form_state) {
-    if (!empty($form['type']['#type'])) {
-      $form['expose']['use_type'] = array(
-        '#type' => 'checkbox',
-        '#title' => t('Unlock Database Reference'),
-        '#description' => t('When checked, the Database Reference will be exposed to the user'),
-        '#default_value' => !empty($this->options['expose']['use_type']),
-      );
-      $form['expose']['type'] = array(
-        '#type' => 'textfield',
-        '#default_value' => $this->options['expose']['type'],
-        '#title' => t('Database Reference identifier'),
-        '#size' => 40,
-        '#description' => t('This will appear in the URL after the ? to identify this Database Reference.'),
-        '#process' => array('views_process_dependency'),
-        '#dependency' => array(
-          'edit-options-expose-use-type' => array(1)
-        ),
-      );
-    }
-    else {
-      $form['expose']['type'] = array(
-        '#type' => 'value',
-        '#value' => '',
-      );
-    }
-
-    $form['expose']['identifier'] = array(
-      '#type' => 'textfield',
-      '#default_value' => $this->options['expose']['identifier'],
-      '#title' => t('Filter identifier'),
-      '#size' => 40,
-      '#description' => t('This will appear in the URL after the ? to identify this filter. Cannot be blank.'),
-    );
-
-    if (!empty($form['operator']['#type'])) {
-      $form['expose']['use_operator'] = array(
-        '#type' => 'checkbox',
-        '#title' => t('Unlock operator'),
-        '#description' => t('When checked, the operator will be exposed to the user'),
-        '#default_value' => !empty($this->options['expose']['use_operator']),
-      );
-      $form['expose']['operator'] = array(
-        '#type' => 'textfield',
-        '#default_value' => $this->options['expose']['operator'],
-        '#title' => t('Operator identifier'),
-        '#size' => 40,
-        '#description' => t('This will appear in the URL after the ? to identify this operator.'),
-        '#process' => array('views_process_dependency'),
-        '#dependency' => array(
-          'edit-options-expose-use-operator' => array(1)
-        ),
-      );
-    }
-    else {
-      $form['expose']['operator'] = array(
-        '#type' => 'value',
-        '#value' => '',
-      );
-    }
-    
-    $form['expose']['optional'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Optional'),
-      '#description' => t('This exposed filter is optional and will have added options to allow it not to be set.'),
-      '#default_value' => $this->options['expose']['optional'],
-    );
-  }
-}
-

+ 0 - 1
tripal_stock/views/handlers/views_handler_filter_stockprop_id.inc

@@ -1 +0,0 @@
-../../../tripal_core/views/handlers/views_handler_filter_stockprop_id.inc