浏览代码

Stock adheres to Coding Standards

laceysanderson 12 年之前
父节点
当前提交
6c42079a45
共有 27 个文件被更改,包括 1719 次插入1596 次删除
  1. 1 1
      tripal_library/tripal_library.module
  2. 30 27
      tripal_stock/other_module_api_functions.inc
  3. 116 110
      tripal_stock/tripal_stock-administration.inc
  4. 73 66
      tripal_stock/tripal_stock-db_references.inc
  5. 107 97
      tripal_stock/tripal_stock-properties.inc
  6. 140 118
      tripal_stock/tripal_stock-relationships.inc
  7. 41 32
      tripal_stock/tripal_stock-secondary_tables.inc
  8. 99 91
      tripal_stock/tripal_stock.api.inc
  9. 37 37
      tripal_stock/tripal_stock.install
  10. 316 299
      tripal_stock/tripal_stock.module
  11. 86 86
      tripal_stock/tripal_stock.views.inc
  12. 25 24
      tripal_stock/views/chado_stock.views.inc
  13. 43 39
      tripal_stock/views/handlers/views_handler_argument_stockprop_id.inc
  14. 15 14
      tripal_stock/views/handlers/views_handler_field_computed_stock_nid.inc
  15. 53 51
      tripal_stock/views/handlers/views_handler_field_stock_dbxref_all.inc
  16. 100 96
      tripal_stock/views/handlers/views_handler_field_stock_dbxref_by_type.inc
  17. 25 24
      tripal_stock/views/handlers/views_handler_field_stockprop_all.inc
  18. 18 15
      tripal_stock/views/handlers/views_handler_field_stockprop_by_type.inc
  19. 41 40
      tripal_stock/views/handlers/views_handler_field_stockrel_all.inc
  20. 16 14
      tripal_stock/views/handlers/views_handler_field_stockrel_by_type.inc
  21. 33 30
      tripal_stock/views/handlers/views_handler_filter_stock_dbxref_id.inc
  22. 99 89
      tripal_stock/views/handlers/views_handler_filter_stock_relationship_id.inc
  23. 57 51
      tripal_stock/views/handlers/views_handler_filter_stockprop_id.inc
  24. 6 5
      tripal_stock/views/misc_tables.views.inc
  25. 87 85
      tripal_stock/views/stock.views.inc
  26. 28 28
      tripal_stock/views/template.node_join.views.inc
  27. 27 27
      tripal_stock/views/template.table_defn.views.inc

+ 1 - 1
tripal_library/tripal_library.module

@@ -1693,7 +1693,7 @@ function tripal_library_cleanup($dummy = NULL, $job_id = NULL) {
       if ($job_id and $i % $interval == 0) {
          tripal_job_set_progress($job_id, intval(($i/$count)*100));
       }
-      $node = db_fetch_object(db_query($nsql, ß$nid->nid));
+      $node = db_fetch_object(db_query($nsql, $nid->nid));
       if (!$node) {
          db_query("DELETE FROM {chado_library} WHERE nid = $nid->nid");
          $message = "chado_library missing node.... DELETING: $nid->nid\n";

+ 30 - 27
tripal_stock/other_module_api_functions.inc

@@ -11,43 +11,46 @@
  * @params tablename: the name of the chado table you want to select the max rank from
  *    this table must contain a rank column of type integer
  * @params where_options: array(
- *													<column_name> => array(
- *														'type' => <type of column: INT/STRING>,
- *														'value' => <the value you want to filter on>,
- *														'exact' => <if TRUE use =; if FALSE use ~>,
- *													)
- *				)
+ *                          <column_name> => array(
+ *                            'type' => <type of column: INT/STRING>,
+ *                            'value' => <the value you want to filter on>,
+ *                            'exact' => <if TRUE use =; if FALSE use ~>,
+ *                          )
+ *        )
  *     where options should include the id and type for that table to correctly
  *     group a set of records together where the only difference are the value and rank
  * @return the maximum rank
  *
  */
-function get_max_chado_rank ($tablename, $where_options) {
+function get_max_chado_rank($tablename, $where_options) {
+
+  $where= array();
+  //generate the where clause from supplied options
+  // the key is the column name
+  foreach ($where_options as $key => $val_array) {
+    if (preg_match('/INT/', $val_array['type'])) {
+      $where[] = $key . "=" . $val_array['value'];
+    }
+     else {
+      if ($val_array['exact']) {
+      $operator='='; }
+      else { $operator='~'; }
+      $where[] = $key . $operator . "'" . $val_array['value'] . "'";
+    }
+  }
 
-	$where= array();
-	//generate the where clause from supplied options
-	// the key is the column name
-	foreach ($where_options as $key => $val_array) {
-		if (preg_match('/INT/', $val_array['type'])) {
-			$where[] = $key."=".$val_array['value'];
-		} else {
-			if ($val_array['exact']) { $operator='='; }
-			else { $operator='~'; }
-			$where[] = $key.$operator."'".$val_array['value']."'";
-		}
-	}
-	
   $previous_db = tripal_db_set_active('chado');
   $result = db_fetch_object(db_query(
     "SELECT max(rank) as max_rank, count(rank) as count FROM %s WHERE %s",
     $tablename,
-    implode(' AND ',$where)
+    implode(' AND ', $where)
   ));
   tripal_db_set_active($previous_db);
-	//drupal_set_message("Max Rank Query=SELECT max(rank) as max_rank, count(rank) as count FROM ".$tablename." WHERE ".implode(' AND ',$where));
-	if ($result->count > 0) {
-	  return $result->max_rank;
-	} else {
-		return -1;
-	}
+  //drupal_set_message("Max Rank Query=SELECT max(rank) as max_rank, count(rank) as count FROM ".$tablename." WHERE ".implode(' AND ',$where));
+  if ($result->count > 0) {
+    return $result->max_rank;
+  }
+  else {
+    return -1;
+  }
 }

+ 116 - 110
tripal_stock/tripal_stock-administration.inc

@@ -1,5 +1,5 @@
 <?php
-// $Id$
+
 
 /**
  * Purpose: Provide Guidance to new Tripal Admin
@@ -11,46 +11,46 @@
  */
 function tripal_stock_module_description_page() {
   $text = '';
-  
+
   $text = '<h3>Tripal Stock Administrative Tools Quick Links</h3>';
     $text .= '<ul>';
-      $text .= '<li>'.l('Configuration', 'admin/tripal/tripal_stock/configuration').'</li>';
-      $text .= '<li>'.l('Stock Listing', 'stocks').'</li>';
+      $text .= '<li>' . l('Configuration', 'admin/tripal/tripal_stock/configuration') . '</li>';
+      $text .= '<li>' . l('Stock Listing', 'stocks') . '</li>';
     $text .= '</ul>';
-    
+
   $text .= '<h3>Module Description:</h3>';
   //================================================================================
   $text .= '<p>The Tripal Stock Module provides functionality for adding, editing, deleting and accessing chado stocks. The stock module was designed to store information about stock collections in a laboratory. What is called a stock could also be called a strain or an accession. There is a lot in common between a Drosophila stock and a Saccharomyces strain and an Arabidopsis line. They all come from some taxon, have genotypes, physical locations in the lab, some conceivable relationship with a publication, some conceivable relationship with a sequence feature (such as a transgene), and could be described by some ontology term. For more information about the chado Stock Module <a href="http://gmod.org/wiki/Chado_Stock_Module">see the GMOD Wiki Page</a></p>';
-  
+
   $text .= '<h3>Setup Instructions:</h3>';
   //================================================================================
   $text .= '<ol>';
-  $text .= '<li><b>Set Ontologies</b>: Since at the time of this modules developement there is no accepted ontology for 
-            describing stocks, their properties and relationships, this module allows you to select the controlled 
-            vocabularies (CVs) in your Chado Database you would like to govern these data. To Set the Controlled Vocabularies for Stocks: 
-            First, ensure your Controlled Vocabulary is in Chado. This can be done by either loading an existing Ontology into Chado using 
-            the <a href="tripal_cv/ontology_loader">Tripal Ontology Loader</a> OR create your ontology from scratch by first 
+  $text .= '<li><b>Set Ontologies</b>: Since at the time of this modules developement there is no accepted ontology for
+            describing stocks, their properties and relationships, this module allows you to select the controlled
+            vocabularies (CVs) in your Chado Database you would like to govern these data. To Set the Controlled Vocabularies for Stocks:
+            First, ensure your Controlled Vocabulary is in Chado. This can be done by either loading an existing Ontology into Chado using
+            the <a href="tripal_cv/ontology_loader">Tripal Ontology Loader</a> OR create your ontology from scratch by first
             <a href="tripal_cv/add_cv">creating a controlled vocabulary</a> and then <a href="tripal_cv/add_cvterm">adding terms to it</a>.
-            Then go to the <a href="tripal_stock/configuration">Configuration Page for Stocks</a> and, in the "Set Stock Controlled Vocabularies" Fieldset, 
+            Then go to the <a href="tripal_stock/configuration">Configuration Page for Stocks</a> and, in the "Set Stock Controlled Vocabularies" Fieldset,
             select the Controlled Vocaulary name for Stock Types, Stock Properties and Stock Relationship Types.</li>';
       $text .= '<ol type="i">';
         $text .= '<li>Stock Types: When you are creating stocks, the type of each stock must be indicated. This might include "DNA extraction", "Individual Plant/Animal" or even "Progeny Population".</li>';
         $text .= '<li>Stock Properties: This module also allows you to assign properties to any stock. Each property has a type and a value where type is required an value is not. Therefore, if you want to say that a stock was grown at 23 degrees Celcius then the Type would be "temperature grown at" and the value would be 23 degrees Celcius. As such the Stock Properties controlled vocabulary might include "temperature grown at", "diet", "extraction date", "stock location", etc.</li>';
         $text .= '<li>Stock Relationship Types: You can also specify relationships between stocks. For example, a stock of type="DNA extraction" (Stock 1a) is related to the stock of type="Individual Plant/Animal" (Stock 1) that it was extracted from. Thus you might specify the relationship Stock 1 is the source material for Stock 1a where the relationship type is "is the source material for". As such Stock Relationship Types might include "is the source material for", "is maternal parent of", "is individual of population", etc.</li>';
       $text .= '</ol>';
-  
-  $text .= '<li><p><b>Set Permissions</b>: The stock module supports the Drupal user permissions interface for 
-               controlling access to stock content and functions. These permissions include viewing, 
+
+  $text .= '<li><p><b>Set Permissions</b>: The stock module supports the Drupal user permissions interface for
+               controlling access to stock content and functions. These permissions include viewing,
                creating, editing or administering of
-               stock content. The default is that only the original site administrator has these 
-               permissions.  You can <a href="'.url('admin/user/roles').'">add roles</a> for classifying users, 
-               <a href="'.url('admin/user/user').'">assign users to roles</a> and
-               <a href="'.url('admin/user/permissions').'">assign permissions</a> for the stock content to 
-               those roles.  For a simple setup, allow anonymous users access to view organism content and 
+               stock content. The default is that only the original site administrator has these
+               permissions.  You can <a href="' . url('admin/user/roles') . '">add roles</a> for classifying users,
+               <a href="' . url('admin/user/user') . '">assign users to roles</a> and
+               <a href="' . url('admin/user/permissions') . '">assign permissions</a> for the stock content to
+               those roles.  For a simple setup, allow anonymous users access to view organism content and
                allow the site administrator all other permissions.</p></li>';
-  
+
   $text .= '<li><b>Sync Stocks</b>: if you chado database already contains stocks, they need to be sync\'d with Drupal</b>. This creates Drupal Content including detail pages for each stock (known as nodes in Drupal). To sync\' Chado with Drupal simply go to the <a href="tripal_stock/configuration">Configuration Page for Stocks</a> and in the "Sync Stocks" Fieldset select the Organisms whose associated stocks you would like to sync. If this list doesn\'t contain an organism which you know is in Chado go to the Organism Configuration Page and make sure it is sync\'d with Drupal.</p>';
-  $text .= '</ol>';  
+  $text .= '</ol>';
   $text .= '<h3>Features of this Module:</h3>';
   //================================================================================
   $text .= '<ul>';
@@ -61,60 +61,60 @@ function tripal_stock_module_description_page() {
         $text .= '<li>Then you can Add External Database References. A Database Reference can be thought of as a synonym for the current stock where you want to specify a source for that synonym. The source would then be thought of as the database where a database can either be online and provide automatic linking out to the synonymous record or offline and simply be a text name of the source. To create a database reference with a given source you must first add the database to chado <a href="tripal_db/add_db">here</a>.</li>';
         $text .= '<li>Finally you can Add Relationships between Stocks. This allows you to specify, for example, the source material of a stock or one of it\'s parents. To create a relationship between your newly added stock and another stock, the other stock must first be created as this one was. Also, since the types of relationships is governed by a controlled vocabulary, just like with properties you have complete control over which relationships you want to allow. Once you click "Finish" you will be re-directed to the Details Page of the new Stock.</li>';
       $text .= '</ol></li>';
-      
+
   $text .= '<li><b>Details Page of a Stock:</b>';
   $text .= '<p>Each stock get\'s it\'s own page on this website. This page is meant to give an overall picture of the stock including listing the basic details, as well as, all properties, database references and relationships. To understand where it is -All page content in Drupal is known as a node and is given a unique identifier or nid. Thus every drupal page has a path of node/<nid>. You can get to the Details page for a given stock from either of the stock listings described below.</p>';
   $text .= '<p>If you want to customize the look of the stock Details page simply copy the PHP/HTML template node-chado_stock.tpl.php from theme_tripal to the base theme you are currently using. Then edit it as desired. There are plans to integrate this details page with Drupal Panels which will provide a much more user-friendly and no-programming-needed method to customize this page.</p>';
-  
+
   $text .= '<li><b>Adding/Updating/Deleting Stocks and their Properties, Database References and Relationships:</b>';
   $text .= '<p>The Stock Details Page also acts as a landing pad for updating/deleting stocks. To <b>update a stock</b>, go to the stocks details page and click on the Edit tab near the top of the page. This tab will only be visable if you have permission to edit chado stock content (See post installation steps above for information on setting user permissions). If you want to <b>delete a stock</b>, click the Edit tab and then near the bottom of the form, click the Delete button. This will delete the entire stock including it\'s properties, database references and any relationships including it.</p>';
   $text .= '<p>To <b>update/delete a given property of a stock</b>, click the "Edit Properties" Tab near the top of the stock details page. This form provides a listing of all existing properties for the given stock with form elements allowing you to change their value. After editing the properties you wanted to, simply click the "Update Properties" button to update all the properties for that stock. To delete a given property simply click the "Delete" Button beside the property you want to delete. You cannot undo this action! To <b>add a property to the given stock</b> simply fill out the "Add Property" form at the bottom of the "Edit Properties" Tab.</p>';
   $text .= '<p><b>Adding, updating and deleting Database References and Relationships</b> for a given stock is exactly the same as the method for properties. To edit Database References, click the "Edit DB References" tab and to add/edit/update stock relationships, click the "Edit Relationships" tab.</p></li>';
-  
+
   $text .= '<li><b><a href="../../stocks">Basic Listing of Stocks:</a></b>';
   $text .= '<p>This module also provides a basic listing of all stocks currently sync\'d with Drupal. To access this listing, there should be a Stocks Primary Menu item which links you to <a href="../../stocks">this page</a>. This page lists each stock on it\'s own row and provides a link to each stock by clicking on it\'s name. Currently there is no way to easily customize this listing.</p></li>';
-  
+
   $text .= '<li><b><a href="../build/views/">Flexible Listing of Stocks using Drupal Views:</a></b>';
   $text .= '<p>In order to access a more flexible listing of stocks you must first install the <a href="http://drupal.org/project/views">Drupal Views2 module</a>. You should then be able to access the default views <a href="../build/views/">here</a>. Essentially, Views is a module which allows you to create custom SQL queries completely through the web interface without knowing SQL. Furthermore, it also does some formatting of the results allowing you to display them as HTML lists, tables or grids. You can also expose filters to the user to let them customize the results they see and even implement various sorting.</p>';
   $text .= '<p>To use one of the Default Views simply click "Enable" and then "Edit" to change it to show exactly what you want. To view the current listing simply clikc "View Page" at the top of the Edit user interface. There are a number of good tutorials out there for Views2, any of which can be used to help you create your own custom listings of biological content. (Note: there aren\'t any tutorials specifically for tripal content but any tutorial for Views2 will show you how to use the views interface.</p></li>';
 
    $text .= '<h3>Page Customizations</h3>';
-   $text .= '<p>There are several ways to customize the look-and-feel for the way Chado data is presented through Tripal. 
+   $text .= '<p>There are several ways to customize the look-and-feel for the way Chado data is presented through Tripal.
              Below is a description of several methods.  These methods may be used in conjunction with one another to
-             provide fine-grained control. 
+             provide fine-grained control.
              <ul>
 
-             <li><p><b>Integration with Drupal Panels</b>:  <a href="http://drupal.org/project/views">Drupal Panels</a> 
-              allows for customization of a page layout if you don\'t want to do PHP/Javascript/CSS programming.  Tripal comes with pre-set layouts for stock pages.  However, 
+             <li><p><b>Integration with Drupal Panels</b>:  <a href="http://drupal.org/project/views">Drupal Panels</a>
+              allows for customization of a page layout if you don\'t want to do PHP/Javascript/CSS programming.  Tripal comes with pre-set layouts for stock pages.  However,
               Panels become useful if you prefer a layout that is different from the pre-set layouts.  Chado content
-              is provided to Panels in the form of Drupal "blocks" which you can then place anywhere on a page using the 
+              is provided to Panels in the form of Drupal "blocks" which you can then place anywhere on a page using the
               Panel\'s GUI.</p></li>
 
-             <li><p><b>Drupal\'s Content Construction Kit (CCK)</b>: the 
+             <li><p><b>Drupal\'s Content Construction Kit (CCK)</b>: the
              <a href="http://drupal.org/project/cck">Content Construction Kit (CCK) </a> is a powerful way to add non-Chado content
              to any page without need to edit template files or knowing PHP.  You must first download and install CCK.
              With CCK, the site administartor can create a new field to appear on the page.  For example, currently,
-             the Chado publication module is not yet supported by Tripal.  Therefore, the site administrator can add a text 
+             the Chado publication module is not yet supported by Tripal.  Therefore, the site administrator can add a text
              field to the stock pages.  This content is not stored in Chado, but will appear on the stock page.  A field
              added by CCK will also appear in the form when editing a stock to allow users to manually enter the appropriate
              text.  If the default pre-set layout and themeing for Tripal is used, it is better to create the CCK element,
-             indicate that it is not to be shown (using the CCK interface), then manually add the new content type 
+             indicate that it is not to be shown (using the CCK interface), then manually add the new content type
              where desired by editing the templates (as described below).  If using Panels, the CCK field can be added to the
              location desired using the Panels interface.</p></li>
 
              <li><p><b>Drupal Node Templates</b>:  The Tripal packages comes with a "theme_tripal" directory that contains the
              themeing for Chado content.    The stock module has a template file for stock "nodes" (Tripal stock pages).  This file
              is named "node-chado_stock.tpl.php", and provides javascript, HTML and PHP code for display of the stock
-             pages.  You can edit this file to control which types of information (or which stock "blocks") are displayed for stocks. Be sure to 
+             pages.  You can edit this file to control which types of information (or which stock "blocks") are displayed for stocks. Be sure to
              copy these template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as
              future Tripal updates may overwrite your customizations. See the <a href="http://tripal.sourceforge.net/">Tripal website </a>
              for instructions on how to access variables and other Chado content within the template file.</p></li>
 
              <li><p><b>Stock "Block" Templates</b>:  In the "theme_tripal" directory is a subdirectory named "tripal_stock".
              Inside this directory is a set of templates that control distinct types of information for stocks.  For example,
-             there is a "base" template for displaying of data directly from the Chado stock table, and a "references" 
+             there is a "base" template for displaying of data directly from the Chado stock table, and a "references"
              template for showing external site references for a stock (data from the stock_dbxref table).  These templates are used both by Drupal blocks
-             for use in Drupal Panels (as described above) or for use in the default pre-set layout that the node template 
+             for use in Drupal Panels (as described above) or for use in the default pre-set layout that the node template
              provides (also desribed above).  You can customize this template as you desire.  Be sure to copy the
              template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as
              future Tripal updates may overwrite your customizations.  See the <a href="http://tripal.sourceforge.net/">Tripal website </a>
@@ -123,14 +123,14 @@ function tripal_stock_module_description_page() {
 
              <li><p><b>Adding Links to the "Resources" Sidebar</b>: If you use the pre-set default Tripal layout for theming, you
              will see a "Resources" sidebar on each page.  The links that appear on the sidebar are automatically generated
-             using Javascript for all of the stock "Blocks" that appear on the page. If you want to add additional links 
-             (e.g. a dynamic link to additional stock content) and you want that link to appear in the 
-             "Resources" sidebar, simply edit the Drupal Node Template (as described above) and add the link to the 
+             using Javascript for all of the stock "Blocks" that appear on the page. If you want to add additional links
+             (e.g. a dynamic link to additional stock content) and you want that link to appear in the
+             "Resources" sidebar, simply edit the Drupal Node Template (as described above) and add the link to the
              section at the bottom of the template file where the resources section is found.</p></li>
 
              </ul>
-             </p>';  
-  
+             </p>';
+
   return $text;
 }
 
@@ -149,11 +149,11 @@ function tripal_stock_admin() {
    // currently processing jobs. If so, we don't want
    // to give the opportunity to sync Stocks
    $active_jobs = FALSE;
-   if(tripal_get_module_active_jobs('tripal_stock')){
+   if (tripal_get_module_active_jobs('tripal_stock')) {
       $active_jobs = TRUE;
    }
-   if($active_jobs){
-   
+   if ($active_jobs) {
+
    $form['notice'] = array(
          '#type' => 'fieldset',
          '#title' => t('Stock Management Temporarily Unavailable')
@@ -167,24 +167,25 @@ function tripal_stock_admin() {
             "jobs page."),
       );
 
-   } else {
+   }
+   else {
 
    // SET Vocabularies -----------------------------------------------------------------------------------------
    $form['set_cv'] = array(
       '#type' => 'fieldset',
       '#title' => t('Set Stock Controlled Vocabularies'),
       '#weight' => -10
-   );   
-   
+   );
+
    $form['set_cv']['message'] = array(
          '#value' => t("This setting allows you to set which chado controlled vocabularies (cv)"
-	              ." are used. Cvs are used to control user input for the type of stock,"
-		      ." any properties they enter for a stock & the types of relationships"
-		      ." between stocks. Only cvs already loaded into chado can be selected here.")
+                ." are used. Cvs are used to control user input for the type of stock,"
+          ." any properties they enter for a stock & the types of relationships"
+          ." between stocks. Only cvs already loaded into chado can be selected here.")
    );
 
    $cv_options = tripal_cv_get_cv_options();
-   
+
    $form['set_cv']['stock_types_cv'] = array(
      '#type' => 'select',
      '#title' => t('Controlled Vocabulary governing Stock Types'),
@@ -270,10 +271,10 @@ function tripal_stock_admin_validate($form, &$form_state) {
       //for each organism selected submit job (handled by tripal_stock_sync_stock_set)
       //  which syncs all stocks with an organism_id equal to the selelcted organism
       foreach ( $organisms_2b_syncd as $organism_id ) {
-        if($organism_id != 0) {
+        if ($organism_id != 0) {
           $job_args[0] = $organism_id;
-          tripal_add_job("Sync Stocks from Organism $organism_id",'tripal_stock',
-            'tripal_stock_sync_stock_set',$job_args,$user->uid);
+          tripal_add_job("Sync Stocks from Organism $organism_id", 'tripal_stock',
+            'tripal_stock_sync_stock_set', $job_args, $user->uid);
         }
       }
     }
@@ -285,7 +286,7 @@ function tripal_stock_admin_validate($form, &$form_state) {
     }
 }
 
-/** 
+/**
  * Syncs all Stocks associated with an organism
  *
  * Note: Handling of multiple organisms is done in tripal_stock_admin_validate()
@@ -301,16 +302,17 @@ function tripal_stock_admin_validate($form, &$form_state) {
  * @ingroup tripal_stock
  */
  function tripal_stock_sync_stock_set($organism_id, $job_id) {
-	global $user;
+  global $user;
 
-	if(!$organism_id) {
-		print '0 Stocks to Sync -No Organisms Selected.\n';
-	} else {
+  if (!$organism_id) {
+    print '0 Stocks to Sync -No Organisms Selected.\n';
+  }
+  else {
 
-		// Get list of stocks to sync
-		$previous_db = tripal_db_set_active('chado');
+    // Get list of stocks to sync
+    $previous_db = tripal_db_set_active('chado');
     $result = db_query(
-       "SELECT stock_id, uniquename, type_id, organism_id FROM stock WHERE organism_id=%d",
+       "SELECT stock_id, uniquename, type_id, organism_id FROM {stock} WHERE organism_id=%d",
        $organism_id
     );
     tripal_db_set_active($previous_db);
@@ -322,67 +324,71 @@ function tripal_stock_admin_validate($form, &$form_state) {
       // $r is the current stock to be sync'd
       $stocks_attempted++;
 
-      print 'Processing '.$r->uniquename."... ";
+      print 'Processing ' . $r->uniquename . "... ";
 
       // check not already in drupal
       $in_drupal_query = db_query(
-      	"SELECT * FROM {chado_stock} WHERE stock_id=%d",
-	 			$r->stock_id
+        "SELECT * FROM {chado_stock} WHERE stock_id=%d",
+         $r->stock_id
       );
       if ( !db_fetch_object($in_drupal_query) ) {
 
         //create new chado_stock node
         $new_node = new stdClass();
-	 			$new_node->type = 'chado_stock';
+         $new_node->type = 'chado_stock';
         $new_node->uid = $user->uid;
-	 			$new_node->title = $r->uniquename;
-	 			$new_node->type_id = $r->type_id;
-	 			$new_node->organism_id = $r->organism_id;
-	 			$new_node->stock_id = $r->stock_id;
+         $new_node->title = $r->uniquename;
+         $new_node->type_id = $r->type_id;
+         $new_node->organism_id = $r->organism_id;
+         $new_node->stock_id = $r->stock_id;
         $new_node->chado_stock_exists = TRUE;
-        
-	 			//print 'New Node:';
-	 			//print_r($new_node);
-	 			
-	 			node_validate($new_node);
-	 			
-        if(!form_get_errors()){
-	    		//print 'Try to Create Node ';
-        	$node = node_submit($new_node);
+
+         //print 'New Node:';
+         //print_r($new_node);
+
+         node_validate($new_node);
+
+        if (!form_get_errors()) {
+          //print 'Try to Create Node ';
+          $node = node_submit($new_node);
           node_save($node);
-          if($node->nid){
-          	$stocks_created_count++;
-	 
-						//Add stock id to chado_stock table
-						/**
-	 					db_query(
-	   	  			"INSERT INTO chado_stock (stock_id, nid, vid) VALUES (%d, %d, %d)",
-	   	  			$r->stock_id,
-	   	  			$node->nid,
-	   	  			$node->vid
-	 					);
-	 					*/
+          if ($node->nid) {
+            $stocks_created_count++;
+
+            //Add stock id to chado_stock table
+            /**
+             db_query(
+               "INSERT INTO chado_stock (stock_id, nid, vid) VALUES (%d, %d, %d)",
+               $r->stock_id,
+               $node->nid,
+               $node->vid
+             );
+             */
           }
-        } else {
-        	print "Not completed due to errors:\nCreate Stock Form Errors: ";
-	 				print_r(form_get_errors());
         }
-	 			print "Nid=".$node->nid."\n";
-			} else {
-				print "Skipped $r->uniquename because it's already in drupal.\n";
+        else {
+          print "Not completed due to errors:\nCreate Stock Form Errors: ";
+           print_r(form_get_errors());
+        }
+         print "Nid=" . $node->nid . "\n";
+      }
+      else {
+        print "Skipped $r->uniquename because it's already in drupal.\n";
       } //end of if not already in drupal
     } //end of while still stocks to be sync'd
   } //end of if organism_id not supplied
-   
+
   if ($stocks_attempted == 0) {
-		print "No stocks retrieved for organism (".$organism_id.")\n";
-		return 1;
-	} else {
-		if ($stocks_created_count > 0) {
-			print "$stocks_created_count Stocks Successfully Created\n";
-			return 1;
-		} else {
-			return 0;
-		}
-	}
-}
+    print "No stocks retrieved for organism (" . $organism_id . ")\n";
+    return 1;
+  }
+  else {
+    if ($stocks_created_count > 0) {
+      print "$stocks_created_count Stocks Successfully Created\n";
+      return 1;
+    }
+    else {
+      return 0;
+    }
+  }
+}

+ 73 - 66
tripal_stock/tripal_stock-db_references.inc

@@ -17,7 +17,7 @@
 function tripal_stock_add_ALL_dbreferences_page($node) {
   $output = '';
 
-  $output .= tripal_stock_add_chado_properties_progress('db_references').'<br>';
+  $output .= tripal_stock_add_chado_properties_progress('db_references') . '<br>';
   $output .= '<b>All Database References should strictly pertain to THE CURRENT Individual</b><br>';
   $output .= '<br>';
   $output .= theme('tripal_stock_references', $node);
@@ -112,29 +112,30 @@ function tripal_stock_add_ONE_dbreference_form_validate($form, &$form_state) {
 
     // Check database is valid db_id in chado
     if ( $form_state['values']['database'] > 0) {
-    	$previous_db = tripal_db_set_active('chado');
-    	$tmp_obj = db_fetch_object(db_query("SELECT count(*) as count FROM db WHERE db_id=%d",$form_state['values']['database']));
-    	tripal_db_set_active($previous_db);
-    	
+      $previous_db = tripal_db_set_active('chado');
+      $tmp_obj = db_fetch_object(db_query("SELECT count(*) as count FROM {db} WHERE db_id=%d", $form_state['values']['database']));
+      tripal_db_set_active($previous_db);
+
       if ($tmp_obj->count != 1) {
-        form_set_error('database', 'The database you selected is not valid. Please choose another one.'); 
+        form_set_error('database', 'The database you selected is not valid. Please choose another one.');
       }
-    } else {
+    }
+    else {
       form_set_error('database', 'Please select a database');
     }
 
     // Check Accession is unique for database
     $previous_db = tripal_db_set_active('chado');
-    $tmp_obj = db_fetch_object(db_query("SELECT count(*) as count FROM dbxref WHERE accession='%s'",$form_state['values']['accession']));
+    $tmp_obj = db_fetch_object(db_query("SELECT count(*) as count FROM {dbxref} WHERE accession='%s'", $form_state['values']['accession']));
     tripal_db_set_active($previous_db);
-    	
+
     if ($tmp_obj->count > 0) {
-      form_set_error('accession', 'This accession has already been assigned to another stock.'); 
+      form_set_error('accession', 'This accession has already been assigned to another stock.');
     }
 
   } //end of if adding
 
-} 
+}
 
 /**
  * Implements hoook_form_submit(): Actually adds the db reference to the stock
@@ -149,17 +150,18 @@ function tripal_stock_add_ONE_dbreference_form_validate($form, &$form_state) {
 function tripal_stock_add_ONE_dbreference_form_submit($form, &$form_state) {
 
   // FIX: Sometimes on programatic submission of form (drupal_execute) values in the form state get lost
-  // 	  however, the post values always seem to be correct
-  if (empty($form_state['values']['db_stock_id'])) { $form_state['values']['db_stock_id'] = $form_state['clicked_button']['#post']['db_stock_id']; }
+  //     however, the post values always seem to be correct
+  if (empty($form_state['values']['db_stock_id'])) {
+  $form_state['values']['db_stock_id'] = $form_state['clicked_button']['#post']['db_stock_id']; }
 
   // Only Create if valid
   if ($form_state['values']['database'] > 0) {
-    
+
 
     // create dbxref
     $previous_db = tripal_db_set_active('chado');
     db_query(
-      "INSERT INTO dbxref (db_id, accession, description) VALUES (%d, '%s', '%s')",
+      "INSERT INTO {dbxref} (db_id, accession, description) VALUES (%d, '%s', '%s')",
       $form_state['values']['database'],
       $form_state['values']['accession'],
       $form_state['values']['db_description']
@@ -168,18 +170,19 @@ function tripal_stock_add_ONE_dbreference_form_submit($form, &$form_state) {
 
     //create stock_dbxref
     $dbxref = tripal_db_get_dbxref_by_accession($form_state['values']['accession'], $form_state['values']['database']);
-		if (!empty($dbxref->dbxref_id)) {
-			$previous_db = tripal_db_set_active('chado');
-    	db_query(
-      	"INSERT INTO stock_dbxref (stock_id, dbxref_id) VALUES (%d, %d)",
-      	$form_state['values']['db_stock_id'],
-      	$dbxref->dbxref_id
-    	);
-			tripal_db_set_active($previous_db);
-
-    	drupal_set_message('Successfully Added Database Reference');
-    } else {
-    	drupal_set_message('Database reference NOT successfully created...','error');
+    if (!empty($dbxref->dbxref_id)) {
+      $previous_db = tripal_db_set_active('chado');
+      db_query(
+        "INSERT INTO {stock_dbxref} (stock_id, dbxref_id) VALUES (%d, %d)",
+        $form_state['values']['db_stock_id'],
+        $dbxref->dbxref_id
+      );
+      tripal_db_set_active($previous_db);
+
+      drupal_set_message('Successfully Added Database Reference');
+    }
+    else {
+      drupal_set_message('Database reference NOT successfully created...', 'error');
     } //end of if dbxref was created successfully
   } //end of if valid db reference
 
@@ -197,7 +200,7 @@ function tripal_stock_add_ONE_dbreference_form_submit($form, &$form_state) {
  *   HTML formatted output
  *
  * @ingroup tripal_stock
- */                                            
+ */
 function tripal_stock_edit_ALL_dbreferences_page($node) {
   $output = '';
 
@@ -209,10 +212,10 @@ function tripal_stock_edit_ALL_dbreferences_page($node) {
 
   return $output;
 }
-                                               
-/**                                            
+
+/**
  * Implements Hook_form(): Handles adding of Database References to Stocks
- * 
+ *
  * Specifically this adds dbxrefs to a current stock using the stock_dbxref table
  *
  * @param $form_state
@@ -224,7 +227,7 @@ function tripal_stock_edit_ALL_dbreferences_page($node) {
  *   An array describing the form to be rendered
  *
  * @ingroup tripal_stock
- */                                        
+ */
 function tripal_stock_edit_ALL_db_references_form($form_state, $node) {
   $form = array();
 
@@ -237,17 +240,18 @@ function tripal_stock_edit_ALL_db_references_form($form_state, $node) {
   );
 
   $i=0;
-  if (!$node->stock->stock_dbxref) { 
-    $node->stock->stock_dbxref = array(); 
-  } elseif (!is_array($node->stock->stock_dbxref)) { 
-    $node->stock->stock_dbxref = array($node->stock->stock_dbxref); 
-  }  
+  if (!$node->stock->stock_dbxref) {
+    $node->stock->stock_dbxref = array();
+  }
+  elseif (!is_array($node->stock->stock_dbxref)) {
+    $node->stock->stock_dbxref = array($node->stock->stock_dbxref);
+  }
   if (sizeof($node->stock->stock_dbxref) != 0) {
   foreach ($node->stock->stock_dbxref as $ref) {
     $i++;
     $form["num-$i"] = array(
       '#type' => 'item',
-      '#value' => $i.'.'
+      '#value' => $i . '.'
     );
 
     $form["accession-$i"] = array(
@@ -261,10 +265,10 @@ function tripal_stock_edit_ALL_db_references_form($form_state, $node) {
     $db_options = tripal_db_get_db_options();
     $db_options[0] = 'Select a Database';
     ksort($db_options);
-    $form["database-$i"] = array( 
-      '#type' => 'select', 
+    $form["database-$i"] = array(
+      '#type' => 'select',
       //'#title' => t('Database'),
-      '#options' => $db_options, 
+      '#options' => $db_options,
       '#default_value' => $ref->dbxref_id->db_id->db_id
     );
 
@@ -311,22 +315,24 @@ function tripal_stock_edit_ALL_db_references_form_submit($form, &$form_state) {
      //Update all
      for ($i=1; $i<=$form_state['values']['num_db_references']; $i++) {
        tripal_stock_update_db_reference(
-					$form_state['values']["id-$i"], 
-					$form_state['values']["database-$i"], 
-					$form_state['values']["accession-$i"]
-			);
+          $form_state['values']["id-$i"],
+          $form_state['values']["database-$i"],
+          $form_state['values']["accession-$i"]
+      );
      }
      drupal_set_message("Updated all Database References");
-     drupal_goto('node/'.$form_state['values']['nid']);
+     drupal_goto('node/' . $form_state['values']['nid']);
 
-  } elseif ( preg_match('/Delete #(\d+)/', $form_state['clicked_button']['#value'], $matches) ) {
+  }
+  elseif ( preg_match('/Delete #(\d+)/', $form_state['clicked_button']['#value'], $matches) ) {
 
      $i = $matches[1];
      tripal_stock_delete_db_reference($form_state['values']["id-$i"]);
      drupal_set_message("Deleted Database Reference");
 
-  } else {
-    drupal_set_message("Unrecognized Button Pressed",'error');
+  }
+  else {
+    drupal_set_message("Unrecognized Button Pressed", 'error');
   }
 
 }
@@ -349,8 +355,8 @@ function tripal_stock_update_db_reference($dbxref_id, $database_id, $accession)
 
   $previous_db = tripal_db_set_active('chado');
   db_query(
-    "UPDATE dbxref SET db_id=%d, accession='%s' WHERE dbxref_id=%d",
-    $database_id, 
+    "UPDATE {dbxref} SET db_id=%d, accession='%s' WHERE dbxref_id=%d",
+    $database_id,
     $accession,
     $dbxref_id
   );
@@ -373,12 +379,12 @@ function tripal_stock_delete_db_reference($dbxref_id) {
 
   $previous_db = tripal_db_set_active('chado');
   db_query(
-    "DELETE FROM dbxref WHERE dbxref_id=%d",
+    "DELETE FROM {dbxref} WHERE dbxref_id=%d",
     $dbxref_id
   );
 
   db_query(
-    "DELETE FROM stock_dbxref WHERE dbxref_id=%d",
+    "DELETE FROM {stock_dbxref} WHERE dbxref_id=%d",
     $dbxref_id
   );
   tripal_db_set_active($previous_db);
@@ -391,26 +397,26 @@ function tripal_stock_delete_db_reference($dbxref_id) {
  * @param $form
  *   An array describing the form to be themed
  *
- * @return 
+ * @return
  *   An HTML rendering of the form
  *
  * @ingroup tripal_stock
  */
-function theme_tripal_stock_edit_ALL_db_references_form ($form) {
+function theme_tripal_stock_edit_ALL_db_references_form($form) {
   $output = '';
 
   $output .= '<br><fieldset>';
   $output .= '<legend>Edit Existing Database References<span class="form-optional" title="This field is optional">(optional)</span></legend>';
   $output .= '<p>Below is a list of already existing database references, one per line. When entering a database reference, the accession '
-  	     .'is a unique identifier for this stock in the specified database.</p>';
+         .'is a unique identifier for this stock in the specified database.</p>';
   $output .= '<table>';
   $output .= '<tr><th>#</th><th>Database</th><th>Accession</th><th></th></tr>';
 
   for ($i=1; $i<=$form['num_db_references']['#value']; $i++) {
-    $output .= '<tr><td>'.drupal_render($form["num-$i"]).'</td><td>'
-    	       .drupal_render($form["database-$i"]).'</td><td>'
-	       .drupal_render($form["accession-$i"]).'</td><td>'
-	       .drupal_render($form["submit-$i"]).'</td></tr>';
+    $output .= '<tr><td>' . drupal_render($form["num-$i"]) . '</td><td>'
+             . drupal_render($form["database-$i"]) . '</td><td>'
+         . drupal_render($form["accession-$i"]) . '</td><td>'
+         . drupal_render($form["submit-$i"]) . '</td></tr>';
   }
 
   $output .= '</table><br>';
@@ -441,14 +447,15 @@ function tripal_stock_list_dbreferences_for_node($db_references) {
     $output .= '<tr><th>Database</th><th>Accession</th></tr>';
 
     foreach ($db_references as $db) {
-        $output .= '<tr><td>'.$db->db_name.'</td><td>'.$db->accession.'</td></tr>';
-    } // end of foreach db reference 
+        $output .= '<tr><td>' . $db->db_name . '</td><td>' . $db->accession . '</td></tr>';
+    } // end of foreach db reference
 
-    $output .= '</table>'; 
+    $output .= '</table>';
 
-  } else {
+  }
+  else {
     $output = 'No Database References Added to the Current Stock';
-  }              
+  }
 
   return $output;
-}     
+}

+ 107 - 97
tripal_stock/tripal_stock-properties.inc

@@ -1,14 +1,14 @@
 <?php
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
 function tripal_stock_add_ALL_property_page($node) {
   $output = '';
 
-  $output .= tripal_stock_add_chado_properties_progress('properties').'<br>';
+  $output .= tripal_stock_add_chado_properties_progress('properties') . '<br>';
   $output .= '<b>All Properties should strictly pertain to THE CURRENT Individual</b><br>';
   $output .= '<br>';
   $output .= theme('tripal_stock_properties', $node);
@@ -20,7 +20,7 @@ function tripal_stock_add_ALL_property_page($node) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
@@ -31,17 +31,17 @@ function tripal_stock_add_ONE_property_form($form_state, $node) {
   $form['add_properties'] = array(
     '#type' => 'fieldset',
     '#title' => t('Add Property') . '<span class="form-optional" title="This field is optional"> (optional)</span>',
-  ); 
+  );
 
   $form['prop_nid'] = array(
     '#type' => 'hidden',
     '#value' => $node->nid
   );
 
-	$tmp_obj = tripal_cv_get_cvterm_by_name('synonym', variable_get('chado_stock_prop_types_cv', 'null'));
-	$synonym_id = $tmp_obj->cvterm_id;
-	
-  $prop_type_options = tripal_cv_get_cvterm_options( variable_get('chado_stock_prop_types_cv', 'null') ); 
+  $tmp_obj = tripal_cv_get_cvterm_by_name('synonym', variable_get('chado_stock_prop_types_cv', 'null'));
+  $synonym_id = $tmp_obj->cvterm_id;
+
+  $prop_type_options = tripal_cv_get_cvterm_options( variable_get('chado_stock_prop_types_cv', 'null') );
   $prop_type_options[0] = 'Select a Type';
   ksort($prop_type_options);
   $form['add_properties']['prop_type_id'] = array(
@@ -67,7 +67,7 @@ function tripal_stock_add_ONE_property_form($form_state, $node) {
   );
 
   $form['add_properties']['submit-add'] = array(
-    '#type' => 'submit',         
+    '#type' => 'submit',
     '#value' => t('Add Property')
   );
 
@@ -75,7 +75,7 @@ function tripal_stock_add_ONE_property_form($form_state, $node) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
@@ -84,18 +84,19 @@ function tripal_stock_add_ONE_property_form_validate($form, &$form_state) {
   // Only Require if Adding Property
   if ($form_state['clicked_button']['#value'] == t('Add Property') ) {
 
-		// Check that there is a stock
-		if ( $form_state['values']['prop_stock_id'] <= 0 ) {
-			form_set_error('prop_stock_id', 'There is no associated stock.');
-		}
-		
+    // Check that there is a stock
+    if ( $form_state['values']['prop_stock_id'] <= 0 ) {
+      form_set_error('prop_stock_id', 'There is no associated stock.');
+    }
+
     // Check that Selected a type
     if ( $form_state['values']['prop_type_id'] == 0) {
       form_set_error('prop_type_id', 'Please select a type of property.');
-    } else {
+    }
+    else {
       // Check that type is in chado
       $previous_db = tripal_db_set_active('chado');
-      $num_rows = db_fetch_object(db_query("SELECT count(*) as count FROM cvterm WHERE cvterm_id=%d", $form_state['values']['prop_type_id']));
+      $num_rows = db_fetch_object(db_query("SELECT count(*) as count FROM {cvterm} WHERE cvterm_id=%d", $form_state['values']['prop_type_id']));
       tripal_db_set_active($previous_db);
       if ( $num_rows->count != 1) {
         form_set_error('prop_type_id', "The type you selected is not valid. Please choose another one. (CODE:$num_rows)");
@@ -115,24 +116,26 @@ function tripal_stock_add_ONE_property_form_validate($form, &$form_state) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
 function tripal_stock_add_ONE_property_form_submit($form, &$form_state) {
-	
+
   // if there is a property add it (only won't be a property if clicked next step w/ no property)
   if ($form_state['values']['prop_type_id'] != 0) {
     //determine the rank for this property
-    $max_rank = get_max_chado_rank('stockprop', 
-    															array('stock_id'=>array('type'=>'INT','value'=>$form_state['values']['prop_stock_id']), 
-    																		'type_id'=>array('type'=>'INT','value'=> $form_state['values']['prop_type_id']) ));
-    if ($max_rank == -1) { $rank = 0; 
-    } else { $rank = $max_rank+1; }
-    
+    $max_rank = get_max_chado_rank('stockprop',
+                                  array('stock_id' => array('type' => 'INT', 'value' => $form_state['values']['prop_stock_id']),
+                                        'type_id' => array('type' => 'INT', 'value' => $form_state['values']['prop_type_id']) ));
+    if ($max_rank == -1) {
+    $rank = 0;
+    }
+    else { $rank = $max_rank+1; }
+
     $previous_db = tripal_db_set_active('chado');
     db_query(
-      "INSERT INTO stockprop (stock_id, type_id, value, rank) VALUES (%d, %d, '%s', %d)",
+      "INSERT INTO {stockprop} (stock_id, type_id, value, rank) VALUES (%d, %d, '%s', %d)",
       $form_state['values']['prop_stock_id'],
       $form_state['values']['prop_type_id'],
       $form_state['values']['prop_value'],
@@ -148,11 +151,11 @@ function tripal_stock_add_ONE_property_form_submit($form, &$form_state) {
       //use update node form so that both title and name get set
       $node = node_load($form_state['values']['prop_nid']);
       $node->title = $form_state['values']['prop_value'];
-      $node_form_state = array( 
+      $node_form_state = array(
         'values' => array(
-					'title' => $form_state['values']['prop_value'], 
-					'op' => 'Save'
-				) 
+          'title' => $form_state['values']['prop_value'],
+          'op' => 'Save'
+        )
       );
       module_load_include('inc', 'node', 'node.pages');
       drupal_execute('chado_stock_node_form', $node_form_state, $node);
@@ -163,7 +166,7 @@ function tripal_stock_add_ONE_property_form_submit($form, &$form_state) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
@@ -196,17 +199,18 @@ function tripal_stock_edit_ALL_properties_form($form_state, $node) {
   );
 
   $i=0;
-  if (!$node->stock->stockprop) { 
-    $node->stock->stockprop = array(); 
-  } elseif (!is_array($node->stock->stockprop)) { 
-    $node->stock->stockprop = array($node->stock->stockprop); 
+  if (!$node->stock->stockprop) {
+    $node->stock->stockprop = array();
+  }
+  elseif (!is_array($node->stock->stockprop)) {
+    $node->stock->stockprop = array($node->stock->stockprop);
   }
   if (sizeof($node->stock->stockprop) != 0) {
   foreach ($node->stock->stockprop as $property) {
     $i++;
     $form["num-$i"] = array(
       '#type' => 'item',
-      '#value' => $i.'.'
+      '#value' => $i . '.'
     );
 
     $form["id-$i"] = array(
@@ -250,7 +254,7 @@ function tripal_stock_edit_ALL_properties_form($form_state, $node) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
@@ -262,76 +266,81 @@ function tripal_stock_edit_ALL_properties_form_submit($form, &$form_state) {
        tripal_stock_update_property($form_state['values']["id-$i"], $form_state['values']["type-$i"], $form_state['values']["value-$i"], $form_state['values']["preferred-$i"], $form_state['values']["nid"]);
      }
      drupal_set_message("Updated all Properties");
-     drupal_goto('node/'.$form_state['values']['nid']);
-  } elseif ( preg_match('/Delete #(\d+)/', $form_state['clicked_button']['#value'], $matches) ) {
+     drupal_goto('node/' . $form_state['values']['nid']);
+  }
+  elseif ( preg_match('/Delete #(\d+)/', $form_state['clicked_button']['#value'], $matches) ) {
      $i = $matches[1];
      tripal_stock_delete_property($form_state['values']["id-$i"], $form_state['values']["type-$i"], $form_state['values']["value-$i"]);
      drupal_set_message("Deleted Property");
-  } else {
-    drupal_set_message("Unrecognized Button Pressed",'error');
+  }
+  else {
+    drupal_set_message("Unrecognized Button Pressed", 'error');
   }
 
-  
+
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
 function tripal_stock_update_property($stockprop_id, $cvterm_id, $value, $preferred, $nid) {
 
-	$previous_db = tripal_db_set_active('chado');
-	$old_obj = db_fetch_object(db_query("SELECT * FROM stockprop WHERE stockprop_id=%d",$stockprop_id));
-	tripal_db_set_active($previous_db);
-	
-	// if they changed the type need to check rank
-	//   (if there is another property of the same type then rank needs to be increased to prevent collisions)
-	if ($cvterm_id == $old_obj->type_id) {
-	  $previous_db = tripal_db_set_active('chado');
-  	db_query(
-    	"UPDATE stockprop SET type_id=%d, value='%s' WHERE stockprop_id=%d",
-    	$cvterm_id, 
-    	$value,
-    	$stockprop_id
-  	);
-  	tripal_db_set_active($previous_db);
-  } else {
+  $previous_db = tripal_db_set_active('chado');
+  $old_obj = db_fetch_object(db_query("SELECT * FROM {stockprop} WHERE stockprop_id=%d", $stockprop_id));
+  tripal_db_set_active($previous_db);
+
+  // if they changed the type need to check rank
+  //   (if there is another property of the same type then rank needs to be increased to prevent collisions)
+  if ($cvterm_id == $old_obj->type_id) {
+    $previous_db = tripal_db_set_active('chado');
+    db_query(
+      "UPDATE {stockprop} SET type_id=%d, value='%s' WHERE stockprop_id=%d",
+      $cvterm_id,
+      $value,
+      $stockprop_id
+    );
+    tripal_db_set_active($previous_db);
+  }
+  else {
       //determine the rank for this property
-    $max_rank = get_max_chado_rank('stockprop', 
-    															array('stock_id'=>array('type'=>'INT','value'=> $old_obj->stock_id), 
-    																		'type_id'=>array('type'=>'INT','value'=> $cvterm_id ) ));
-    if ($max_rank == -1) { $rank = 0; 
-    } else { $rank = $max_rank+1; }
-	  $previous_db = tripal_db_set_active('chado');
-  	db_query(
-    	"UPDATE stockprop SET type_id=%d, value='%s', rank=%d WHERE stockprop_id=%d",
-    	$cvterm_id, 
-    	$value,
-    	$rank,
-    	$stockprop_id
-  	);
-  	tripal_db_set_active($previous_db);  	
+    $max_rank = get_max_chado_rank('stockprop',
+                                  array('stock_id' => array('type' => 'INT', 'value' => $old_obj->stock_id),
+                                        'type_id' => array('type' => 'INT', 'value' => $cvterm_id ) ));
+    if ($max_rank == -1) {
+    $rank = 0;
+    }
+    else { $rank = $max_rank+1; }
+    $previous_db = tripal_db_set_active('chado');
+    db_query(
+      "UPDATE {stockprop} SET type_id=%d, value='%s', rank=%d WHERE stockprop_id=%d",
+      $cvterm_id,
+      $value,
+      $rank,
+      $stockprop_id
+    );
+    tripal_db_set_active($previous_db);
   }
 
   // Set Preferred Synonym
-  //use update node form so that both title and name get set                                                                                                                                                                       
+  //use update node form so that both title and name get set
   if ($preferred) {
-    $node = node_load($nid);                                                                                                                                                                            
-    $node->title = $value;                                                                                                                                                                              
-    $node_form_state = array(                                                                                                                                                                                                        
-      'values' => array(                                                                                                                                                                                                             
-        'title' => $value,                                                                                                                                               
-        'op' => 'Save'                                                                                                                                                                                
-      )                                                                                                                                                                                                            
-    );                                                                                                                                                                                                                               
-    module_load_include('inc', 'node', 'node.pages');                                                                                                                                                                                
-    drupal_execute('chado_stock_node_form', $node_form_state, $node);  
+    $node = node_load($nid);
+    $node->title = $value;
+    $node_form_state = array(
+      'values' => array(
+        'title' => $value,
+        'op' => 'Save'
+      )
+    );
+    module_load_include('inc', 'node', 'node.pages');
+    drupal_execute('chado_stock_node_form', $node_form_state, $node);
   }
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
@@ -339,7 +348,7 @@ function tripal_stock_delete_property($stockprop_id) {
 
   $previous_db = tripal_db_set_active('chado');
   db_query(
-    "DELETE FROM stockprop WHERE stockprop_id=%d",
+    "DELETE FROM {stockprop} WHERE stockprop_id=%d",
     $stockprop_id
   );
   tripal_db_set_active($previous_db);
@@ -347,24 +356,24 @@ function tripal_stock_delete_property($stockprop_id) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
-function theme_tripal_stock_edit_ALL_properties_form ($form) {
+function theme_tripal_stock_edit_ALL_properties_form($form) {
   $output = '';
 
   $output .= '<br><fieldset>';
   $output .= '<legend>Edit Already Existing Properties<span class="form-optional" title="This field is optional">(optional)</span></legend>';
   $output .= '<p>Below is a list of already existing properties for this stock, one property per line. The type refers to the type of '
-  	     .'property and the value is the value for that property. For example, if this stock has a seed coat colour of green then '
-	     .'the property type=sead coat colour and the value=green. When the type of property is synonym, there is an extra checkbox '
-	     .'allowing you to specify which is the <b>Preferred Synonym</b>. This will change the current name of the stock.</p>';
+         .'property and the value is the value for that property. For example, if this stock has a seed coat colour of green then '
+       .'the property type=sead coat colour and the value=green. When the type of property is synonym, there is an extra checkbox '
+       .'allowing you to specify which is the <b>Preferred Synonym</b>. This will change the current name of the stock.</p>';
   $output .= '<table>';
   $output .= '<tr><th>#</th><th>Type</th><th>Value</th><th></th></tr>';
 
   for ($i=1; $i<=$form['num_properties']['#value']; $i++) {
-    $output .= '<tr><td>'.drupal_render($form["num-$i"]).'</td><td>'.drupal_render($form["type-$i"]).'</td><td>'.drupal_render($form["value-$i"]).drupal_render($form["preferred-$i"]).'</td><td>'.drupal_render($form["submit-$i"]).'</td></tr>';
+    $output .= '<tr><td>' . drupal_render($form["num-$i"]) . '</td><td>' . drupal_render($form["type-$i"]) . '</td><td>' . drupal_render($form["value-$i"]) . drupal_render($form["preferred-$i"]) . '</td><td>' . drupal_render($form["submit-$i"]) . '</td></tr>';
   }
 
   $output .= '</table><br>';
@@ -375,7 +384,7 @@ function theme_tripal_stock_edit_ALL_properties_form ($form) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
@@ -387,21 +396,22 @@ function tripal_stock_list_properties_for_node($properties, $synonyms) {
 
     if (!empty($synonyms) ) {
       foreach ($synonyms as $s) {
-        $output .= '<tr><td>synonym</td><td>'.$s.'</td></tr>';
+        $output .= '<tr><td>synonym</td><td>' . $s . '</td></tr>';
       }
     }
 
     if (!empty($properties) ) {
       foreach ($properties as $p) {
-        $output .= '<tr><td>'.$p->type.'</td><td>'.$p->value.'</td></tr>';
+        $output .= '<tr><td>' . $p->type . '</td><td>' . $p->value . '</td></tr>';
       } // end of foreach property
     }
 
     $output .= '</table>';
 
-  } else {
+  }
+  else {
     $output = 'No Properties Added to the Current Stock';
   }
 
   return $output;
-}
+}

+ 140 - 118
tripal_stock/tripal_stock-relationships.inc

@@ -1,15 +1,15 @@
 <?php
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
 function tripal_stock_add_ALL_relationships_page($node) {
   $output = '';
 
-  $output .= tripal_stock_add_chado_properties_progress('relationships').'<br>';
-  $output .= '<b>All Relationships should include the CURRENT Individual ('.$node->stock->uniquename.')</b><br>';
+  $output .= tripal_stock_add_chado_properties_progress('relationships') . '<br>';
+  $output .= '<b>All Relationships should include the CURRENT Individual (' . $node->stock->uniquename . ')</b><br>';
   $output .= '<br>';
   $output .= theme('tripal_stock_relationships', $node);
   $output .= '<br><br>';
@@ -31,9 +31,9 @@ function tripal_stock_add_ONE_relationship_form($form_state, $node) {
   $_SESSION['organism'] = $organism_id; //needed for autocomplete enter stock to work
 
   $form['rel_nid'] = array(
-    '#type' => 'hidden', 
+    '#type' => 'hidden',
     '#value' => $node->nid
-  ); 
+  );
 
   $form['add_relationships'] = array(
     '#type' => 'fieldset',
@@ -85,7 +85,7 @@ function tripal_stock_add_ONE_relationship_form($form_state, $node) {
 
   );
 
-  $form['add_relationships']['r_stock_uniquename'] = array( 
+  $form['add_relationships']['r_stock_uniquename'] = array(
     '#type' => 'value',
     '#value' => $node->stock->uniquename,
     '#required' => TRUE
@@ -96,7 +96,7 @@ function tripal_stock_add_ONE_relationship_form($form_state, $node) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
@@ -108,15 +108,18 @@ function tripal_stock_add_ONE_relationship_form_validate($form, &$form_state) {
     $subject_results = tripal_stock_get_stock_by_name_identifier( $form_state['values']['subject_id'], $_SESSION['organism']);
     if (sizeof($subject_results) > 1) {
       $links= array();
-      for ($i=0; $i<sizeof($subject_results); $i++) { $links[] = l($i+1, "node/".$subject_results[$i]->nid); }
-      $message = "Too many stocks match '".$form_state['values']['subject_id']."'! "
-      	       	 . " Please refine your input to match ONLY ONE stock. <br>"
-		 . "To aid in this process, here are the stocks that match your initial input: "
-		 .join(', ',$links);
+      for ($i=0; $i<sizeof($subject_results); $i++) {
+      $links[] = l($i+1, "node/" . $subject_results[$i]->nid); }
+      $message = "Too many stocks match '" . $form_state['values']['subject_id'] . "'! "
+                  . " Please refine your input to match ONLY ONE stock. <br>"
+     . "To aid in this process, here are the stocks that match your initial input: "
+     . join(', ', $links);
       form_set_error('subject_id', $message);
-    } elseif (sizeof($subject_results) < 1) {
-      form_set_error('subject_id', "There are no stocks matching your input. Please check your input for typos and/or lookup the stock ".l('here', 'stocks'));
-    } elseif (sizeof($subject_results) == 1) {
+    }
+    elseif (sizeof($subject_results) < 1) {
+      form_set_error('subject_id', "There are no stocks matching your input. Please check your input for typos and/or lookup the stock " . l('here', 'stocks'));
+    }
+    elseif (sizeof($subject_results) == 1) {
       $form_state['values']['subject_id'] = $subject_results[0]->stock->stock_id;
     }
 
@@ -124,26 +127,30 @@ function tripal_stock_add_ONE_relationship_form_validate($form, &$form_state) {
     $object_results = tripal_stock_get_stock_by_name_identifier( $form_state['values']['object_id'], $_SESSION['organism']);
     if (sizeof($object_results) > 1) {
       $links= array();
-      for ($i=0; $i<sizeof($object_results); $i++) { $links[] = l($i+1, "node/".$object_results[$i]->nid); } 
-      $message = "Too many stocks match '".$form_state['values']['object_id']."'! "
+      for ($i=0; $i<sizeof($object_results); $i++) {
+      $links[] = l($i+1, "node/" . $object_results[$i]->nid); }
+      $message = "Too many stocks match '" . $form_state['values']['object_id'] . "'! "
                  . "Please refine your input to match ONLY ONE stock. <br>"
                  . "To aid in this process, here are the stocks that match your initial input: "
-                 .join(', ',$links);
+                 . join(', ', $links);
       form_set_error('object_id', $message);
-    } elseif (sizeof($object_results) < 1) {
-      form_set_error('object_id', "There are no stocks matching your input. Please check your input for typos and/or lookup the stock ".l('here', 'stocks'));                                                                         
-    } elseif (sizeof($object_results) == 1) {
+    }
+    elseif (sizeof($object_results) < 1) {
+      form_set_error('object_id', "There are no stocks matching your input. Please check your input for typos and/or lookup the stock " . l('here', 'stocks'));
+    }
+    elseif (sizeof($object_results) == 1) {
       $form_state['values']['object_id'] = $object_results[0]->stock->stock_id;
     }
 
     // check valid type selected
     if ($form_state['values']['type_id'] == 0) {
       form_set_error('type_id', 'Please select a type of relationship.');
-    } else {
-    	$previous_db = tripal_db_set_active('chado');
-    	$tmp_obj = db_fetch_object(db_query("SELECT count(*) as count FROM cvterm WHERE cvterm_id=%d",$form_state['values']['type_id']));
-    	tripal_db_set_active($previous_db);
-    	
+    }
+    else {
+      $previous_db = tripal_db_set_active('chado');
+      $tmp_obj = db_fetch_object(db_query("SELECT count(*) as count FROM {cvterm} WHERE cvterm_id=%d", $form_state['values']['type_id']));
+      tripal_db_set_active($previous_db);
+
       if ($tmp_obj->count != 1) {
         form_set_error('type_id', 'The type you selected is not valid. Please choose another one.');
       }
@@ -152,23 +159,23 @@ function tripal_stock_add_ONE_relationship_form_validate($form, &$form_state) {
     // check either subject or object is the current stock
     if ( $subject_results[0]->nid != $form_state['values']['rel_nid'] ) {
       if ( $object_results[0]->nid != $form_state['values']['rel_nid'] ) {
-        form_set_error('subject_id', 'Either Subject or Object must be the current stock ('.$form_state['values']['r_stock_uniquename'].').');
+        form_set_error('subject_id', 'Either Subject or Object must be the current stock (' . $form_state['values']['r_stock_uniquename'] . ').');
       }
     }
   } //end of require validation if adding relationship
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
 function tripal_stock_add_ONE_relationship_form_submit($form, &$form_state) {
-  
+
   if ($form_state['values']['subject_id'] > 0) {
     $previous_db = tripal_db_set_active('chado');
     db_query(
-      "INSERT INTO stock_relationship (subject_id, type_id, object_id, value) VALUES (%d, %d, %d, '%s')",
+      "INSERT INTO {stock_relationship} (subject_id, type_id, object_id, value) VALUES (%d, %d, %d, '%s')",
       $form_state['values']['subject_id'],
       $form_state['values']['type_id'],
       $form_state['values']['object_id'],
@@ -182,13 +189,13 @@ function tripal_stock_add_ONE_relationship_form_submit($form, &$form_state) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
 function tripal_stock_edit_ALL_relationships_page($node) {
   $output = '';
-	
+
   $output .= drupal_get_form('tripal_stock_edit_ALL_relationships_form', $node);
   $output .= '<br>';
   $output .= drupal_get_form('tripal_stock_add_ONE_relationship_form', $node);
@@ -197,25 +204,26 @@ function tripal_stock_edit_ALL_relationships_page($node) {
 
   return $output;
 }
-                                                      
-/**                                                   
- * Implements Hook_form()                             
+
+/**
+ * Implements Hook_form()
  *
  * @ingroup tripal_stock
- */                                                   
+ */
 function tripal_stock_edit_ALL_relationships_form($form_state, $node) {
   $form = array();
-  
+
   // All Stock Relationships
-  $node = tripal_core_expand_chado_vars($node, 'table', 'stock_relationship');    
-   
+  $node = tripal_core_expand_chado_vars($node, 'table', 'stock_relationship');
+
   // compile all relationships into one variable
   $relationships = array();
   if (is_array($node->stock->stock_relationship->subject_id)) {
     foreach ($node->stock->stock_relationship->subject_id as $r) {
       $relationships[$r->stock_relationship_id] = $r;
     }
-  } elseif (is_object($node->stock->stock_relationship->subject_id)) { 
+  }
+  elseif (is_object($node->stock->stock_relationship->subject_id)) {
     $relationships[$node->stock->stock_relationship->subject_id->stock_relationship_id] = $node->stock->stock_relationship->subject_id;
   }
 
@@ -223,15 +231,16 @@ function tripal_stock_edit_ALL_relationships_form($form_state, $node) {
     foreach ($node->stock->stock_relationship->object_id as $r) {
       $relationships[$r->stock_relationship_id] = $r;
     }
-  } elseif (is_object($node->stock->stock_relationship->object_id)) { 
+  }
+  elseif (is_object($node->stock->stock_relationship->object_id)) {
     $relationships[$node->stock->stock_relationship->object_id->stock_relationship_id] = $node->stock->stock_relationship->object_id;
   }
-    
+
   $form['nid'] = array(
     '#type' => 'hidden',
     '#value' => $node->nid
   );
-  
+
   $form['r_stock_uniquename'] = array(
     '#type' => 'hidden',
     '#value' => $node->stock->uniquename
@@ -244,7 +253,7 @@ function tripal_stock_edit_ALL_relationships_form($form_state, $node) {
     $i++;
     $form["num-$i"] = array(
       '#type' => 'item',
-      '#value' => $i.'.'
+      '#value' => $i . '.'
     );
 
     $form["id-$i"] = array(
@@ -253,36 +262,38 @@ function tripal_stock_edit_ALL_relationships_form($form_state, $node) {
     );
 
     //Enter relationship specific fields
-    if ( $node->stock->stock_id != $r->subject_id->stock_id ) { 
+    if ( $node->stock->stock_id != $r->subject_id->stock_id ) {
       $default = $r->subject_id->uniquename;
-      $description = l($r->subject_id->name, 'node/'.$r->subject_id->nid); 
-    } else { $default = $node->stock->uniquename; $description = 'Current Stock'; }
+      $description = l($r->subject_id->name, 'node/' . $r->subject_id->nid);
+    }
+    else { $default = $node->stock->uniquename; $description = 'Current Stock'; }
     $form["subject_id-$i"] = array(
-      '#type' => 'textfield',      
-      //'#title' => t('Subject'), 
+      '#type' => 'textfield',
+      //'#title' => t('Subject'),
       '#required'   => TRUE,
       '#size' => 30,
       '#default_value' => $default,
       '#description' => $description,
-    ); 
+    );
 
     $type_options = tripal_cv_get_cvterm_options( variable_get('chado_stock_relationship_cv', 'null') );
-    ksort($type_options);          
-    $form["type_id-$i"] = array(  
-      '#type' => 'select',    
-      //'#title' => t('Type of Relationship'), 
+    ksort($type_options);
+    $form["type_id-$i"] = array(
+      '#type' => 'select',
+      //'#title' => t('Type of Relationship'),
       '#options' => $type_options,
       '#required' => TRUE,
       '#default_value' => $r->type_id->cvterm_id
     );
 
-    if ( $node->stock->stock_id != $r->object_id->stock_id ) { 
+    if ( $node->stock->stock_id != $r->object_id->stock_id ) {
       $default = $r->object_id->uniquename;
-      $description = l($r->object_id->name, 'node/'.$r->object_id->nid);
-    } else { $default = $node->stock->uniquename; $description = 'Current Stock'; }
+      $description = l($r->object_id->name, 'node/' . $r->object_id->nid);
+    }
+    else { $default = $node->stock->uniquename; $description = 'Current Stock'; }
     $form["object_id-$i"] = array(
-      '#type' => 'textfield',          
-      //'#title' => t('Object'),      
+      '#type' => 'textfield',
+      //'#title' => t('Object'),
       '#required'   => TRUE,
       '#size' => 30,
       '#default_value' => $default,
@@ -310,7 +321,7 @@ function tripal_stock_edit_ALL_relationships_form($form_state, $node) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
@@ -320,48 +331,55 @@ function tripal_stock_edit_ALL_relationships_form_validate($form, &$form_state)
   if ($form_state['clicked_button']['#value'] == t('Update Relationships') ) {
 
     for ($i=1; $i<=$form_state['values']['num_relationships']; $i++) {
-      
+
       // check valid stock selected for subject
       $subject_results = tripal_stock_get_stock_by_name_identifier( $form_state['values']["subject_id-$i"], $_SESSION['organism']);
       if (sizeof($subject_results) > 1) {
         $links= array();
-        for ($j=0; $j<sizeof($subject_results); $j++) { $links[] = l($j+1, "node/".$subject_results[$j]->nid); }
-        $message = "Too many stocks match '".$form_state['values']["subject_id-$i"]."'! "
-                 . "Please refine your input to match ONLY ONE stock. <br>" 
+        for ($j=0; $j<sizeof($subject_results); $j++) {
+        $links[] = l($j+1, "node/" . $subject_results[$j]->nid); }
+        $message = "Too many stocks match '" . $form_state['values']["subject_id-$i"] . "'! "
+                 . "Please refine your input to match ONLY ONE stock. <br>"
                  . "To aid in this process, here are the stocks that match your initial input: "
-                 .join(', ',$links);
+                 . join(', ', $links);
         form_set_error("subject_id-$i", $message);
-      } elseif (sizeof($subject_results) < 1) { 
-        form_set_error("subject_id-$i", "There are no stocks matching your input. Please check your input for typos and/or lookup the stock ".l('here', 'stocks'));
-      } elseif (sizeof($subject_results) == 1) {
+      }
+      elseif (sizeof($subject_results) < 1) {
+        form_set_error("subject_id-$i", "There are no stocks matching your input. Please check your input for typos and/or lookup the stock " . l('here', 'stocks'));
+      }
+      elseif (sizeof($subject_results) == 1) {
         $form_state['values']["subject_id-$i"] = $subject_results[0]->stock->stock_id;
-      } 
+      }
 
       // check valid stock selected for object
       $object_results = tripal_stock_get_stock_by_name_identifier( $form_state['values']["object_id-$i"], $_SESSION['organism']);
       if (sizeof($object_results) > 1) {
         $links= array();
-        for ($j=0; $j<sizeof($object_results); $j++) { $links[] = l($j+1, "node/".$object_results[$j]->nid); }
-        $message = "Too many stocks match '".$form_state['values']["object_id-$i"]."'! "
-                 . "Please refine your input to match ONLY ONE stock. <br>" 
+        for ($j=0; $j<sizeof($object_results); $j++) {
+        $links[] = l($j+1, "node/" . $object_results[$j]->nid); }
+        $message = "Too many stocks match '" . $form_state['values']["object_id-$i"] . "'! "
+                 . "Please refine your input to match ONLY ONE stock. <br>"
                  . "To aid in this process, here are the stocks that match your initial input: "
-                 .join(', ',$links);
+                 . join(', ', $links);
         form_set_error("object_id-$i", $message);
-      } elseif (sizeof($object_results) < 1) {
-        form_set_error("object_id-$i", "There are no stocks matching your input. Please check your input for typos and/or lookup the stock ".l('here', 'stocks'));
-      } elseif (sizeof($object_results) == 1) {
+      }
+      elseif (sizeof($object_results) < 1) {
+        form_set_error("object_id-$i", "There are no stocks matching your input. Please check your input for typos and/or lookup the stock " . l('here', 'stocks'));
+      }
+      elseif (sizeof($object_results) == 1) {
         $form_state['values']["object_id-$i"] = $object_results[0]->stock->stock_id;
-      } 
+      }
 
       // check valid type selected
       if ($form_state['values']["type_id-$i"] == 0) {
         form_set_error('type_id', 'Please select a type of relationship.');
-      } else {
-    		$previous_db = tripal_db_set_active('chado');
-    		$tmp_obj = db_fetch_object(db_query("SELECT count(*) as count FROM cvterm WHERE cvterm_id=%d",$form_state['values']["type_id-$i"]));
-    		tripal_db_set_active($previous_db);
-    	
-      	if ($tmp_obj->count != 1) {
+      }
+      else {
+        $previous_db = tripal_db_set_active('chado');
+        $tmp_obj = db_fetch_object(db_query("SELECT count(*) as count FROM {cvterm} WHERE cvterm_id=%d", $form_state['values']["type_id-$i"]));
+        tripal_db_set_active($previous_db);
+
+        if ($tmp_obj->count != 1) {
           form_set_error("type_id-$i", 'The type you selected is not valid. Please choose another one.');
         }
       }
@@ -369,7 +387,7 @@ function tripal_stock_edit_ALL_relationships_form_validate($form, &$form_state)
       // check either subject or object is the current stock
       if ( $subject_results[0]->nid != $form_state['values']['nid'] ) {
         if ( $object_results[0]->nid != $form_state['values']['nid'] ) {
-          form_set_error("subject_id-$i", 'Either Subject or Object must be the current stock ('.$form_state['values']['r_stock_uniquename'].').');
+          form_set_error("subject_id-$i", 'Either Subject or Object must be the current stock (' . $form_state['values']['r_stock_uniquename'] . ').');
         }
       }
 
@@ -379,7 +397,7 @@ function tripal_stock_edit_ALL_relationships_form_validate($form, &$form_state)
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
@@ -391,41 +409,44 @@ function tripal_stock_edit_ALL_relationships_form_submit($form, &$form_state) {
 
        //process stock textfields
        tripal_stock_update_relationship(
-				$form_state['values']["id-$i"], 
-				$form_state['values']["subject_id-$i"],
-				$form_state['values']["type_id-$i"], 
-				$form_state['values']["object_id-$i"]
-			);
+        $form_state['values']["id-$i"],
+        $form_state['values']["subject_id-$i"],
+        $form_state['values']["type_id-$i"],
+        $form_state['values']["object_id-$i"]
+      );
      }
      drupal_set_message("Updated all Relationships");
-     drupal_goto('node/'.$form_state['values']['nid']);
+     drupal_goto('node/' . $form_state['values']['nid']);
 
-  } elseif ( preg_match('/Delete #(\d+)/', $form_state['clicked_button']['#value'], $matches) ) {
+  }
+  elseif ( preg_match('/Delete #(\d+)/', $form_state['clicked_button']['#value'], $matches) ) {
 
      $i = $matches[1];
      tripal_stock_delete_relationship($form_state['values']["id-$i"]);
      drupal_set_message("Deleted Relationship");
 
-  } elseif ($form_state['clicked_button']['#value'] == t('Back to Stock') ) {
-    drupal_goto('node/'.$form_state['values']['nid']);
-  } else {
-    drupal_set_message("Unrecognized Button Pressed",'error');
+  }
+  elseif ($form_state['clicked_button']['#value'] == t('Back to Stock') ) {
+    drupal_goto('node/' . $form_state['values']['nid']);
+  }
+  else {
+    drupal_set_message("Unrecognized Button Pressed", 'error');
   }
 
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
-function tripal_stock_update_relationship ($stock_relationship_id, $subject_id, $cvterm_id, $object_id) {
+function tripal_stock_update_relationship($stock_relationship_id, $subject_id, $cvterm_id, $object_id) {
 
   $previous_db = tripal_db_set_active('chado');
   db_query(
-    "UPDATE stock_relationship SET subject_id=%d, type_id=%d, object_id=%d WHERE stock_relationship_id=%d",
+    "UPDATE {stock_relationship} SET subject_id=%d, type_id=%d, object_id=%d WHERE stock_relationship_id=%d",
     $subject_id,
-    $cvterm_id, 
+    $cvterm_id,
     $object_id,
     $stock_relationship_id
   );
@@ -434,15 +455,15 @@ function tripal_stock_update_relationship ($stock_relationship_id, $subject_id,
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
-function tripal_stock_delete_relationship ($stock_relationship_id) {
+function tripal_stock_delete_relationship($stock_relationship_id) {
 
   $previous_db = tripal_db_set_active('chado');
   db_query(
-    "DELETE FROM stock_relationship WHERE stock_relationship_id=%d",
+    "DELETE FROM {stock_relationship} WHERE stock_relationship_id=%d",
     $stock_relationship_id
   );
   tripal_db_set_active($previous_db);
@@ -450,27 +471,27 @@ function tripal_stock_delete_relationship ($stock_relationship_id) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
-function theme_tripal_stock_edit_ALL_relationships_form ($form) {
+function theme_tripal_stock_edit_ALL_relationships_form($form) {
   $output = '';
-  
+
   $output .= '<br><fieldset>';
   $output .= '<legend>Edit Already Existing Relationships<span class="form-optional" title="This field is optional">(optional)</span></legend>';
   $output .= '<p>Each relationship for this stock is listed below, one per line. The textboxes indicating '
-  	    .'the subject and object of the relationship can contain the uniquename, name, database '
-	    .'reference or synonym of a stock of the same organism.</p>';
+        . 'the subject and object of the relationship can contain the uniquename, name, database '
+      . 'reference or synonym of a stock of the same organism.</p>';
   $output .= '<table>';
   $output .= '<tr><th>#</th><th>Subject</th><th>Type</th><th>Object</th><th></th></tr>';
 
   for ($i=1; $i<=$form['num_relationships']['#value']; $i++) {
-    $output .= '<tr><td>'.drupal_render($form["num-$i"]).'</td><td>'
-    	       .drupal_render($form["subject_id-$i"]).'</td><td>'
-	       .drupal_render($form["type_id-$i"]).'</td><td>'
-	       .drupal_render($form["object_id-$i"]).'</td><td>'
-	       .drupal_render($form["submit-$i"]).'</td></tr>';
+    $output .= '<tr><td>' . drupal_render($form["num-$i"]) . '</td><td>'
+             . drupal_render($form["subject_id-$i"]) . '</td><td>'
+         . drupal_render($form["type_id-$i"]) . '</td><td>'
+         . drupal_render($form["object_id-$i"]) . '</td><td>'
+         . drupal_render($form["submit-$i"]) . '</td></tr>';
   }
 
   $output .= '</table><br>';
@@ -494,21 +515,22 @@ function tripal_stock_list_relationships_for_node($stock_name, $subject_relation
 
     if (!empty($subject_relationships) ) {
       foreach ($subject_relationships as $s) {
-        $output .= '<tr><td>'.$s->subject_name.'</td><td>'.$s->relationship_type.'</td><td>'.$stock_name.'</td></tr>';
+        $output .= '<tr><td>' . $s->subject_name . '</td><td>' . $s->relationship_type . '</td><td>' . $stock_name . '</td></tr>';
       }
     }
 
     if (!empty($object_relationships) ) {
       foreach ($object_relationships as $o) {
-        $output .= '<tr><td>'.$stock_name.'</td><td>'.$o->relationship_type.'</td><td>'.$o->object_name.'</td></tr>';
+        $output .= '<tr><td>' . $stock_name . '</td><td>' . $o->relationship_type . '</td><td>' . $o->object_name . '</td></tr>';
       } // end of foreach property
     }
 
     $output .= '</table>';
-  } else {
-    $output = 'No Relationships Involving the Current Stock'; 
+  }
+  else {
+    $output = 'No Relationships Involving the Current Stock';
   }
 
   return $output;
 
-}
+}

+ 41 - 32
tripal_stock/tripal_stock-secondary_tables.inc

@@ -1,8 +1,7 @@
 <?php
-// $Id$
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
@@ -14,48 +13,52 @@ function tripal_stock_back_to_stock_button($form_state, $nid) {
     '#value' => $nid
   );
 
-  $form["submit-back"] = array( 
+  $form["submit-back"] = array(
     '#type' => 'submit',
-    '#value' => t('Back to Stock') 
+    '#value' => t('Back to Stock')
   );
 
   return $form;
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
 function tripal_stock_back_to_stock_button_submit($form, $form_state) {
-  drupal_goto('node/'.$form_state['values']['nid']);
+  drupal_goto('node/' . $form_state['values']['nid']);
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
 function tripal_stock_add_chado_properties_progress($current) {
 
-    $value = '<div class="form_progress"><div class="form_progress-text">'; 
+    $value = '<div class="form_progress"><div class="form_progress-text">';
 
-    if ($current == 'main') { $value .= '<span id="form-step-current">Create Basic Stock</span>'; } 
+    if ($current == 'main') {
+    $value .= '<span id="form-step-current">Create Basic Stock</span>'; }
     else { $value .= '<span id="form-step">Create Basic Stock</span>'; }
 
     $value .= '<span id="form-segway">  >>  </span>';
 
-    if ($current == 'properties') { $value .= '<span id="form-step-current">Add Synonyms & Properties</span>'; }
+    if ($current == 'properties') {
+    $value .= '<span id="form-step-current">Add Synonyms & Properties</span>'; }
     else { $value .= '<span id="form-step">Add Synonyms & Properties</span>'; }
 
-    $value .= '<span id="form-segway">  >>  </span>';                       
+    $value .= '<span id="form-segway">  >>  </span>';
 
-    if ($current == 'db_references') { $value .= '<span id="form-step-current">Add Database References</span>'; }
+    if ($current == 'db_references') {
+    $value .= '<span id="form-step-current">Add Database References</span>'; }
     else { $value .= '<span id="form-step">Add Database References</span>'; }
 
-    $value .= '<span id="form-segway">  >>  </span>';         
+    $value .= '<span id="form-segway">  >>  </span>';
 
-    if ($current == 'relationships') { $value .= '<span id="form-step-current">Add Relationships</span>'; }
+    if ($current == 'relationships') {
+    $value .= '<span id="form-step-current">Add Relationships</span>'; }
     else { $value .= '<span id="form-step">Add Relationships</span>'; }
 
     $value .= '</div></div>';
@@ -65,7 +68,7 @@ function tripal_stock_add_chado_properties_progress($current) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
@@ -85,7 +88,8 @@ function tripal_stock_add_chado_properties_navigate($form_state, $step, $nid) {
     'relationships' => 'node/%node/relationships'
   );
   $steps_value = array();
-  foreach ($steps as $k => $v) { $steps_value[] = $k.';'.$v; }
+  foreach ($steps as $k => $v) {
+  $steps_value[] = $k . ';' . $v; }
   $form['steps'] = array(
     '#type' => 'hidden',
     '#value' => implode('::', $steps_value)
@@ -114,7 +118,7 @@ function tripal_stock_add_chado_properties_navigate($form_state, $step, $nid) {
   }
 
   if ($step != $form['last_step']['#value']) {
-    $form['submit-next'] = array( 
+    $form['submit-next'] = array(
       '#type' => 'submit',
       '#value' => t('Next Step')
     );
@@ -122,7 +126,7 @@ function tripal_stock_add_chado_properties_navigate($form_state, $step, $nid) {
 
   if ($step == $form['last_step']['#value']) {
     $form['submit-finish'] = array(
-      '#type' => 'submit', 
+      '#type' => 'submit',
       '#value' => t('Finish')
     );
   }
@@ -131,13 +135,13 @@ function tripal_stock_add_chado_properties_navigate($form_state, $step, $nid) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
 function tripal_stock_add_chado_properties_navigate_submit($form, $form_state) {
 
-  $raw_steps = preg_split('/::/', $form_state['values']['steps']); 
+  $raw_steps = preg_split('/::/', $form_state['values']['steps']);
 
   $steps = array();
   $current_index = 'EMPTY';
@@ -146,7 +150,7 @@ function tripal_stock_add_chado_properties_navigate_submit($form, $form_state) {
   foreach ($raw_steps as $raw_step) {
     $step = preg_split('/;/', $raw_step);
     $steps[$i] = $step;
-    
+
     if ($step[0] == $form_state['values']['current_step']) {
       $current_index = $i;
     }
@@ -154,16 +158,19 @@ function tripal_stock_add_chado_properties_navigate_submit($form, $form_state) {
     $i++;
   }
   $num_steps = $i;
-  
-  if (strcmp($current_index,'EMPTY') == 0) {
+
+  if (strcmp($current_index, 'EMPTY') == 0) {
     // No Matching Step
-    drupal_set_message('Could not determine next step -'.$form_state['values']['current_step'].', please contact the administrator', 'error');
-  } elseif ($current_index == 0) {
+    drupal_set_message('Could not determine next step -' . $form_state['values']['current_step'] . ', please contact the administrator', 'error');
+  }
+  elseif ($current_index == 0) {
     $next_goto = $steps[$current_index+1][1];
-  } elseif ($current_index == ($num_steps-1)) {
+  }
+  elseif ($current_index == ($num_steps-1)) {
     $prev_goto = $steps[$current_index-1][1];
     $next_goto = 'node/%node';
-  } else {
+  }
+  else {
     $prev_goto = $steps[$current_index-1][1];
     $next_goto = $steps[$current_index+1][1];
   }
@@ -172,10 +179,12 @@ function tripal_stock_add_chado_properties_navigate_submit($form, $form_state) {
     //replace %node
     $prev_goto = preg_replace('/%node/', $form_state['values']['nid'], $prev_goto);
     $_REQUEST['destination'] = $prev_goto;
-  } elseif ($form_state['clicked_button']['#value'] == t('Next Step') ) {
+  }
+  elseif ($form_state['clicked_button']['#value'] == t('Next Step') ) {
     $next_goto = preg_replace('/%node/', $form_state['values']['nid'], $next_goto);
     $_REQUEST['destination'] = $next_goto;
-  } elseif ($form_state['clicked_button']['#value'] == t('Finish') ) {
+  }
+  elseif ($form_state['clicked_button']['#value'] == t('Finish') ) {
     $next_goto = preg_replace('/%node/', $form_state['values']['nid'], $next_goto);
     $_REQUEST['destination'] = $next_goto;
   }
@@ -183,7 +192,7 @@ function tripal_stock_add_chado_properties_navigate_submit($form, $form_state) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
@@ -204,7 +213,7 @@ function tripal_stock_is_obsolete_form($node, $stock_id) {
 }
 
 /**
- * 
+ *
  *
  * @ingroup tripal_stock
  */
@@ -212,7 +221,7 @@ function tripal_stock_is_obsolete_form_submit($form, &$form_state) {
 
   $previous_db = tripal_db_set_active('chado');
   db_query(
-    "UPDATE stock SET is_obsolete='t' WHERE stock_id=%d",
+    "UPDATE {stock} SET is_obsolete='t' WHERE stock_id=%d",
     $form_state['values']['make_obsolete_stock_id']
   );
   tripal_db_set_active($previous_db);

+ 99 - 91
tripal_stock/tripal_stock.api.inc

@@ -5,7 +5,7 @@
  * @ingroup tripal_api
  * @ingroup tripal_stock
  */
- 
+
 /**
  * Purpose: Return a given stock node using the nid
  *
@@ -17,53 +17,54 @@
  *
  * @ingroup tripal_stock_api
  */
-function tripal_stock_get_stock_by_nid ($nid) {
-	
-	return node_load($nid);
-	
+function tripal_stock_get_stock_by_nid($nid) {
+
+  return node_load($nid);
+
 }
 
 /**
  * Purpose: Return a given stock object using the stock id
  *
- * @return 
+ * @return
  *   Stock object created by node load
  *
  * @ingroup tripal_stock_api
  */
-function tripal_stock_get_stock_by_stock_id ($stock_id) {
+function tripal_stock_get_stock_by_stock_id($stock_id) {
 
   $sql = "SELECT nid FROM {chado_stock} WHERE stock_id=%d";
   $r = db_fetch_object(db_query($sql, $stock_id));
   if (!empty($r->nid)) {
     return node_load($r->nid);
-  } else {
+  }
+  else {
     watchdog('tripal_stock', 'tripal_stock_get_stock_by_stock_id(!stock_id): no stock with that stock_id is sync\'d with drupal', array('!stock_id' => $stock_id), WATCHDOG_WARNING);
-	}
+  }
+
+  return 0;
 
-	return 0;
-	
 }
 
 /**
  * Purpose: Returns all stocks currently sync'd with drupal
  *
- * @return 
+ * @return
  *   An array of node objects keyed by stock_id
  *
  * @ingroup tripal_stock_api
  */
 function tripal_stock_get_all_stocks() {
-	$sql = "SELECT stock_id, nid from {chado_stock}";
-	$resource = db_query($sql);
-	$stocks = array();
-	while ($r = db_fetch_object($resource)) {
-		$node = node_load($r->nid);
-		if ($node) {
+  $sql = "SELECT stock_id, nid from {chado_stock}";
+  $resource = db_query($sql);
+  $stocks = array();
+  while ($r = db_fetch_object($resource)) {
+    $node = node_load($r->nid);
+    if ($node) {
       $stocks[$r->stock_id] = $node;
     }
-	}
-	return $stocks;
+  }
+  return $stocks;
 }
 
 /**
@@ -72,7 +73,7 @@ function tripal_stock_get_all_stocks() {
  * @param $values
  *   An associative array containing the values for filtering the results.
  *
- * @return 
+ * @return
  *   An array of matching stock objects (produced using node_load)
  *   matching the given criteria
  *
@@ -96,20 +97,20 @@ function tripal_stock_get_all_stocks() {
  * @endcode
  * The above code selects a record from the chado stock table using three fields with values which
  * identify a stock or multiple stocks. Then the node for each stock identified is returned, if it
- * exists. The $values array is nested such that the organism is identified by way of the 
- * organism_id foreign key constraint by specifying the genus and species.  The cvterm is also 
+ * exists. The $values array is nested such that the organism is identified by way of the
+ * organism_id foreign key constraint by specifying the genus and species.  The cvterm is also
  * specified using its foreign key and the cv_id for the cvterm is nested as well.
  *
  * @ingroup tripal_stock_api
  */
 function tripal_stock_get_stocks($values) {
 
-  $stock_ids = tripal_core_chado_select('stock',array('stock_id'),$values);
+  $stock_ids = tripal_core_chado_select('stock', array('stock_id'), $values);
 
   // Change from stock_ids to nodes-----------------------------------
   $stock_ids = array_filter($stock_ids);
   $stock_ids = array_unique($stock_ids);
-  
+
   $stocks = array();
   foreach ($stock_ids as $stock_id) {
     $node = tripal_stock_get_stock_by_stock_id($stock_id->stock_id);
@@ -117,7 +118,7 @@ function tripal_stock_get_stocks($values) {
       $stocks[] = $node;
     }
   }
-  
+
   return $stocks;
 }
 
@@ -131,7 +132,7 @@ function tripal_stock_get_stocks($values) {
  * @param $stock_values
  *   An array of column_name => value where column_name is any column in the stock table
  *   and value is the value you want that column to be. This is used as a tripal_core_chado_select
- *   values array so nesting is allowed. 
+ *   values array so nesting is allowed.
  *
  * @return
  *   An array of stock node objects
@@ -167,14 +168,14 @@ function tripal_stock_get_stocks_by_stockprop($stockprop_values, $stock_values)
   if (!empty($stock_values)) {
     $stockprop_values['stock_id'] = $stock_values;
   }
-  
+
   //get stock_ids from stockprop table
-  $stock_ids = tripal_core_chado_select('stockprop',array('stock_id'),$stockprop_values);
+  $stock_ids = tripal_core_chado_select('stockprop', array('stock_id'), $stockprop_values);
 
   // Change from stock_ids to nodes-----------------------------------
   $stock_ids = array_filter($stock_ids);
   $stock_ids = array_unique($stock_ids);
-  
+
   $stocks = array();
   foreach ($stock_ids as $stock_id) {
     $node = tripal_stock_get_stock_by_stock_id($stock_id->stock_id);
@@ -182,13 +183,13 @@ function tripal_stock_get_stocks_by_stockprop($stockprop_values, $stock_values)
       $stocks[] = $node;
     }
   }
-  
+
   return $stocks;
 }
 
 /**
  * Purpose: Return all stocks with a given name identifier
- *  which might match stock.name, stock.uniquename, dbxref.accession, 
+ *  which might match stock.name, stock.uniquename, dbxref.accession,
  *  stockprop.value where stockprop.type='synonym'
  *
  * @param $name
@@ -203,13 +204,13 @@ function tripal_stock_get_stocks_by_stockprop($stockprop_values, $stock_values)
  */
 function tripal_stock_get_stock_by_name_identifier($name, $organism_id) {
   $stock_ids = array();
-  
+
   $options = array(
     'case_insensitive_columns' => array('name', 'uniquename', 'accession', 'value')
   );
-  
+
   // where name_identifier = stock.name-------------------------------
-  $current_stocks = tripal_core_chado_select('stock',array('stock_id'),
+  $current_stocks = tripal_core_chado_select('stock', array('stock_id'),
     array(
       'name' => $name,
       'organism_id' => $organism_id,
@@ -219,11 +220,12 @@ function tripal_stock_get_stock_by_name_identifier($name, $organism_id) {
     )
   );
   if (!empty($current_stocks)) {
-    foreach ($current_stocks as $c) { $stock_ids[] = $c->stock_id; }
+    foreach ($current_stocks as $c) {
+    $stock_ids[] = $c->stock_id; }
   }
 
   // where name_identifier = stock.uniquename-------------------------------
-  $current_stocks = tripal_core_chado_select('stock',array('stock_id'),
+  $current_stocks = tripal_core_chado_select('stock', array('stock_id'),
     array(
       'uniquename' => $name,
       'organism_id' => $organism_id,
@@ -233,12 +235,13 @@ function tripal_stock_get_stock_by_name_identifier($name, $organism_id) {
     )
   );
   if (!empty($current_stocks)) {
-    foreach ($current_stocks as $c) { $stock_ids[] = $c->stock_id; }
+    foreach ($current_stocks as $c) {
+    $stock_ids[] = $c->stock_id; }
   }
-  
+
   // where name_identifier = dbxref.accession-------------------------------
   // linked to stock through stock.dbxref
-  $current_stocks = tripal_core_chado_select('stock',array('stock_id'),
+  $current_stocks = tripal_core_chado_select('stock', array('stock_id'),
     array(
       'dbxref_id' => array(
         'accession' => $name,
@@ -250,11 +253,12 @@ function tripal_stock_get_stock_by_name_identifier($name, $organism_id) {
     )
   );
   if (!empty($current_stocks)) {
-    foreach ($current_stocks as $c) { $stock_ids[] = $c->stock_id; }  
+    foreach ($current_stocks as $c) {
+    $stock_ids[] = $c->stock_id; }
   }
-  
+
   // linked to stock through stock_dbxref?
-  $current_stocks = tripal_core_chado_select('stock_dbxref',array('stock_id'),
+  $current_stocks = tripal_core_chado_select('stock_dbxref', array('stock_id'),
     array(
       'dbxref_id' => array(
         'accession' => $name,
@@ -268,12 +272,14 @@ function tripal_stock_get_stock_by_name_identifier($name, $organism_id) {
     )
   );
   if (!empty($current_stocks)) {
-    foreach ($current_stocks as $c) { $stock_ids[] = $c->stock_id; }  
+    foreach ($current_stocks as $c) {
+      $stock_ids[] = $c->stock_id;
+    }
   }
-  
+
   // where name_identifier = stockprop.value-------------------------------
-  // where type='synonym' 
-  $current_stocks = tripal_core_chado_select('stockprop',array('stock_id'),
+  // where type='synonym'
+  $current_stocks = tripal_core_chado_select('stockprop', array('stock_id'),
     array(
       'stock_id' => array(
         'organism_id' => $organism_id,
@@ -289,13 +295,15 @@ function tripal_stock_get_stock_by_name_identifier($name, $organism_id) {
     )
   );
   if (!empty($current_stocks)) {
-    foreach ($current_stocks as $c) { $stock_ids[] = $c->stock_id; }
+    foreach ($current_stocks as $c) {
+      $stock_ids[] = $c->stock_id;
+    }
   }
-  
+
   // Change from stock_ids to nodes-----------------------------------
   $stock_ids = array_filter($stock_ids);
   $stock_ids = array_unique($stock_ids);
-  
+
   $stocks = array();
   foreach ($stock_ids as $stock_id) {
     $node = tripal_stock_get_stock_by_stock_id($stock_id);
@@ -303,10 +311,10 @@ function tripal_stock_get_stock_by_name_identifier($name, $organism_id) {
       $stocks[] = $node;
     }
   }
-  
+
   return $stocks;
 }
- 
+
 /**
  * Implements hook_chado_stock_schema()
  *
@@ -329,21 +337,21 @@ function tripal_stock_chado_stock_schema() {
           'organism_id' => 'organism_id',
         ),
   );
-      
+
   $description['foreign keys']['dbxref'] = array(
         'table' => 'dbxref',
         'columns' => array(
           'dbxref_id' => 'dbxref_id',
         ),
   );
-      
+
   $description['foreign keys']['cvterm'] = array(
         'table' => 'cvterm',
         'columns' => array(
           'type_id' => 'cvterm_id',
         ),
   );
-     
+
   $referring_tables = array(
     'stock_cvterm',
     'stock_dbxref',
@@ -351,10 +359,10 @@ function tripal_stock_chado_stock_schema() {
     'stock_pub',
     'stock_relationship',
     'stockcollection_stock',
-    'stockprop'  
+    'stockprop'
   );
   $description['referring_tables'] = $referring_tables;
-  
+
   return $description;
 }
 
@@ -371,21 +379,21 @@ function tripal_stock_chado_stock_schema() {
  */
 function tripal_stock_chado_stockprop_schema() {
   $description = array();
-  
+
   $description['foreign keys']['cvterm'] = array(
         'table' => 'cvterm',
         'columns' => array(
           'type_id' => 'cvterm_id',
         ),
   );
-  
+
   $description['foreign keys']['stock'] = array(
         'table' => 'stock',
         'columns' => array(
           'stock_id' => 'stock_id',
         ),
   );
-  
+
   return $description;
 }
 
@@ -402,21 +410,21 @@ function tripal_stock_chado_stockprop_schema() {
  */
 function tripal_stock_chado_stockprop_pub_schema() {
   $description = array();
-  
+
   $description['foreign keys']['pub'] = array(
         'table' => 'pub',
         'columns' => array(
           'pub_id' => 'pub_id',
         ),
   );
-  
+
   $description['foreign keys']['stockprop'] = array(
         'table' => 'stockprop',
         'columns' => array(
           'stockprop_id' => 'stockprop_id',
         ),
   );
-  
+
   return $description;
 }
 
@@ -433,14 +441,14 @@ function tripal_stock_chado_stockprop_pub_schema() {
  */
 function tripal_stock_chado_stock_cvterm_schema() {
   $description = array();
-  
+
   $description['foreign keys']['cvterm'] = array(
         'table' => 'cvterm',
         'columns' => array(
           'cvterm_id' => 'cvterm_id',
         ),
   );
-  
+
   $description['foreign keys']['stock'] = array(
         'table' => 'stock',
         'columns' => array(
@@ -454,7 +462,7 @@ function tripal_stock_chado_stock_cvterm_schema() {
           'pub_id' => 'pub_id',
         ),
   );
-  
+
   return $description;
 }
 
@@ -471,21 +479,21 @@ function tripal_stock_chado_stock_cvterm_schema() {
  */
 function tripal_stock_chado_stock_dbxref_schema() {
   $description = array();
-  
+
   $description['foreign keys']['dbxref'] = array(
         'table' => 'dbxref',
         'columns' => array(
           'dbxref_id' => 'dbxref_id',
         ),
   );
-  
+
   $description['foreign keys']['stock'] = array(
         'table' => 'stock',
         'columns' => array(
           'stock_id' => 'stock_id',
         ),
   );
-  
+
   return $description;
 }
 
@@ -502,21 +510,21 @@ function tripal_stock_chado_stock_dbxref_schema() {
  */
 function tripal_stock_chado_stock_genotype_schema() {
   $description = array();
-  
+
   $description['foreign keys']['genotype'] = array(
         'table' => 'genotype',
         'columns' => array(
           'genotype_id' => 'genotype_id',
         ),
   );
-  
+
   $description['foreign keys']['stock'] = array(
         'table' => 'stock',
         'columns' => array(
           'stock_id' => 'stock_id',
         ),
   );
-  
+
   return $description;
 }
 
@@ -533,21 +541,21 @@ function tripal_stock_chado_stock_genotype_schema() {
  */
 function tripal_stock_chado_stock_pub_schema() {
   $description = array();
-  
+
   $description['foreign keys']['pub'] = array(
         'table' => 'pub',
         'columns' => array(
           'pub_id' => 'pub_id',
         ),
   );
-  
+
   $description['foreign keys']['stock'] = array(
         'table' => 'stock',
         'columns' => array(
           'stock_id' => 'stock_id',
         ),
   );
-  
+
   return $description;
 }
 
@@ -564,14 +572,14 @@ function tripal_stock_chado_stock_pub_schema() {
  */
 function tripal_stock_chado_stock_relationship_schema() {
   $description = array();
-  
+
   $description['foreign keys']['cvterm'] = array(
         'table' => 'cvterm',
         'columns' => array(
           'type_id' => 'cvterm_id',
         ),
   );
-  
+
   $description['foreign keys']['stock'] = array(
         'table' => 'stock',
         'columns' => array(
@@ -579,7 +587,7 @@ function tripal_stock_chado_stock_relationship_schema() {
           'object_id' => 'stock_id',
         ),
   );
-  
+
   return $description;
 }
 
@@ -596,21 +604,21 @@ function tripal_stock_chado_stock_relationship_schema() {
  */
 function tripal_stock_chado_stock_relationship_pub_schema() {
   $description = array();
-  
+
   $description['foreign keys']['pub'] = array(
         'table' => 'pub',
         'columns' => array(
           'pub_id' => 'pub_id',
         ),
   );
-  
+
   $description['foreign keys']['stock_relationship'] = array(
         'table' => 'stock_relationship',
         'columns' => array(
           'stock_relationship_id' => 'stock_relationship_id',
         ),
   );
-  
+
   return $description;
 }
 
@@ -627,21 +635,21 @@ function tripal_stock_chado_stock_relationship_pub_schema() {
  */
 function tripal_stock_chado_stockcollection_schema() {
   $description = array();
-  
+
   $description['foreign keys']['cvterm'] = array(
         'table' => 'cvterm',
         'columns' => array(
           'type_id' => 'cvterm_id',
         ),
   );
-  
+
   $description['foreign keys']['contact'] = array(
         'table' => 'contact',
         'columns' => array(
           'contact_id' => 'contact_id',
         ),
   );
-  
+
   return $description;
 }
 
@@ -658,21 +666,21 @@ function tripal_stock_chado_stockcollection_schema() {
  */
 function tripal_stock_chado_stockcollection_stock_schema() {
   $description = array();
-  
+
   $description['foreign keys']['stock'] = array(
         'table' => 'stock',
         'columns' => array(
           'stock_id' => 'stock_id',
         ),
   );
-  
+
   $description['foreign keys']['stockcollection'] = array(
         'table' => 'stockcollection',
         'columns' => array(
           'stockcollection_id' => 'stockcollection_id',
         ),
   );
-  
+
   return $description;
 }
 
@@ -689,20 +697,20 @@ function tripal_stock_chado_stockcollection_stock_schema() {
  */
 function tripal_stock_chado_stockcollectionprop_schema() {
   $description = array();
-  
+
   $description['foreign keys']['cvterm'] = array(
         'table' => 'cvterm',
         'columns' => array(
           'type_id' => 'cvterm_id',
         ),
   );
-  
+
   $description['foreign keys']['stockcollection'] = array(
         'table' => 'stockcollection',
         'columns' => array(
           'stockcollection_id' => 'stockcollection_id',
         ),
   );
-  
+
   return $description;
-}
+}

+ 37 - 37
tripal_stock/tripal_stock.install

@@ -1,5 +1,5 @@
 <?php
-// $Id$
+
 
 /**
  * Install the tripal stock module including it's content type
@@ -8,55 +8,55 @@
 
 /** Implementation of hook_install() */
 function tripal_stock_install() {
-	drupal_install_schema('tripal_stock');
+  drupal_install_schema('tripal_stock');
 }
 
 /** Implementation of hook_uninstall() */
 function tripal_stock_uninstall() {
-	drupal_uninstall_schema('tripal_stock');
+  drupal_uninstall_schema('tripal_stock');
 
-	// Get the list of nodes to remove
-	$sql_lib_id = "SELECT nid, vid ".
+  // Get the list of nodes to remove
+  $sql_lib_id = "SELECT nid, vid ".
                  "FROM {node} ".
                  "WHERE type='chado_stock'";
-	$result = db_query($sql_lib_id);
+  $result = db_query($sql_lib_id);
 
-	//delete all nodes
-	while ($node = db_fetch_object($result)) {
-	node_delete($node->nid);
-	}
+  //delete all nodes
+  while ($node = db_fetch_object($result)) {
+  node_delete($node->nid);
+  }
 
 }
 
 /** Implementation of hook_schema() */
 function tripal_stock_schema() {
-	$schema['chado_stock'] = array(
-		'fields' => array(
+  $schema['chado_stock'] = array(
+    'fields' => array(
       'vid' => array(
-				'type' => 'int',
-				'unsigned' => TRUE,
-				'not null' => TRUE,
- 	 	  ),
-  	  'nid' => array(
-   	   	'type' => 'int',
-   	   	'unsigned' => TRUE,
-   	   	'not null' => TRUE,
-  	  ),
-   	 	'stock_id' => array(
-   	   	'type' => 'int',
-   	   	'unsigned' => TRUE,
-   	   	'not null' => TRUE,
-    	),
-  	),
-  	'indexes' => array(
-    	'stock_id' => array('stock_id'),
-     	'nid' => array('nid'),
-  	),
-  	'unique' => array(
-    	'stock_id' => array('stock_id'),
-  	),
-  	'primary key' => array('vid'),
-	);
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        ),
+      'nid' => array(
+          'type' => 'int',
+          'unsigned' => TRUE,
+          'not null' => TRUE,
+      ),
+        'stock_id' => array(
+          'type' => 'int',
+          'unsigned' => TRUE,
+          'not null' => TRUE,
+      ),
+    ),
+    'indexes' => array(
+      'stock_id' => array('stock_id'),
+       'nid' => array('nid'),
+    ),
+    'unique' => array(
+      'stock_id' => array('stock_id'),
+    ),
+    'primary key' => array('vid'),
+  );
 
   return $schema;
-}
+}

+ 316 - 299
tripal_stock/tripal_stock.module

@@ -1,5 +1,4 @@
 <?php
-// $Id$
 
 /**
  * @file
@@ -11,13 +10,13 @@
  * @{
  * Provides functions for managing chado stocks including creating details pages for each stock
  *
- * The Tripal Stock Module provides functionality for adding, editing, deleting and accessing chado 
- * stocks. The stock module was designed to store information about stock collections in a 
- * laboratory. What is called a stock could also be called a strain or an accession. There is a lot 
- * in common between a Drosophila stock and a Saccharomyces strain and an Arabidopsis line. They all 
- * come from some taxon, have genotypes, physical locations in the lab, some conceivable 
- * relationship with a publication, some conceivable relationship with a sequence feature (such as a 
- * transgene), and could be described by some ontology term. For more information about the chado 
+ * The Tripal Stock Module provides functionality for adding, editing, deleting and accessing chado
+ * stocks. The stock module was designed to store information about stock collections in a
+ * laboratory. What is called a stock could also be called a strain or an accession. There is a lot
+ * in common between a Drosophila stock and a Saccharomyces strain and an Arabidopsis line. They all
+ * come from some taxon, have genotypes, physical locations in the lab, some conceivable
+ * relationship with a publication, some conceivable relationship with a sequence feature (such as a
+ * transgene), and could be described by some ontology term. For more information about the chado
  * Stock Module see the GMOD Wiki Page (http://gmod.org/wiki/Chado_Stock_Module)
  * @}
  * @ingroup tripal_modules
@@ -51,7 +50,7 @@ function tripal_stock_menu() {
     'access arguments' => array('administer site configuration'),
     'type' => MENU_NORMAL_ITEM
   );
-  
+
   $items['admin/tripal/tripal_stock/configuration'] = array(
     'title' => t('Configuration'),
     'description' => t('Settings for Chado Stocks'),
@@ -60,39 +59,39 @@ function tripal_stock_menu() {
     'access arguments' => array('administer site configuration'),
     'type' => MENU_NORMAL_ITEM
   );
-  
+
   //Displaying stocks----------------------------
   $items['stocks'] = array(
-  	'menu_name' => ('primary-links'),
+    'menu_name' => ('primary-links'),
     'title' => t('Stocks'),
     'page callback' => 'tripal_stock_show_stocks',
     'access arguments' => array('access chado_stock content'),
-    'type' => MENU_NORMAL_ITEM,  
+    'type' => MENU_NORMAL_ITEM,
   );
 
   // Adding Secondary Properties-----------------
-  $items['node/%cs_node/properties'] = array(       
-    'title' => t('Add Properties & Synonyms'),                         
+  $items['node/%cs_node/properties'] = array(
+    'title' => t('Add Properties & Synonyms'),
     'description' => t('Settings for Chado Stocks'),
-    'page callback' => 'tripal_stock_add_ALL_property_page',           
-    'page arguments' => array(1), 
+    'page callback' => 'tripal_stock_add_ALL_property_page',
+    'page arguments' => array(1),
     'access arguments' => array('create chado_stock content'),
     'type' => MENU_CALLBACK
-  ); 
+  );
 
-  $items['node/%cs_node/db_references'] = array(                        
-    'title' => t('Add Database References'),                   
-    'description' => t('Settings for Chado Stocks'),              
-    'page callback' => 'tripal_stock_add_ALL_dbreferences_page',                         
+  $items['node/%cs_node/db_references'] = array(
+    'title' => t('Add Database References'),
+    'description' => t('Settings for Chado Stocks'),
+    'page callback' => 'tripal_stock_add_ALL_dbreferences_page',
     'page arguments' => array(1),
     'access arguments' => array('create chado_stock content'),
     'type' => MENU_CALLBACK
-  ); 
+  );
 
-  $items['node/%cs_node/relationships'] = array(                      
-    'title' => t('Add Relationships'),                      
-    'description' => t('Settings for Chado Stocks'),               
-    'page callback' => 'tripal_stock_add_ALL_relationships_page',                          
+  $items['node/%cs_node/relationships'] = array(
+    'title' => t('Add Relationships'),
+    'description' => t('Settings for Chado Stocks'),
+    'page callback' => 'tripal_stock_add_ALL_relationships_page',
     'page arguments' => array(1),
     'access arguments' => array('create chado_stock content'),
     'type' => MENU_CALLBACK
@@ -111,7 +110,7 @@ function tripal_stock_menu() {
 
     $items['node/%cs_node/edit_relationships'] = array(
     'title' => t('Edit Relationships'),
-    'description' => t('Settings for Chado Stocks'), 
+    'description' => t('Settings for Chado Stocks'),
     'page callback' => 'tripal_stock_edit_ALL_relationships_page',
     'page arguments' => array(1),
     'access arguments' => array('edit chado_stock content'),
@@ -134,9 +133,9 @@ function tripal_stock_menu() {
 /**
  * Implements Menu wildcard_load hook
  *
- * Purpose: Allows the node ID of a chado stock to be dynamically 
+ * Purpose: Allows the node ID of a chado stock to be dynamically
  *   pulled from the path. The node is loaded from this node ID
- *   and supplied to the page as an arguement. This is an example 
+ *   and supplied to the page as an arguement. This is an example
  *   of dynamic argument replacement using wildcards in the path.
  *
  * @param $nid
@@ -194,7 +193,7 @@ function tripal_stock_perm() {
  */
 function chado_stock_access($op, $node, $account) {
    if ($op == 'create') {
-      if(!user_access('create chado_stock content', $account)){
+      if (!user_access('create chado_stock content', $account)) {
         return FALSE;
       }
    }
@@ -227,7 +226,7 @@ function chado_stock_access($op, $node, $account) {
  *   An array with fields important for views integration
  *
  * @ingroup tripal_stock
- */ 
+ */
 function tripal_stock_views_api() {
    return array(
       'api' => 2.0,
@@ -243,11 +242,11 @@ function tripal_stock_views_api() {
  * @ingroup tripal_stock
  */
 function tripal_stock_theme() {
-	return array(
-		'tripal_stock_stock_table' => array (
-			'arguments' => array('stocks'),
-		),
-		// Property edit forms--------------------------
+  return array(
+    'tripal_stock_stock_table' => array(
+      'arguments' => array('stocks'),
+    ),
+    // Property edit forms--------------------------
     'tripal_stock_edit_ALL_properties_form' => array(
       'arguments' => array('form'),
       'function' => 'theme_tripal_stock_edit_ALL_properties_form',
@@ -261,27 +260,27 @@ function tripal_stock_theme() {
       'function' => 'theme_tripal_stock_edit_ALL_relationships_form',
     ),
     // Block Templates------------------------------
-    'tripal_stock_base' => array (
-      'arguments' => array('node'=> null),
+    'tripal_stock_base' => array(
+      'arguments' => array('node' => NULL),
       'template' => 'tripal_stock_base',
     ),
-    'tripal_stock_properties' => array (
-      'arguments' => array('node'=> null),
+    'tripal_stock_properties' => array(
+      'arguments' => array('node' => NULL),
       'template' => 'tripal_stock_properties',
     ),
-    'tripal_stock_references' => array (
-      'arguments' => array('node'=> null),
+    'tripal_stock_references' => array(
+      'arguments' => array('node' => NULL),
       'template' => 'tripal_stock_references',
     ),
-    'tripal_stock_relationships' => array (
-      'arguments' => array('node'=> null),
+    'tripal_stock_relationships' => array(
+      'arguments' => array('node' => NULL),
       'template' => 'tripal_stock_relationships',
-    ),    
-    'tripal_stock_synonyms' => array (
-      'arguments' => array('node'=> null),
+    ),
+    'tripal_stock_synonyms' => array(
+      'arguments' => array('node' => NULL),
       'template' => 'tripal_stock_synonyms',
     ),
-	);
+  );
 }
 
 /**
@@ -296,17 +295,18 @@ function tripal_stock_theme() {
  *
  * @ingroup tripal_stock
  */
-function tripal_stock_show_stocks () {
-	$sql = "SELECT COUNT(stock_id) FROM {chado_stock}";
+function tripal_stock_show_stocks() {
+  $sql = "SELECT COUNT(stock_id) FROM {chado_stock}";
    $no_stocks = db_result(db_query($sql));
-   if($no_stocks != 0) {
+   if ($no_stocks != 0) {
       $stocks = tripal_stock_get_all_stocks();
-      if($no_stocks != count($stocks)) {
+      if ($no_stocks != count($stocks)) {
          drupal_set_message("Synchronization needed.");
       }
-      return theme('tripal_stock_stock_table',&$stocks);
-   } else {
-      return t("No Stocks exists. Please contact administrators to ".
+      return theme('tripal_stock_stock_table', &$stocks);
+   }
+   else {
+      return t("No Stocks exists. Please contact administrators to " .
                "synchronize stocks.");
    }
 }
@@ -322,11 +322,11 @@ function tripal_stock_show_stocks () {
  *
  * @ingroup tripal_stock
  */
-function theme_tripal_stock_stock_table (&$stocks) {
+function theme_tripal_stock_stock_table(&$stocks) {
 
-	// cycle through the stocks and build the stocks page
-	$output = "<div id=\"stocks\">";
-	$output .= '<table>';
+  // cycle through the stocks and build the stocks page
+  $output = "<div id=\"stocks\">";
+  $output .= '<table>';
   $output .= "<tr>";
   $output .= "<th>Name</th>";
   $output .= "<th>Type</th>";
@@ -334,16 +334,16 @@ function theme_tripal_stock_stock_table (&$stocks) {
   $output .= "<th>Description</th>";
   $output .= "</tr>";
 
-  foreach($stocks as $node){
-		$output .= "<tr>";
-		$output .= "<td>".l($node->stock->name, "node/".$node->nid)."</td>";
-		$output .= "<td>".$node->stock->type_id->name."</td>";
-		$output .= "<td nowrap>".$node->stock->organism_id->common_name."</td>";
-		$output .= "<td>".$node->stock->description."</td>";
-		$output .= "</tr>";
-	}
-	$output .= "</table>";
-	$output .= "</div>";
+  foreach ($stocks as $node) {
+    $output .= "<tr>";
+    $output .= "<td>" . l($node->stock->name, "node/" . $node->nid) . "</td>";
+    $output .= "<td>" . $node->stock->type_id->name . "</td>";
+    $output .= "<td nowrap>" . $node->stock->organism_id->common_name . "</td>";
+    $output .= "<td>" . $node->stock->description . "</td>";
+    $output .= "</tr>";
+  }
+  $output .= "</table>";
+  $output .= "</div>";
 
    return $output;
 }
@@ -386,9 +386,9 @@ function chado_stock_load($node) {
     "SELECT stock_id as stock_id FROM {chado_stock} WHERE vid=%d",
     $node->vid
   ));
-  
+
   // Get stock content and add to node
-  $stock = tripal_core_generate_chado_var('stock', array('stock_id'=>$map->stock_id));
+  $stock = tripal_core_generate_chado_var('stock', array('stock_id' => $map->stock_id));
   //
   // move expandable fields downwards
   $node->expandable_fields = $stock->expandable_fields;
@@ -398,7 +398,7 @@ function chado_stock_load($node) {
   $node->expandable_nodes = $stock->expandable_nodes;
   unset($stock->expandable_nodes);
   $node->stock = $stock;
-  
+
   return $node;
 }
 
@@ -407,12 +407,12 @@ function chado_stock_load($node) {
  * Implements hook_form(): Creates the main Add/Edit/Delete Form for chado stocks
  *
  * Parts to be added by this form
- *     name, 
- *     uniquename, 
- *     description, 
+ *     name,
+ *     uniquename,
+ *     description,
  *     type => select from cvterm with key cvterm_id,
  *     organism => select from available with key organism_id
- *     main_db_reference => accession, version, description, db_name(select from dropdown) 
+ *     main_db_reference => accession, version, description, db_name(select from dropdown)
  *
  * @param $node
  *   An empty node object on insert OR the current stock node object on update
@@ -448,13 +448,13 @@ function chado_stock_form($node, $form_state) {
   // Will then do default redirect (to new node) on submit
   $form['simulate_multipart'] = array(
     '#type' => 'textfield',
-    '#attributes'=>array('style'=>"display:none"),
+    '#attributes' => array('style' => "display:none"),
     '#default_value' => TRUE
   );
 
   if (!isset($node->stock->uniquename)) {
-    $form['progress'] = array( 
-      '#type' => 'item', 
+    $form['progress'] = array(
+      '#type' => 'item',
       '#value' => tripal_stock_add_chado_properties_progress('main')
     );
   }
@@ -468,14 +468,14 @@ function chado_stock_form($node, $form_state) {
     '#type' => 'textfield',
     '#title' => t('Name'),
     '#default_value' => $node->stock->name,
-    '#required'	     => TRUE
+    '#required'       => TRUE
   );
 
   $form['names']['uniquename'] = array(
     '#type' => 'textfield',
     '#title' => t('Unique Name'),
     '#default_value' => $node->stock->uniquename,
-    '#required'	     => TRUE
+    '#required'       => TRUE
   );
 
   $form['names']['stock_id'] = array(
@@ -485,29 +485,33 @@ function chado_stock_form($node, $form_state) {
 
   $form['details'] = array(
     '#type' => 'fieldset',
-    '#title' =>	t('Stock Details')
+    '#title' =>  t('Stock Details')
   );
 
-  $type_options = tripal_cv_get_cvterm_options( variable_get('chado_stock_types_cv', 'null') );
+  $type_options = tripal_cv_get_cvterm_options( variable_get('chado_stock_types_cv', 'NULL') );
   $type_options[0] = 'Select a Type';
-  if ($node->nid == '') { $type_default = 0; } else { $type_default = $node->stock->type_id->cvterm_id; }
+  if ($node->nid == '') {
+  $type_default = 0; }
+  else { $type_default = $node->stock->type_id->cvterm_id; }
   $form['details']['type_id'] = array(
     '#type' => 'select',
     '#title' => t('Type of Stock'),
     '#options' => $type_options,
     '#default_value' => $type_default,
-    '#required'	  => TRUE,
+    '#required'    => TRUE,
   );
 
   $stock_oganism_options = tripal_organism_get_organism_options();
   $stock_oganism_options[0] = 'Select An Organism';
-  if ($node->nid == '') { $organism_default = 0; } else {  $organism_default = $node->stock->organism_id->organism_id; }
+  if ($node->nid == '') {
+  $organism_default = 0; }
+  else {  $organism_default = $node->stock->organism_id->organism_id; }
   $form['details']['organism_id'] = array(
     '#type' => 'select',
     '#title' => t('Source Organism for stock'),
     '#default_value' => $organism_default,
     '#options' => $stock_oganism_options,
-    '#required'	  => TRUE
+    '#required'    => TRUE
   );
 
 
@@ -538,7 +542,9 @@ function chado_stock_form($node, $form_state) {
 
   $db_options = tripal_db_get_db_options();
   $db_options[0] = 'Select a Database';
-  if ($node->nid == '') { $db_default = 0; } else { $db_default = $node->stock->dbxref_id->db_id->db_id; }
+  if ($node->nid == '') {
+  $db_default = 0; }
+  else { $db_default = $node->stock->dbxref_id->db_id->db_id; }
   $form['database_reference']['database'] = array(
     '#type' => 'select',
     '#title' => t('Database'),
@@ -561,31 +567,33 @@ function chado_stock_form($node, $form_state) {
  */
 function chado_stock_validate($node, &$form) {
 
-	$int_in_chado_sql = "SELECT count(*) as count FROM %s WHERE %s=%d";
-	$string_in_chado_sql = "SELECT count(*) as count FROM %s WHERE %s='%s'";
-	
+  $int_in_chado_sql = "SELECT count(*) as count FROM %s WHERE %s=%d";
+  $string_in_chado_sql = "SELECT count(*) as count FROM %s WHERE %s='%s'";
+
   // Validate Uniquename only if add
   if (empty($node->stock_id)) {
-  	$previous_db = tripal_db_set_active('chado');
-  	$chado_row = db_fetch_object(db_query("SELECT * FROM stock WHERE uniquename='".$node->uniquename."'"));
-  	tripal_db_set_active($previous_db);
-  	if(!empty($chado_row->stock_id)) {
-  		$drupal_row = db_fetch_object(db_query("SELECT * FROM {chado_stock} WHERE stock_id=".$chado_row->stock_id));
-  		if (!empty($drupal_row->nid)) {
-  			$link = l('node/'.$drupal_row->nid, $node->uniquename);
-  			form_set_error('uniquename', "There is already a stock with that uniquename $link. Please enter another uniquename.");
-			} else {
-				form_set_error('uniquename', "There is already a stock with that uniquename (although it's not sync'd with drupal). Please enter another uniquename.");
-			}
-  	}
+    $previous_db = tripal_db_set_active('chado');
+    $chado_row = db_fetch_object(db_query("SELECT * FROM {stock} WHERE uniquename='" . $node->uniquename . "'"));
+    tripal_db_set_active($previous_db);
+    if (!empty($chado_row->stock_id)) {
+      $drupal_row = db_fetch_object(db_query("SELECT * FROM {chado_stock} WHERE stock_id=" . $chado_row->stock_id));
+      if (!empty($drupal_row->nid)) {
+        $link = l('node/' . $drupal_row->nid, $node->uniquename);
+        form_set_error('uniquename', "There is already a stock with that uniquename $link. Please enter another uniquename.");
+      }
+      else {
+        form_set_error('uniquename', "There is already a stock with that uniquename (although it's not sync'd with drupal). Please enter another uniquename.");
+      }
+    }
   }
 
 
   // Check Type of Stock is valid cvterm_id in chado ( $form['values']['details']['type_id'] )
   if ( $node->type_id == 0) {
     form_set_error('type_id', 'Please select a type of stock.');
-  } else {
-  	$previous_db = tripal_db_set_active('chado');
+  }
+  else {
+    $previous_db = tripal_db_set_active('chado');
     $num_rows = db_fetch_object(db_query($int_in_chado_sql, 'cvterm', 'cvterm_id', $node->type_id));
     tripal_db_set_active($previous_db);
     if ( $num_rows->count != 1) {
@@ -595,8 +603,9 @@ function chado_stock_validate($node, &$form) {
   // Check Source Organism is valid organism_id in chado ( $form['values']['details']['organism_id'] )
   if ( $node->organism_id == 0) {
     form_set_error('organism_id', 'Please select a source organism for this stock');
-  } else {
-  	$previous_db = tripal_db_set_active('chado');
+  }
+  else {
+    $previous_db = tripal_db_set_active('chado');
     $num_rows = db_fetch_object(db_query($int_in_chado_sql, 'organism', 'organism_id', $node->organism_id));
     tripal_db_set_active($previous_db);
     if ( $num_rows->count != 1 ) {
@@ -604,12 +613,13 @@ function chado_stock_validate($node, &$form) {
   }
 
   // Check if Accession also database
-  if ($node->accession != '') { 
+  if ($node->accession != '') {
     if ($node->database == 0) {
       // there is an accession but no database selected
       form_set_error('database', 'You need to enter both a database and an accession for that database in order to add a database reference.');
     }
-  } else {
+  }
+  else {
     if ($node->database > 0) {
       // there is a database selected but no accession
       form_set_error('accession', 'You need to enter both a database and an accession for that database in order to add a database reference.');
@@ -618,7 +628,7 @@ function chado_stock_validate($node, &$form) {
 
   // Check database is valid db_id in chado ( $form['values']['database_reference']['database'] )
   if ( $node->database > 0) {
-  	$previous_db = tripal_db_set_active('chado');
+    $previous_db = tripal_db_set_active('chado');
     $num_rows = db_fetch_object(db_query($int_in_chado_sql, 'db', 'db_id', $node->database));
     tripal_db_set_active($previous_db);
     if ($num_rows->count != 1) {
@@ -639,51 +649,52 @@ function chado_stock_validate($node, &$form) {
  * @ingroup tripal_stock
  */
 function chado_stock_insert($node) {
-  
+
   //If the chado stock exists
   // then don't create but simply link to node
   if ($node->chado_stock_exists) {
-  	if (!empty($node->stock_id)) {
-  		db_query(
-    		"INSERT INTO {chado_stock} (nid, vid, stock_id) "
-    		."VALUES (%d, %d, %d)",
-    		$node->nid,
-    		$node->vid,
-    		$node->stock_id
-  		);
-  	}
+    if (!empty($node->stock_id)) {
+      db_query(
+        "INSERT INTO {chado_stock} (nid, vid, stock_id) "
+        ."VALUES (%d, %d, %d)",
+        $node->nid,
+        $node->vid,
+        $node->stock_id
+      );
+    }
     return $node;
   }
-  
-	// create dbxref
+
+  // create dbxref
   if ( !empty($node->accession) ) {
-    if ( !empty($node->database) ) { 
+    if ( !empty($node->database) ) {
       $values = array(
-      	'db_id' => $node->database,
-      	'accession' => $node->accession,
+        'db_id' => $node->database,
+        'accession' => $node->accession,
       );
-      if (!tripal_core_chado_select('dbxref',array(dbxref_id), $values)) {
-      	$values['description'] = $node->db_description;
-      	$values['version'] = '1';
-      	$dbxref_status = tripal_core_chado_insert('dbxref', $values);
-      	if (!$dbxref_status) {
-      		drupal_set_message('Unable to add database reference to this stock.', 'warning');
-      		watchdog('tripal_stock', 
-      			'Insert Stock: Unable to create dbxref where values:%values', 
-      			array('%values' => print_r($values, TRUE)),
-      			WATCHDOG_WARNING
-      		);
-      	}
-      } else { $dbxref_status = 1; }
-  	}
+      if (!tripal_core_chado_select('dbxref', array(dbxref_id), $values)) {
+        $values['description'] = $node->db_description;
+        $values['version'] = '1';
+        $dbxref_status = tripal_core_chado_insert('dbxref', $values);
+        if (!$dbxref_status) {
+          drupal_set_message('Unable to add database reference to this stock.', 'warning');
+          watchdog('tripal_stock',
+            'Insert Stock: Unable to create dbxref where values:%values',
+            array('%values' => print_r($values, TRUE)),
+            WATCHDOG_WARNING
+          );
+        }
+      }
+      else { $dbxref_status = 1; }
+    }
   }
-  
+
   // create stock
-  if($dbxref_status) {
-		$values = array(
+  if ($dbxref_status) {
+    $values = array(
       'dbxref_id' => array(
-      	'db_id' => $node->database, 
-      	'accession' => $node->accession
+        'db_id' => $node->database,
+        'accession' => $node->accession
       ),
       'organism_id' => $node->organism_id,
       'name' => $node->title,
@@ -692,8 +703,9 @@ function chado_stock_insert($node) {
       'type_id' => $node->type_id
     );
     $stock_status = tripal_core_chado_insert('stock', $values);
-  } else {
-		$values = array(
+  }
+  else {
+    $values = array(
       'organism_id' => $node->organism_id,
       'name' => $node->title,
       'uniquename' => $node->uniquename,
@@ -705,39 +717,41 @@ function chado_stock_insert($node) {
 
   // create drupal chado_stock entry
   if ($stock_status) {
-	  $values = array(
-    	'organism_id' => $node->organism_id,
-    	'uniquename' => $node->uniquename,
-    	'type_id' => $node->type_id
-  	);
-  	$chado_stock = tripal_core_chado_select('stock', array('stock_id'), $values);
-  	if (!empty($chado_stock[0]->stock_id)) {
-  		db_query(
-    		"INSERT INTO {chado_stock} (nid, vid, stock_id) "
-    		."VALUES (%d, %d, %d)",
-    		$node->nid,
-    		$node->vid,
-    		$chado_stock[0]->stock_id
-  		);
-
- 	 		//Move on to next stage of Stock Creation based on next_stage_path field
-  		if ($node->simulate_multipart) {
-    		$next_stage_path = preg_replace('/%node/', $node->nid, $node->next_step_path);  
-    		$_REQUEST['destination'] = $next_stage_path;
-  		}
-  	} else {
-			drupal_set_message('Error during stock creation.', 'error');
-			watchdog('tripal_stock', 
-      	'Insert Stock: Unable to find newly created stock where values:%values', 
-      	array('%values' => print_r($values, TRUE)),
-      	WATCHDOG_ERROR
+    $values = array(
+      'organism_id' => $node->organism_id,
+      'uniquename' => $node->uniquename,
+      'type_id' => $node->type_id
+    );
+    $chado_stock = tripal_core_chado_select('stock', array('stock_id'), $values);
+    if (!empty($chado_stock[0]->stock_id)) {
+      db_query(
+        "INSERT INTO {chado_stock} (nid, vid, stock_id) "
+        ."VALUES (%d, %d, %d)",
+        $node->nid,
+        $node->vid,
+        $chado_stock[0]->stock_id
+      );
+
+        //Move on to next stage of Stock Creation based on next_stage_path field
+      if ($node->simulate_multipart) {
+        $next_stage_path = preg_replace('/%node/', $node->nid, $node->next_step_path);
+        $_REQUEST['destination'] = $next_stage_path;
+      }
+    }
+    else {
+      drupal_set_message('Error during stock creation.', 'error');
+      watchdog('tripal_stock',
+        'Insert Stock: Unable to find newly created stock where values:%values',
+        array('%values' => print_r($values, TRUE)),
+        WATCHDOG_ERROR
       );
       return FALSE;
-  	}
-  } else {
-  	drupal_set_message('Error during stock creation.', 'error');
-    watchdog('tripal_stock', 
-    	'Insert Stock: Unable to create stock where values:%values', 
+    }
+  }
+  else {
+    drupal_set_message('Error during stock creation.', 'error');
+    watchdog('tripal_stock',
+      'Insert Stock: Unable to create stock where values:%values',
       array('%values' => print_r($values, TRUE)),
       WATCHDOG_WARNING
     );
@@ -763,70 +777,73 @@ function chado_stock_update($node) {
 
   if ($node->revision) {
     chado_stock_insert($node);
-  } else {
-
-		//update dbxref
-		if ($node->database) {
-			if($node->accession) {
-				$dbxref_mode = '';
-				$stock = tripal_core_chado_select(
-					'stock', 
-					array('dbxref_id', 'type_id'), 
-					array('stock_id' => $node->stock_id)
-				);
-			
-				if ($stock[0]->dbxref_id) {
-					$values = array(
-						'db_id' => $node->database,
-						'accession' => $node->accession,
-						'description' => $node->db_description
-					);
-					$dbxref_status = tripal_core_chado_update(
-						'dbxref', 
-						array('dbxref_id' => $stock[0]->dbxref_id), 
-						$values
-					);
-					$dbxref_mode = 'Update';
-				} else {
-					if ($stock[0]->type_id) {
-						//create the dbxref
-						//used the type_id as a control to check we have a stock but not a dbxref
-						$values = array(
-							'db_id' => $node->database,
-							'accession' => $node->accession,
-							'description' => $node->db_description,
-							'version' => '1',
-						);						
-						$dbxref_status = tripal_core_chado_insert(
-							'dbxref',
-							$values
-						);
-						$dbxref_mode = 'Create';
-					} else {
-						drupal_set_message('Unable to find stock to Update', 'error');
-						watchdog(
-							'tripal_stock',
-							'Stock Update: Unable to find stock to update using values: %values',
-							array('%values', print_r($values, TRUE)),
-							WATCHDOG_ERROR
-						);
-						return FALSE;
-					}
-				}
-			}
-		}
-		
-		if (!$dbxref_status) {
-			watchdog(
-				'tripal_stock',
-				'Stock Update: Unable to %mode main stock dbxref with values: %values',
-				array('%values' => print_r($values,TRUE), '%mode' => $dbxref_mode),
-				WATCHDOG_WARNING
-			);
-		}
+  }
+  else {
+
+    //update dbxref
+    if ($node->database) {
+      if ($node->accession) {
+        $dbxref_mode = '';
+        $stock = tripal_core_chado_select(
+          'stock',
+          array('dbxref_id', 'type_id'),
+          array('stock_id' => $node->stock_id)
+        );
+
+        if ($stock[0]->dbxref_id) {
+          $values = array(
+            'db_id' => $node->database,
+            'accession' => $node->accession,
+            'description' => $node->db_description
+          );
+          $dbxref_status = tripal_core_chado_update(
+            'dbxref',
+            array('dbxref_id' => $stock[0]->dbxref_id),
+            $values
+          );
+          $dbxref_mode = 'Update';
+        }
+        else {
+          if ($stock[0]->type_id) {
+            //create the dbxref
+            //used the type_id as a control to check we have a stock but not a dbxref
+            $values = array(
+              'db_id' => $node->database,
+              'accession' => $node->accession,
+              'description' => $node->db_description,
+              'version' => '1',
+            );
+            $dbxref_status = tripal_core_chado_insert(
+              'dbxref',
+              $values
+            );
+            $dbxref_mode = 'Create';
+          }
+          else {
+            drupal_set_message('Unable to find stock to Update', 'error');
+            watchdog(
+              'tripal_stock',
+              'Stock Update: Unable to find stock to update using values: %values',
+              array('%values', print_r($values, TRUE)),
+              WATCHDOG_ERROR
+            );
+            return FALSE;
+          }
+        }
+      }
+    }
+
+    if (!$dbxref_status) {
+      watchdog(
+        'tripal_stock',
+        'Stock Update: Unable to %mode main stock dbxref with values: %values',
+        array('%values' => print_r($values, TRUE), '%mode' => $dbxref_mode),
+        WATCHDOG_WARNING
+      );
+    }
 
     //can't change stock id which is all thats stored in drupal thus only update chado
-		$update_values = array(
+    $update_values = array(
       'organism_id' => $node->organism_id,
       'name' => $node->title,
       'uniquename' => $node->uniquename,
@@ -834,25 +851,25 @@ function chado_stock_update($node) {
       'type_id' => $node->type_id,
     );
     if ($dbxref_status) {
-    	$update_values['dbxref_id'] = array(
-    		'db_id' => $node->database, 
-    		'accession' => $node->accession
-    	);
+      $update_values['dbxref_id'] = array(
+        'db_id' => $node->database,
+        'accession' => $node->accession
+      );
     }
     $status = tripal_core_chado_update(
-    	'stock',
-    	array('stock_id' => $node->stock_id), 
-    	$update_values
+      'stock',
+      array('stock_id' => $node->stock_id),
+      $update_values
     );
-    
+
     if (!$status) {
-    	drupal_set_message('Unable to update stock', 'error');
-    	watchdog(
-    		'tripal_stock',
-    		'Stock Update: Unable to update stock using match values: %mvalues and update values: %uvalues',
-				array('%mvalues' => print_r(array('stock_id' => $node->stock_id),TRUE), '%uvalues' => print_r($update_values,TRUE)),
-				WATCHDOG_ERROR
-    	);
+      drupal_set_message('Unable to update stock', 'error');
+      watchdog(
+        'tripal_stock',
+        'Stock Update: Unable to update stock using match values: %mvalues and update values: %uvalues',
+        array('%mvalues' => print_r(array('stock_id' => $node->stock_id), TRUE), '%uvalues' => print_r($update_values, TRUE)),
+        WATCHDOG_ERROR
+      );
     }
   }
 
@@ -876,11 +893,11 @@ function chado_stock_delete($node) {
   // Set stock in chado: is_obsolete = TRUE
   $previous_db = tripal_db_set_active('chado');
   db_query(
-    "DELETE FROM stock WHERE stock_id=%d",
+    "DELETE FROM {stock} WHERE stock_id=%d",
     $node->stock->stock_id
   );
   tripal_db_set_active($previous_db);
-  
+
   //remove drupal node and all revisions
   db_query(
     "DELETE FROM {chado_stock} WHERE nid=%d",
@@ -892,7 +909,7 @@ function chado_stock_delete($node) {
  * Purpose: Implement Blocks relating to stock content
  *
  * @param $op
- *   What kind of information to retrieve about the block or blocks. 
+ *   What kind of information to retrieve about the block or blocks.
  *   Possible values include list, configure, save, view.
  * @param $delta
  *   Which block to return (not applicable if $op is 'list').
@@ -900,66 +917,66 @@ function chado_stock_delete($node) {
  *   If $op is 'save', the submitted form data from the configuration form.
  *
  * @return
- *   One of the following depending on $op: An array of block descriptions (list), the configuration 
- *   form (configure), nothing (save), an array defining subject and content for the block indexed 
+ *   One of the following depending on $op: An array of block descriptions (list), the configuration
+ *   form (configure), nothing (save), an array defining subject and content for the block indexed
  *   by $delta (view)
  *
  * @ingroup tripal_stock
  */
-function tripal_stock_block ($op = 'list', $delta = 0, $edit=array()) {
-  switch($op) {
+function tripal_stock_block($op = 'list', $delta = 0, $edit=array()) {
+  switch ($op) {
     case 'list':
       $blocks['base']['info'] = t('Tripal Stock Details');
       $blocks['base']['cache'] = BLOCK_NO_CACHE;
 
       $blocks['properties']['info'] = t('Tripal Stock Properties');
       $blocks['properties']['cache'] = BLOCK_NO_CACHE;
-         
+
       $blocks['references']['info'] = t('Tripal Stock References');
       $blocks['references']['cache'] = BLOCK_NO_CACHE;
-         
+
       $blocks['relationships_as_object']['info'] = t('Tripal Stock Relationships');
       $blocks['relationships_as_object']['cache'] = BLOCK_NO_CACHE;
-         
+
       $blocks['synonyms']['info'] = t('Tripal Stock Synonyms');
       $blocks['synonyms']['cache'] = BLOCK_NO_CACHE;
-                  
+
       return $blocks;
 
- 		case 'view':
- 			if(user_access('access chado_stock content') and arg(0) == 'node' and is_numeric(arg(1))) {
-      	$nid = arg(1);
-      	$node = node_load($nid);
- 
+     case 'view':
+       if (user_access('access chado_stock content') and arg(0) == 'node' and is_numeric(arg(1))) {
+        $nid = arg(1);
+        $node = node_load($nid);
+
         $block = array();
-        switch($delta){
-					case 'base':
-						$block['subject'] = t('Stock Details');
-						$block['content'] = theme('tripal_stock_base',$node);
-						break;
-						
-					case 'properties':
-						$block['subject'] = t('Properties');
-						$block['content'] = theme('tripal_stock_properties',$node);
-						break;
-						
-					case 'references':
-						$block['subject'] = t('References');
-						$block['content'] = theme('tripal_stock_references',$node);
-						break;
-						
-					case 'relationships':
-						$block['subject'] = t('Relationships');
-						$block['content'] = theme('tripal_stock_relationships',$node);
-						break;
-						
-					case 'synonyms':
-						$block['subject'] = t('Synonyms');
-						$block['content'] = theme('tripal_stock_synonyms',$node);
-						break;
-						
+        switch ($delta) {
+          case 'base':
+            $block['subject'] = t('Stock Details');
+            $block['content'] = theme('tripal_stock_base', $node);
+            break;
+
+          case 'properties':
+            $block['subject'] = t('Properties');
+            $block['content'] = theme('tripal_stock_properties', $node);
+            break;
+
+          case 'references':
+            $block['subject'] = t('References');
+            $block['content'] = theme('tripal_stock_references', $node);
+            break;
+
+          case 'relationships':
+            $block['subject'] = t('Relationships');
+            $block['content'] = theme('tripal_stock_relationships', $node);
+            break;
+
+          case 'synonyms':
+            $block['subject'] = t('Synonyms');
+            $block['content'] = theme('tripal_stock_synonyms', $node);
+            break;
+
         }
-				return $block;
-			}
-	}
+        return $block;
+      }
+  }
 }

+ 86 - 86
tripal_stock/tripal_stock.views.inc

@@ -65,32 +65,32 @@ function tripal_stock_views_handlers() {
      'views_handler_field_stockprop_by_type' => array(
        'parent' => 'views_handler_field_prerender_list',
      ),
-		'views_handler_field_stockprop_all' => array(
+    'views_handler_field_stockprop_all' => array(
        'parent' => 'views_handler_field_prerender_list',
      ),
-		'views_handler_field_stockrel_by_type' => array(
+    'views_handler_field_stockrel_by_type' => array(
        'parent' => 'views_handler_field_prerender_list',
      ),
-		'views_handler_field_stockrel_all' => array(
+    'views_handler_field_stockrel_all' => array(
        'parent' => 'views_handler_field_prerender_list',
      ),
-		'views_handler_field_stock_dbxref_by_type' => array(
+    'views_handler_field_stock_dbxref_by_type' => array(
        'parent' => 'views_handler_field_prerender_list',
      ),
-		'views_handler_field_stock_dbxref_all' => array(
+    'views_handler_field_stock_dbxref_all' => array(
        'parent' => 'views_handler_field_prerender_list',
      ),
      'views_handler_filter_stockprop_id' => array(
-     	'parent' => 'views_handler_filter',
+       'parent' => 'views_handler_filter',
      ),
      'views_handler_filter_stock_dbxref_id' => array(
-     	'parent' => 'views_handler_filter',
+       'parent' => 'views_handler_filter',
      ),
      'views_handler_filter_stock_relationship_id' => array(
-     	'parent' => 'views_handler_filter',
+       'parent' => 'views_handler_filter',
      ),
      'views_handler_argument_stockprop_id' => array(
-     	'parent' => 'views_handler_argument_string',
+       'parent' => 'views_handler_argument_string',
      ),
    ),
  );
@@ -101,7 +101,7 @@ function tripal_stock_views_handlers() {
  */
 function tripal_stock_views_data_alter(&$data) {
 
-  if( !(is_array($db_url) and array_key_exists('chado',$db_url)) ){
+  if ( !(is_array($db_url) and array_key_exists('chado', $db_url)) ) {
 
     // Add featuer relationship to node
     $data['node']['stock_chado_nid'] = array(
@@ -134,92 +134,92 @@ function tripal_stock_views_data_alter(&$data) {
  *
  * @ingroup tripal_stock_views
  */
-function tripal_stock_views_pre_render	(&$view) {
-	if (preg_match('/stock/', $view->base_table)) {
+function tripal_stock_views_pre_render  (&$view) {
+  if (preg_match('/stock/', $view->base_table)) {
 
-		//-----Node IDs---------------------------------------------
-		// @see file: tripal_core.views.inc function: tripal_core_add_node_ids_to_view (&$view);
+    //-----Node IDs---------------------------------------------
+    // @see file: tripal_core.views.inc function: tripal_core_add_node_ids_to_view (&$view);
 
-		// retrieve the stock_id for each record in the views current page
-		$stock_ids = array();
-		foreach ($view->result as $row_num => $row) {
-			$stock_ids[$row_num] = $row->stock_id;
-		}
+    // retrieve the stock_id for each record in the views current page
+    $stock_ids = array();
+    foreach ($view->result as $row_num => $row) {
+      $stock_ids[$row_num] = $row->stock_id;
+    }
 
-		if (sizeof($stock_ids)) {
+    if (sizeof($stock_ids)) {
 
-			//-----Properties------------------------------------------
-			$field_names = array_keys($view->field);
-			//if any property fields are in the current view
-			$property_field_names = preg_grep('/properties/',$field_names);
-			if (!empty($property_field_names)) {
-				$sql = "SELECT stockprop.*, cvterm.name as type_name FROM stockprop "
-					."INNER JOIN cvterm cvterm ON stockprop.type_id=cvterm.cvterm_id "
-					."WHERE stockprop.stock_id IN (".implode(',',$stock_ids).")";
-				$previous_db = tripal_db_set_active('chado');
-				$resource = db_query($sql);
-			 tripal_db_set_active($previous_db);
+      //-----Properties------------------------------------------
+      $field_names = array_keys($view->field);
+      //if any property fields are in the current view
+      $property_field_names = preg_grep('/properties/', $field_names);
+      if (!empty($property_field_names)) {
+        $sql = "SELECT stockprop.*, cvterm.name as type_name FROM {stockprop} "
+          ."INNER JOIN cvterm cvterm ON stockprop.type_id=cvterm.cvterm_id "
+          ."WHERE stockprop.stock_id IN (" . implode(',', $stock_ids) . ")";
+        $previous_db = tripal_db_set_active('chado');
+        $resource = db_query($sql);
+       tripal_db_set_active($previous_db);
 
-				$view->result[$key]->properties = array();
-				while ($r = db_fetch_object($resource)) {
-					$key = array_search($r->stock_id, $stock_ids);
-					$view->result[$key]->properties[] = $r;
-				}
-			}
+        $view->result[$key]->properties = array();
+        while ($r = db_fetch_object($resource)) {
+          $key = array_search($r->stock_id, $stock_ids);
+          $view->result[$key]->properties[] = $r;
+        }
+      }
 
-			//-----Relationships----------------------------------------
-			//if any relationship fields are in the current view
-			$relationship_field_names = preg_grep('/relationships/', $field_names);
-			if (!empty($relationship_field_names)) {
-				$sql = "SELECT stock_relationship.*, cvterm.name as type_name, "
-					."subject_stock.name as subject_name, object_stock.name as object_name "
-					."FROM stock_relationship "
-					."LEFT JOIN stock subject_stock ON stock_relationship.subject_id=subject_stock.stock_id "
-					."LEFT JOIN stock object_stock ON stock_relationship.object_id=object_stock.stock_id "
-					."LEFT JOIN cvterm cvterm ON stock_relationship.type_id = cvterm.cvterm_id "
-					."WHERE stock_relationship.subject_id IN (".implode(',',$stock_ids).") "
-					."OR stock_relationship.object_id IN (".implode(',',$stock_ids).") ";
-				$previous_db = tripal_db_set_active('chado');
-				$resource = db_query($sql);
-			 tripal_db_set_active($previous_db);
+      //-----Relationships----------------------------------------
+      //if any relationship fields are in the current view
+      $relationship_field_names = preg_grep('/relationships/', $field_names);
+      if (!empty($relationship_field_names)) {
+        $sql = "SELECT stock_relationship.*, cvterm.name as type_name, "
+          ."subject_stock.name as subject_name, object_stock.name as object_name "
+          ."FROM stock_relationship "
+          ."LEFT JOIN stock subject_stock ON stock_relationship.subject_id=subject_stock.stock_id "
+          ."LEFT JOIN stock object_stock ON stock_relationship.object_id=object_stock.stock_id "
+          ."LEFT JOIN cvterm cvterm ON stock_relationship.type_id = cvterm.cvterm_id "
+          ."WHERE stock_relationship.subject_id IN (" . implode(',', $stock_ids) . ") "
+          ."OR stock_relationship.object_id IN (" . implode(',', $stock_ids) . ") ";
+        $previous_db = tripal_db_set_active('chado');
+        $resource = db_query($sql);
+       tripal_db_set_active($previous_db);
 
-				while ($r = db_fetch_object($resource)) {
-					if (in_array($r->subject_id, $stock_ids)) {
-						$key = array_search($r->subject_id, $stock_ids);
-						$r->stock_id = $r->subject_id;
-						$view->result[$key]->relationships[] = clone $r;
-					}
-					if (in_array($r->object_id, $stock_ids)) {
-						$key = array_search($r->object_id, $stock_ids);
-						$r->stock_id = $r->object_id;
-						$view->result[$key]->relationships[] = clone $r;
-					}
-				}
-			}
+        while ($r = db_fetch_object($resource)) {
+          if (in_array($r->subject_id, $stock_ids)) {
+            $key = array_search($r->subject_id, $stock_ids);
+            $r->stock_id = $r->subject_id;
+            $view->result[$key]->relationships[] = clone $r;
+          }
+          if (in_array($r->object_id, $stock_ids)) {
+            $key = array_search($r->object_id, $stock_ids);
+            $r->stock_id = $r->object_id;
+            $view->result[$key]->relationships[] = clone $r;
+          }
+        }
+      }
 
-			//-----DB References--------------------------------------------
-			//if any dbxref fields are in the current view
-			$dbxref_field_names = preg_grep('/dbxref/',$field_names);
-			if (!empty($dbxref_field_names)) {
-				$sql = "SELECT stock_dbxref.*, dbxref.db_id, db.name as db_name, db.urlprefix, "
-					."dbxref.accession, dbxref.version, dbxref.description "
-					."FROM stock_dbxref "
-					."LEFT JOIN dbxref dbxref ON stock_dbxref.dbxref_id=dbxref.dbxref_id "
-					."LEFT JOIN db db ON dbxref.db_id=db.db_id "
-					."WHERE stock_dbxref.stock_id IN (".implode(',',$stock_ids).")";
-				$previous_db = tripal_db_set_active('chado');
-				$resource = db_query($sql);
-			 tripal_db_set_active($previous_db);
+      //-----DB References--------------------------------------------
+      //if any dbxref fields are in the current view
+      $dbxref_field_names = preg_grep('/dbxref/', $field_names);
+      if (!empty($dbxref_field_names)) {
+        $sql = "SELECT stock_dbxref.*, dbxref.db_id, db.name as db_name, db.urlprefix, "
+          ."dbxref.accession, dbxref.version, dbxref.description "
+          ."FROM stock_dbxref "
+          ."LEFT JOIN dbxref dbxref ON stock_dbxref.dbxref_id=dbxref.dbxref_id "
+          ."LEFT JOIN db db ON dbxref.db_id=db.db_id "
+          ."WHERE stock_dbxref.stock_id IN (" . implode(',', $stock_ids) . ")";
+        $previous_db = tripal_db_set_active('chado');
+        $resource = db_query($sql);
+       tripal_db_set_active($previous_db);
 
-				$view->result[$key]->dbxref = array();
-				while ($r = db_fetch_object($resource)) {
-					$key = array_search($r->stock_id, $stock_ids);
-					$view->result[$key]->dbxref[] = $r;
-				}
-			}
+        $view->result[$key]->dbxref = array();
+        while ($r = db_fetch_object($resource)) {
+          $key = array_search($r->stock_id, $stock_ids);
+          $view->result[$key]->dbxref[] = $r;
+        }
+      }
 
-		} //if there are stocks
-	} //if we're dealing with a stock view
+    } //if there are stocks
+  } //if we're dealing with a stock view
 }
 
 /**

+ 25 - 24
tripal_stock/views/chado_stock.views.inc

@@ -3,7 +3,8 @@
 //module_load_include('inc','views', 'handlers/views_handler_relationship');
 
 /**
- * Purpose: this function returns the portion of the data array which describes the chado_stock 
+ * @file
+ * Purpose: this function returns the portion of the data array which describes the chado_stock
  * drupal table, it's fields and any joins between it and other tables
  *
  * The main need for description of this table to views is to join chado data with drupal nodes
@@ -12,14 +13,14 @@
  *
  * @ingroup tripal_stock_views
  */
-function retrieve_chado_stock_views_data () {
-	global $db_url;
+function retrieve_chado_stock_views_data() {
+  global $db_url;
   $data = array();
-  
+
   // if the chado database is not local to the drupal database
   // then we need to set the database name.  This should always
   // be 'chado'.
-  if(is_array($db_url) and array_key_exists('chado',$db_url)){
+  if (is_array($db_url) and array_key_exists('chado', $db_url)) {
      // return empty data array b/c if chado is external then no join to the nodetable can be made
      return $data;
   }
@@ -34,38 +35,38 @@ function retrieve_chado_stock_views_data () {
     'title' => t('Stock Node ID'),
     'help' => t('The node ID for this analysis'),
     'field' => array(
-     	'handler' => 'views_handler_field_numeric',
- 		  'click sortable' => TRUE,
+       'handler' => 'views_handler_field_numeric',
+       'click sortable' => TRUE,
     ),
     'filter' => array(
-     	'handler' => 'views_handler_filter_numeric',
+       'handler' => 'views_handler_filter_numeric',
     ),
     'sort' => array(
-     	'handler' => 'views_handler_sort',
+       'handler' => 'views_handler_sort',
     ),
   );
-  
+
   // Note: No joins need to be made from $data['stock']['table']
-  
+
   // Join the chado stock table to stock
   $data['chado_stock']['table']['join']['stock'] = array(
-  	'left_field' => 'stock_id',
-  	'field' => 'stock_id',
+    'left_field' => 'stock_id',
+    'field' => 'stock_id',
   );
-  
+
   // Join the node table to chado stock
   $data['node']['table']['join']['chado_stock'] = array(
-  	'left_field' => 'nid',
-  	'field' => 'nid',
+    'left_field' => 'nid',
+    'field' => 'nid',
   );
-  
+
   // Join the node table to stock
   $data['node']['table']['join']['stock'] = array(
-  	'left_table' => 'chado_stock',
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );  
-  
+    'left_table' => 'chado_stock',
+    'left_field' => 'nid',
+    'field' => 'nid',
+  );
+
   // Add relationship between chado_stock and stock
   $data['chado_stock']['stock_nid'] = array(
     'group' => 'Stock',
@@ -97,6 +98,6 @@ function retrieve_chado_stock_views_data () {
       'base field' => 'nid'
     ),
   );
-  
-	return $data;
+
+  return $data;
 }

+ 43 - 39
tripal_stock/views/handlers/views_handler_argument_stockprop_id.inc

@@ -1,6 +1,7 @@
 <?php
 
 /**
+ * @file
  * Allows a stock property in the path to be used to filter a view
  *
  * @ingroup tripal_stock
@@ -8,64 +9,67 @@
  */
 class views_handler_argument_stockprop_id extends views_handler_argument_string {
 
-	function options_form(&$form, &$form_state) {
-    parent::options_form($form, $form_state);   
+  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)");
+    $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(
+    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,
-		);
+      '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() {
+  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);
+
+    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);
   }
 
-}
+}

+ 15 - 14
tripal_stock/views/handlers/views_handler_field_computed_stock_nid.inc

@@ -1,26 +1,27 @@
 <?php
 
 /**
- * Adds the Node ID to for the current stock 
+ * @file
+ * Adds the Node ID to for the current stock
  *
- * This handler is only needed if chado is in a separate database and, therefore, the node tables 
+ * This handler is only needed if chado is in a separate database and, therefore, the node tables
  * cannot be joined to the stock tables
  *
  * @ingroup tripal_stock
  * @ingroup views_field_handlers
  */
 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 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 query() {
+    $this->ensure_my_table();
+    $this->add_additional_fields();
+  }
 
-	function render($values) { 
-		return $values->stock_nid;
-	}
-} 
+  function render($values) {
+    return $values->stock_nid;
+  }
+}

+ 53 - 51
tripal_stock/views/handlers/views_handler_field_stock_dbxref_all.inc

@@ -1,9 +1,10 @@
 <?php
 
 /**
+ * @file
  * Field handler allowing all database references for a given stock to be displayed in a single cell
  *
- * This handler only deals with database references joined to the stock through stock_dbxref. For 
+ * This handler only deals with database references joined to the stock through stock_dbxref. For
  * the database reference joined to the stock by stock.dbxref_id simply join to the dbxref table.
  *
  * @ingroup tripal_stock
@@ -21,66 +22,67 @@ class views_handler_field_stock_dbxref_all extends views_handler_field_prerender
     $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 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'].')';
-		}
+    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');
+    $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'];
+    $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'];
   }
 }
 

+ 100 - 96
tripal_stock/views/handlers/views_handler_field_stock_dbxref_by_type.inc

@@ -1,10 +1,11 @@
 <?php
 
 /**
- * Field handler allowing all database references of a specified db for a given stock to be 
+ * @file
+ * Field handler allowing all database references of a specified db for a given stock to be
  * displayed in a single cell.
  *
- * This handler only deals with database references joined to the stock through stock_dbxref. For 
+ * This handler only deals with database references joined to the stock through stock_dbxref. For
  * the database reference joined to the stock by stock.dbxref_id simply join to the dbxref table.
  *
  * @ingroup tripal_stock
@@ -16,7 +17,7 @@ class views_handler_field_stock_dbxref_by_type extends views_handler_field_prere
 
     // 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    
+    //    FALSE => or just value is rendered  -only 1 porperty type is displayed
     $this->display_type = TRUE;
 
   }
@@ -24,7 +25,7 @@ class views_handler_field_stock_dbxref_by_type extends views_handler_field_prere
   function option_definition() {
     $options = parent::option_definition();
     $options['stockprop_type_ids'] = array('default' => array());
-		$options['display_options'] = array('default' => array('accession','db_name','link'));
+    $options['display_options'] = array('default' => array('accession', 'db_name', 'link'));
     return $options;
   }
 
@@ -34,23 +35,23 @@ class views_handler_field_stock_dbxref_by_type extends views_handler_field_prere
   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']),
-		);
-		
+    $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);
+    $db_options[0] = 'Select a Database';
+    ksort($db_options);
     $form['db_ids'] = array(
       '#type' => 'checkboxes',
       '#title' => t('Database'),
@@ -66,92 +67,95 @@ class views_handler_field_stock_dbxref_by_type extends views_handler_field_prere
     $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 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];
-		}
+    $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');
+    $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'];
+    $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'];
   }
 }
 

+ 25 - 24
tripal_stock/views/handlers/views_handler_field_stockprop_all.inc

@@ -1,6 +1,7 @@
 <?php
 
 /**
+ * @file
  * Field handler allowing all properties for a given stock to be displayed in a single cell
  *
  * @ingroup tripal_stock
@@ -18,32 +19,32 @@ class views_handler_field_stockprop_all extends views_handler_field_prerender_li
     $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 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'].')';
+    return $item['value'] . ' (' . $item['type_name'] . ')';
   }
 
   function document_self_tokens(&$tokens) {

+ 18 - 15
tripal_stock/views/handlers/views_handler_field_stockprop_by_type.inc

@@ -1,7 +1,8 @@
 <?php
 
 /**
- * Field handler allowing all properties of a specified type for a given stock to be displayed in a 
+ * @file
+ * Field handler allowing all properties of a specified type for a given stock to be displayed in a
  * single cell
  *
  * @ingroup tripal_stock
@@ -9,7 +10,7 @@
  */
 class views_handler_field_stockprop_by_type extends views_handler_field_prerender_list {
   function init(&$view, $options) {
-    parent::init($view, $options);    
+    parent::init($view, $options);
   }
 
   function option_definition() {
@@ -40,7 +41,7 @@ class views_handler_field_stockprop_by_type extends views_handler_field_prerende
       ),
       '#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">',
@@ -51,7 +52,7 @@ class views_handler_field_stockprop_by_type extends views_handler_field_prerende
       '#default_value' => $this->options['stockprop_type_ids'],
     );
   }
-  
+
   /**
    * Add this term to the query
    */
@@ -63,11 +64,11 @@ class views_handler_field_stockprop_by_type extends views_handler_field_prerende
     $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) {
@@ -78,7 +79,7 @@ class views_handler_field_stockprop_by_type extends views_handler_field_prerende
               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;
@@ -93,23 +94,25 @@ class views_handler_field_stockprop_by_type extends views_handler_field_prerende
 
   function render_item($count, $item) {
     $text = array();
-    
+
     if ($this->options['stockprop_display_options']['value']) {
       if ($item['value']) {
         $text[] =  $item['value'];
-      } else {
+      }
+      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" />';
+        $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] . ' (' . $text[1] . ')';
+    }
+    else {
       return $text[0];
     }
   }

+ 41 - 40
tripal_stock/views/handlers/views_handler_field_stockrel_all.inc

@@ -1,6 +1,7 @@
 <?php
 
 /**
+ * @file
  * Field handler allowing all relationships for a given stock to be displayed in a single cell
  *
  * @ingroup tripal_stock
@@ -18,56 +19,56 @@ class views_handler_field_stockrel_all extends views_handler_field_prerender_lis
     $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 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'];
+    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');
+    $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'];
+    $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'];
 
   }
 }

+ 16 - 14
tripal_stock/views/handlers/views_handler_field_stockrel_by_type.inc

@@ -1,7 +1,8 @@
 <?php
 
 /**
- * Field handler allowing all relationships of a specified type for a given stock to be displayed in 
+ * @file
+ * Field handler allowing all relationships of a specified type for a given stock to be displayed in
  * a single cell
  *
  * @ingroup tripal_stock
@@ -13,7 +14,7 @@ class views_handler_field_stockrel_by_type extends views_handler_field_prerender
 
     // 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    
+    //    FALSE => or just value is rendered  -only 1 porperty type is displayed
     $this->display_type = TRUE;
 
   }
@@ -21,7 +22,7 @@ class views_handler_field_stockrel_by_type extends views_handler_field_prerender
   function option_definition() {
     $options = parent::option_definition();
     $options['stockrel_type_ids'] = array('default' => array());
-    $options['stockrel_display_options'] = array('default' => array('subject','type','object'));
+    $options['stockrel_display_options'] = array('default' => array('subject', 'type', 'object'));
     return $options;
   }
 
@@ -45,7 +46,7 @@ class views_handler_field_stockrel_by_type extends views_handler_field_prerender
       ),
       '#default_value' => array($this->options['stockrel_display_parts']['subject'], $this->options['stockrel_display_parts']['type'], $this->options['stockrel_display_parts']['object']),
     );
-    
+
     $form['stockrel_display_rels'] = array(
       '#type' => 'radios',
       '#title' => t('Display Relationships Where'),
@@ -62,7 +63,7 @@ class views_handler_field_stockrel_by_type extends views_handler_field_prerender
       ),
       '#default_value' => $this->options['stockrel_display_rels'],
     );
-    
+
     $options = tripal_cv_get_cvterm_options( variable_get('chado_stock_relationship_cv', 'null') );
     $form['stockrel_type_ids'] = array(
       '#type' => 'checkboxes',
@@ -83,14 +84,14 @@ class views_handler_field_stockrel_by_type extends views_handler_field_prerender
     $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) {      
+        foreach ($relationships as $relationship) {
           // perform filtering------
           //type
           if (!empty($this->options['stockrel_type_ids'])) {
@@ -99,18 +100,19 @@ class views_handler_field_stockrel_by_type extends views_handler_field_prerender
               continue;
             }
           }
-          
+
           //"Display Relationships Where" criteria
           if (preg_match('/subject/', $this->options['stockrel_display_rels'])) {
             if ($relationship->stock_id != $relationship->subject_id) {
               continue;
-            }      
-          } elseif (preg_match('/object/', $this->options['stockrel_display_rels'])) {
+            }
+          }
+          elseif (preg_match('/object/', $this->options['stockrel_display_rels'])) {
             if ($relationship->stock_id != $relationship->object_id) {
               continue;
             }
           }
-          
+
           // 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;
@@ -127,7 +129,7 @@ class views_handler_field_stockrel_by_type extends views_handler_field_prerender
 
   function render_item($count, $item) {
     $text = array();
-    
+
     // Render Parts
     if ($this->options['stockrel_display_parts']['subject']) {
       $text[] = $item['subject_name'];
@@ -138,7 +140,7 @@ class views_handler_field_stockrel_by_type extends views_handler_field_prerender
     if ($this->options['stockrel_display_parts']['object']) {
       $text[] = $item['object_name'];
     }
-    
+
     return implode(' ', $text);
   }
 

+ 33 - 30
tripal_stock/views/handlers/views_handler_filter_stock_dbxref_id.inc

@@ -1,6 +1,7 @@
 <?php
 
 /**
+ * @file
  * Allows stocks to be filtered by associated database reference accession
  *
  * @ingroup tripal_stock
@@ -12,7 +13,7 @@ class views_handler_filter_stock_dbxref_id extends views_handler_filter {
     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);
@@ -33,32 +34,34 @@ class views_handler_filter_stock_dbxref_id extends views_handler_filter {
 
   }
 
-	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);
-			}
-		}
-	}
-  
+  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);
+    ksort($db_options);
     $form['db'] = array(
       '#type' => 'checkboxes',
       '#title' => t('Databases'),
@@ -72,10 +75,10 @@ class views_handler_filter_stock_dbxref_id extends views_handler_filter {
 
   function value_form(&$form, &$form_state) {
     parent::value_form($form, $form_state);
-    
-		$form['value'] = array(
-  	  '#type' => 'textfield',
-    	'#title' => t('Accession'),
+
+    $form['value'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Accession'),
       '#default_value' => $this->value,
     );
   }
@@ -105,7 +108,7 @@ class views_handler_filter_stock_dbxref_id extends views_handler_filter {
         '#type' => 'select',
         '#title' => t('Database References'),
         '#options' => $this->type_options(),
-        '#default_value' => $this->type,  
+        '#default_value' => $this->type,
       );
 
       if (isset($form[$type]['#title'])) {
@@ -230,7 +233,7 @@ class views_handler_filter_stock_dbxref_id extends views_handler_filter {
         '#value' => '',
       );
     }
-    
+
     $form['expose']['optional'] = array(
       '#type' => 'checkbox',
       '#title' => t('Optional'),

+ 99 - 89
tripal_stock/views/handlers/views_handler_filter_stock_relationship_id.inc

@@ -2,111 +2,120 @@
 
 class views_handler_filter_stock_relationship_id extends views_handler_filter {
 
-	function query () {
-	  if ($this->value) {
-	  
+  function query() {
+    if ($this->value) {
+
       // get variable position
       if ($this->options['fixed_position'] == 'subject_id') {
         $this->options['variable_position'] = 'object_id';
-      } else {
+      }
+      else {
         $this->options['variable_position'] = 'subject_id';
       }
-        
-	    // determine if just checking presence
-	    if (preg_match('/NULL/', $this->operator)) {
+
+      // determine if just checking presence
+      if (preg_match('/NULL/', $this->operator)) {
           $where = 'stock.stock_id IN ('
-            .'SELECT '.$this->options['variable_position'].' FROM stock_relationship '
-            .'WHERE '.$this->options['fixed_position'].' '.$this->operator.' AND type_id = '.$this->options['type']
-          .')';
-          $this->query->add_where($this->options['group'], $where);	      
-	    } else {
-        
+            . 'SELECT ' . $this->options['variable_position'] . ' FROM {stock_relationship} '
+            . 'WHERE ' . $this->options['fixed_position'] . ' ' . $this->operator . ' AND type_id = ' . $this->options['type']
+          . ')';
+          $this->query->add_where($this->options['group'], $where);
+      }
+      else {
+
         // determine whether regex was requested
         if ($this->operator == '~') {
-          $search_options = array('regex_columns' => array('name','uniquename'));
+          $search_options = array('regex_columns' => array('name', 'uniquename'));
           $this->operator = '=';
-        } elseif ($this->operator == '!~') {
-          $search_options = array('regex_columns' => array('name','uniquename'));
+        }
+        elseif ($this->operator == '!~') {
+          $search_options = array('regex_columns' => array('name', 'uniquename'));
           $this->operator = '!=';
-        } else {
+        }
+        else {
           $search_options = array();
         }
-        
+
         // get fixed stock id(s)
-        $fixed_stock = tripal_core_chado_select('stock',array('stock_id'),array('uniquename' => $this->value), $search_options);
+        $fixed_stock = tripal_core_chado_select('stock', array('stock_id'), array('uniquename' => $this->value), $search_options);
         $fixed_stock_ids = array();
         if ($fixed_stock[0]->stock_id) {
           $fixed_stock_ids[] = $fixed_stock[0]->stock_id;
-        } else {
-          $fixed_stock = tripal_core_chado_select('stock',array('stock_id'),array('name' => $this->value), $search_options);
+        }
+        else {
+          $fixed_stock = tripal_core_chado_select('stock', array('stock_id'), array('name' => $this->value), $search_options);
           if (sizeof($fixed_stock) > 1) {
             foreach ($fixed_stock as $s) {
               $fixed_stock_ids[] = $s->stock_id;
             }
-          } elseif (sizeof($fixed_stock) == 1) {
+          }
+          elseif (sizeof($fixed_stock) == 1) {
             $fixed_stock_ids[] = $fixed_stock[0]->stock_id;
           }
         }
-        
+
         // determine operator
         if ($this->operator == '=' && sizeof($fixed_stock_ids) > 1) {
           $this->operator = 'IN';
-        } elseif ($this->operator == '!=' && sizeof($fixed_stock_ids) > 1) {
+        }
+        elseif ($this->operator == '!=' && sizeof($fixed_stock_ids) > 1) {
           $this->operator = 'NOT IN';
         }
-        
+
         //generate where
         if (sizeof($fixed_stock_ids) == 1) {
           $where = 'stock.stock_id IN ('
-            .'SELECT '.$this->options['variable_position'].' FROM stock_relationship '
-            .'WHERE '.$this->options['fixed_position'].' '.$this->operator.' '.$fixed_stock_ids[0].' AND type_id = '.$this->options['type']
-          .')';
+            . 'SELECT ' . $this->options['variable_position'] . ' FROM {stock_relationship} '
+            . 'WHERE ' . $this->options['fixed_position'] . ' ' . $this->operator . ' ' . $fixed_stock_ids[0] . ' AND type_id = ' . $this->options['type']
+          . ')';
           $this->query->add_where($this->options['group'], $where);
-        } elseif (sizeof($fixed_stock_ids) > 1) {
+        }
+        elseif (sizeof($fixed_stock_ids) > 1) {
           $where = 'stock.stock_id IN ('
-            .'SELECT '.$this->options['variable_position'].' FROM stock_relationship '
-            .'WHERE '.$this->options['fixed_position'].' '.$this->operator.' ('.implode(', ',$fixed_stock_ids).') AND type_id = '.$this->options['type']
-          .')';
+            . 'SELECT ' . $this->options['variable_position'] . ' FROM {stock_relationship} '
+            . 'WHERE ' . $this->options['fixed_position'] . ' ' . $this->operator . ' (' . implode(', ', $fixed_stock_ids) . ') AND type_id = ' . $this->options['type']
+          . ')';
           $this->query->add_where($this->options['group'], $where);
-        } else {
-          drupal_set_message('No stock with the name or uniquename '.$this->value.' was found -No filtering done.','error');
+        }
+        else {
+          drupal_set_message('No stock with the name or uniquename ' . $this->value . ' was found -No filtering done.', 'error');
         }
       } //end of not just checking presence
     }
-	}
-	
+  }
+
   function options_form(&$form, &$form_state) {
-  	
+
     if ($this->can_expose()) {
       $this->show_expose_button($form, $form_state);
     }
 
-  	$instructions = 'This filter allows you to enter a stock, the position of that stock in the '
-  		.'relationship and relationship type and only stocks with a relationship of the type described '
-  		.'will be shown. For example, if you want all stocks where Fred is_paternal_parent_of, then '
-  		.'you would enter Fred as the value, select is_paternal_parent_of as the Relationship Type '
-  		.'and subject as the Fixed Position.';
-  	$form['instructions'] = array(
-  		'#type' => 'item',
-  		'#value' => t($instructions)
-  	);
-  	
+    $instructions = 'This filter allows you to enter a stock, the position of that stock in the '
+      .'relationship and relationship type and only stocks with a relationship of the type described '
+      .'will be shown. For example, if you want all stocks where Fred is_paternal_parent_of, then '
+      .'you would enter Fred as the value, select is_paternal_parent_of as the Relationship Type '
+      .'and subject as the Fixed Position.';
+    $form['instructions'] = array(
+      '#type' => 'item',
+      '#value' => t($instructions)
+    );
+
     $form['op_val_start'] = array('#value' => '<div class="clear-block">');
 
     // left side
-    
+
     $this->types_form($form, $form_state);
-		$form['type']['#prefix'] = '<div class="views-left-50">';
-		$form['type']['#suffix'] = '</div>';
+    $form['type']['#prefix'] = '<div class="views-left-50">';
+    $form['type']['#suffix'] = '</div>';
 
     $this->show_operator_form($form, $form_state);
     $form['operator']['#prefix'] = '<div class="views-right-50">';
-		$form['operator']['#suffix'] = '</div>';
-		
-		$this->show_value_form($form, $form_state);
-		$form['value']['#prefix'] = '<div class="views-right-50">';
-		$form['value']['#suffix'] = '</div>';
-		
+    $form['operator']['#suffix'] = '</div>';
+
+    $this->show_value_form($form, $form_state);
+    $form['value']['#prefix'] = '<div class="views-right-50">';
+    $form['value']['#suffix'] = '</div>';
+
     // right side
 
 
@@ -114,11 +123,11 @@ class views_handler_filter_stock_relationship_id extends views_handler_filter {
     $form['fixed_position']['#prefix'] = '<div class="views-right-50">';
     $form['fixed_position']['#suffix'] = '</div>';
 
-		
+
     if ($this->can_expose()) {
       $this->show_expose_form($form, $form_state);
     }
-    
+
     $form['op_val_start'] = array('#value' => '</div>');
 
   }
@@ -126,29 +135,30 @@ class views_handler_filter_stock_relationship_id extends views_handler_filter {
   function value_form(&$form, &$form_state) {
     parent::value_form($form, $form_state);
 
-		$form['value'] = array(
-			'#type' => 'textfield',
-			'#title' => ($this->options['label']) ? $this->options['label'] : t('Stock Name'),
-			'#default_value' => $this->value,
-			'#size' => 40,
-		);
-    	
+    $form['value'] = array(
+      '#type' => 'textfield',
+      '#title' => ($this->options['label']) ? $this->options['label'] : t('Stock Name'),
+      '#default_value' => $this->value,
+      '#size' => 40,
+    );
+
   }
 
-  function type_options () {
+  function type_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 stock_relationship)");
+    $result = db_query("SELECT cvt.cvterm_id as type_id, cvt.name FROM {cvterm} cvt WHERE cvt.cvterm_id IN (SELECT type_id FROM {stock_relationship})");
     tripal_db_set_active($previous_db);
 
     $types = array();
-    while ($r = db_fetch_object($result)) { $types[$r->type_id] = $r->name; }
-    
+    while ($r = db_fetch_object($result)) {
+    $types[$r->type_id] = $r->name; }
+
     return $types;
   }
-  
+
   function types_form(&$form, &$form_state) {
-  	
+
     $form['type'] = array(
       '#type' => count($options) < 10 ? 'radios' : 'select',
       '#title' => t('Relationship Types'),
@@ -157,21 +167,21 @@ class views_handler_filter_stock_relationship_id extends views_handler_filter {
     );
 
   }
-  
-  function fixed_position_form (&$form, &$form_state) {
-  
-  	$form['fixed_position'] = array(
-  		'#type' => 'radios',
-  		'#title' => 'Position of Stock to Filter on',
-  		'#description' => t('Where a relationship consists of a subject type object, this field indicates '
-  			.'what position in the relationship remains fixed (is the stock entered as the value).'),
-  		'#options' => array(
-  			'subject_id' => 'Subject',
-  			'object_id' => 'Object'
-  		),
-  		'#default_value' => ($this->options['fixed_position']) ? $this->options['fixed_position'] : 'subject_id',
-  	);
-  	
+
+  function fixed_position_form(&$form, &$form_state) {
+
+    $form['fixed_position'] = array(
+      '#type' => 'radios',
+      '#title' => 'Position of Stock to Filter on',
+      '#description' => t('Where a relationship consists of a subject type object, this field indicates '
+        .'what position in the relationship remains fixed (is the stock entered as the value).'),
+      '#options' => array(
+        'subject_id' => 'Subject',
+        'object_id' => 'Object'
+      ),
+      '#default_value' => ($this->options['fixed_position']) ? $this->options['fixed_position'] : 'subject_id',
+    );
+
   }
 
   function operator_options() {
@@ -247,7 +257,7 @@ class views_handler_filter_stock_relationship_id extends views_handler_filter {
       '#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) {
@@ -285,7 +295,7 @@ class views_handler_filter_stock_relationship_id extends views_handler_filter {
         '#value' => '',
       );
     }
-    
+
     $form['expose']['optional'] = array(
       '#type' => 'checkbox',
       '#title' => t('Optional'),
@@ -293,4 +303,4 @@ class views_handler_filter_stock_relationship_id extends views_handler_filter {
       '#default_value' => $this->options['expose']['optional'],
     );
   }
-}
+}

+ 57 - 51
tripal_stock/views/handlers/views_handler_filter_stockprop_id.inc

@@ -1,6 +1,7 @@
 <?php
 
 /**
+ * @file
  * Allows stocks to be filtered by proeprty values
  *
  * @ingroup tripal_stock
@@ -36,46 +37,50 @@ class views_handler_filter_stockprop_id extends views_handler_filter {
   function options_validate(&$form, &$form_state) {
     parent::options_validate($form, $form_state);
 
-    if (preg_match('/NULL/',$form_state['values']['options']['operator'])) {
+    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');
+        drupal_set_message('The Value (' . $value . ') will be IGNORED when the Operator is set to "Is Present" or Is Absent".', 'warning');
       }
-    } else {
+    }
+    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.'));
+           . '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');
+                 . $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 . ")";
+      $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 stockprop.stock_id FROM stockprop WHERE stockprop.type_id=" . $this->type . ")";
+      $this->query->add_where($this->options['group'], $new_where_sql);
+    }
+    elseif ($this->value) {
+      $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 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.")";
-			$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 stockprop.stock_id FROM stockprop WHERE stockprop.type_id=".$this->type.")";
-			$this->query->add_where($this->options['group'], $new_where_sql);
-		} elseif ($this->value) {
-			$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)");
+    $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; }
+    while ($r = db_fetch_object($result)) {
+    $types[$r->type_id] = $r->name; }
 
     $form['type'] = array(
       '#type' => count($options) < 10 ? 'radios' : 'select',
@@ -90,28 +95,29 @@ class views_handler_filter_stockprop_id extends views_handler_filter {
 
   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(
+
+    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,
-    	);
+    }
+    else {
+      $form['value'] = array(
+        '#type' => 'textfield',
+        '#title' => t('Value'),
+        '#default_value' => $this->value,
+      );
     }
   }
 
@@ -140,7 +146,7 @@ class views_handler_filter_stockprop_id extends views_handler_filter {
         '#type' => 'select',
         '#title' => t('Property Types'),
         '#options' => $this->type_options(),
-        '#default_value' => $this->type,  
+        '#default_value' => $this->type,
       );
 
       if (isset($form[$type]['#title'])) {
@@ -202,16 +208,16 @@ class views_handler_filter_stockprop_id extends views_handler_filter {
       '#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',
-			),
+      '#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',
+      ),
     );
   }
 
@@ -275,7 +281,7 @@ class views_handler_filter_stockprop_id extends views_handler_filter {
         '#value' => '',
       );
     }
-    
+
     $form['expose']['optional'] = array(
       '#type' => 'checkbox',
       '#title' => t('Optional'),
@@ -283,6 +289,6 @@ class views_handler_filter_stockprop_id extends views_handler_filter {
       '#default_value' => $this->options['expose']['optional'],
     );
   }
-  
-  
+
+
 }

+ 6 - 5
tripal_stock/views/misc_tables.views.inc

@@ -1,6 +1,7 @@
 <?php
 
 /**
+ * @file
  * Purpose: Allows the stock module to add fields to other module views
  *
  *   For example, a field counting the number of stocks associted with a given organism would be
@@ -13,14 +14,14 @@
           'handler' => 'views_handler_field_chado_count',
           'table_to_query' => 'stock',
         ),
-      ); 
+      );
  *   @endcode
  *
  * @ingroup tripal_stock_views
  */
 function retrieve_stock_misc_tables_views_data() {
   $data = array();
- 
+
   // Table: Organism--------------------------------------------------------------------------------
   // Calculated Field: Number of stocks (Count -Int)
   // Provides the number of stocks for a given organism
@@ -31,7 +32,7 @@ function retrieve_stock_misc_tables_views_data() {
       'handler' => 'views_handler_field_chado_count',
       'table_to_query' => 'stock',
     ),
-  );  
-  
+  );
+
   return $data;
-}
+}

+ 87 - 85
tripal_stock/views/stock.views.inc

@@ -1,7 +1,8 @@
 <?php
 
 /**
- * Purpose: this function returns the portion of the data array 
+ * @file
+ * Purpose: this function returns the portion of the data array
  *   which describes the stock table, it's fields and any joins between it and other tables
  * @see tripal_stock_views_data() --in tripal_stock.views.inc
  *
@@ -37,59 +38,60 @@ function retrieve_stock_views_data() {
   // 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)){
+  if (is_array($db_url) and array_key_exists('chado', $db_url)) {
      $database = 'chado';
   }
 
 
-	// Basic table definition
+  // Basic table definition
   $data['stock']['table']['group'] = t('Chado Stock');
   $data['stock']['table']['base'] = array(
     'field' => 'stock_id',
     'title' => t('Chado Stock'),
     'help' => t('Chado Stocks are a record of any material upon which an experiment can be done. For example, a DNA sample, an individual or a population.'),
   );
-  if($database){
+  if ($database) {
      $data['stock']['table']['base']['database'] = $database;
   }
 
-	// Define relationships between this table and others
+  // Define relationships between this table and others
   $data['stock']['table']['join'] = array(
     'organism' => array(
       'left_field' => 'organism_id',
       'field' => 'organism_id',
     ),
-  ); 
+  );
 
-	// Table Field Definitions----------------------
+  // Table Field Definitions----------------------
   // Field: feature_id (primary key)
   $data['stock']['stock_id'] = array(
     'title' => 'Stock ID',
     'help' => 'The primary key of a stock',
     'field' => array(
-     	'handler' => 'views_handler_field_numeric',
- 		  'click sortable' => TRUE,
+       'handler' => 'views_handler_field_numeric',
+       'click sortable' => TRUE,
     ),
     'filter' => array(
-     	'handler' => 'views_handler_filter_numeric',
+       'handler' => 'views_handler_filter_numeric',
     ),
     'sort' => array(
-     	'handler' => 'views_handler_sort',
+       'handler' => 'views_handler_sort',
     ),
   );
-  
+
   // Calculated Field: Node ID
   //  use custom field handler to query drupal for the node ID
   //  this is only needed if chado is in a separate database from drupal
-	if ($database){
-  	$data['stock']['stock_nid'] = array(
-    	'title' => 'Node ID',
-    	'help' => 'This is the node ID of this feature. It can be used as a link to the node.',
-    	'field' => array(
+  if ($database) {
+    $data['stock']['stock_nid'] = array(
+      'title' => 'Node ID',
+      'help' => 'This is the node ID of this feature. It can be used as a link to the node.',
+      'field' => array(
        'handler' => 'views_handler_field_computed_stock_nid',
       ),
-  	);
-  } else {
+    );
+  }
+  else {
     // Add relationship between chado_stock and stock
     $data['stock']['stock_nid'] = array(
       'group' => 'Stock',
@@ -126,11 +128,11 @@ function retrieve_stock_views_data() {
       'handler' => 'views_handler_argument_string',
     ),
   );
-  // if joined to the node table add a "Link to Node" option for the field  
+  // if joined to the node table add a "Link to Node" option for the field
   if (!$database) {
     $data['stock']['uniquename']['field']['handler'] = 'views_handler_field_node_optional';
   }
-  
+
   //Field: name (varchar 255)
   $data['stock']['name'] = array(
     'title' => t('Name'),
@@ -149,11 +151,11 @@ function retrieve_stock_views_data() {
       'handler' => 'views_handler_argument_string',
     ),
   );
-  // if joined to the node table add a "Link to Node" option for the field  
+  // if joined to the node table add a "Link to Node" option for the field
   if (!$database) {
     $data['stock']['name']['field']['handler'] = 'views_handler_field_node_optional';
   }
-  
+
   //Field: description (varchar 255)
   $data['stock']['description'] = array(
     'title' => t('Description'),
@@ -184,17 +186,17 @@ function retrieve_stock_views_data() {
     'filter' => array(
        'handler' => 'views_handler_filter_chado_boolean',
        'label' => t('Is Obsolete?'),
-       'type' => 'yes-no',    
+       'type' => 'yes-no',
     ),
     'sort' => array(
       'handler' => 'views_handler_sort',
     ),
   );
 
-	//Calculated Field: stock properties
-	// uses a custom field handler which pulls results from the view
-	// actual query performed in chado_stock_views_views_pre_render	(&$view) -file:tripal_stock.views.inc
-	$data['stock']['properties'] = array(
+  //Calculated Field: stock properties
+  // uses a custom field handler which pulls results from the view
+  // actual query performed in chado_stock_views_views_pre_render  (&$view) -file:tripal_stock.views.inc
+  $data['stock']['properties'] = array(
     'title' => t('Stock Properties'),
     'help' => t('Properties of the current stock.'),
     'field' => array(
@@ -203,34 +205,34 @@ function retrieve_stock_views_data() {
       'handler' => 'views_handler_field_stockprop_by_type',
     ),
     'filter' => array(
-    	'title' => t('Properties'),
-    	'help' => t('Filter by a given property type or value.'),
-    	'handler' => 'views_handler_filter_stockprop_id',
+      'title' => t('Properties'),
+      'help' => t('Filter by a given property type or value.'),
+      'handler' => 'views_handler_filter_stockprop_id',
     ),
     'argument' => array(
-    	'title' => t('Properties'),
-    	'help' => t('Allow a property to be supplied in the path'),
-    	'handler' => 'views_handler_argument_stockprop_id',
+      'title' => t('Properties'),
+      'help' => t('Allow a property to be supplied in the path'),
+      'handler' => 'views_handler_argument_stockprop_id',
+    ),
+  );
+
+  //Calculated Field: stock properties (ALL)
+  // uses a custom field handler which pulls results from the view
+  // actual query performed in chado_stock_views_views_pre_render  (&$view) -file:tripal_stock.views.inc
+  $data['stock']['all_properties'] = array(
+    'title' => t('All Stock Properties'),
+    'help' => t('Properties of the current stock.'),
+    'field' => array(
+      'title' => t('All Properties'),
+      'help' => t('Display all properties associated with a stock.'),
+      'handler' => 'views_handler_field_stockprop_all',
     ),
   );
 
-	//Calculated Field: stock properties (ALL)
-	// uses a custom field handler which pulls results from the view
-	// actual query performed in chado_stock_views_views_pre_render	(&$view) -file:tripal_stock.views.inc
-	$data['stock']['all_properties'] = array(
-  	'title' => t('All Stock Properties'),
-  	'help' => t('Properties of the current stock.'),
-  	'field' => array(
-    	'title' => t('All Properties'),
-    	'help' => t('Display all properties associated with a stock.'),
-    	'handler' => 'views_handler_field_stockprop_all',
-  	),
-	);
-	
-	//Calculated Field: stock relationships
-	// uses a custom field handler which pulls results from the view
-	// actual query performed in chado_stock_views_views_pre_render	(&$view) -file:tripal_stock.views.inc
-	$data['stock']['relationships'] = array(
+  //Calculated Field: stock relationships
+  // uses a custom field handler which pulls results from the view
+  // actual query performed in chado_stock_views_views_pre_render  (&$view) -file:tripal_stock.views.inc
+  $data['stock']['relationships'] = array(
     'title' => t('Stock Relationships'),
     'help' => t('Relationships including the current stock.'),
     'field' => array(
@@ -239,27 +241,27 @@ function retrieve_stock_views_data() {
       'handler' => 'views_handler_field_stockrel_by_type',
     ),
     'filter' => array(
-    	'handler' => 'views_handler_filter_stock_relationship_id'
+      'handler' => 'views_handler_filter_stock_relationship_id'
+    ),
+  );
+
+  //Calculated Field: stock relationships (ALL)
+  // uses a custom field handler which pulls results from the view
+  // actual query performed in chado_stock_views_views_pre_render  (&$view) -file:tripal_stock.views.inc
+  $data['stock']['all_relationships'] = array(
+    'title' => t('All Stock Relationships'),
+    'help' => t('Relationships including the current stock.'),
+    'field' => array(
+      'title' => t('All Relationships'),
+      'help' => t('Display all relationships including the stock.'),
+      'handler' => 'views_handler_field_stockrel_all',
     ),
   );
 
-	//Calculated Field: stock relationships (ALL)
-	// uses a custom field handler which pulls results from the view
-	// actual query performed in chado_stock_views_views_pre_render	(&$view) -file:tripal_stock.views.inc
-	$data['stock']['all_relationships'] = array(
-  	'title' => t('All Stock Relationships'),
-  	'help' => t('Relationships including the current stock.'),
-  	'field' => array(
-    	'title' => t('All Relationships'),
-    	'help' => t('Display all relationships including the stock.'),
-    	'handler' => 'views_handler_field_stockrel_all',
-  	),
-	);
-	
-	//Calculated Field: stock dbxrefs 
-	// uses a custom field handler which pulls results from the view
-	// actual query performed in chado_stock_views_views_pre_render	(&$view) -file:tripal_stock.views.inc
-	$data['stock']['dbxref'] = array(
+  //Calculated Field: stock dbxrefs
+  // uses a custom field handler which pulls results from the view
+  // actual query performed in chado_stock_views_views_pre_render  (&$view) -file:tripal_stock.views.inc
+  $data['stock']['dbxref'] = array(
     'title' => t('Stock Database References'),
     'help' => t('Database References associated with the current stock.'),
     'field' => array(
@@ -268,23 +270,23 @@ function retrieve_stock_views_data() {
       'handler' => 'views_handler_field_stock_dbxref_by_type',
     ),
     'filter' => array(
-    	'title' => t('Database References'),
-    	'help' => t('Filter by a given database reference type and/or value.'),
-    	'handler' => 'views_handler_filter_stock_dbxref_id',
+      'title' => t('Database References'),
+      'help' => t('Filter by a given database reference type and/or value.'),
+      'handler' => 'views_handler_filter_stock_dbxref_id',
     ),
   );
 
-	//Calculated Field: stock dbxrefs (ALL)
-	// uses a custom field handler which pulls results from the view
-	// actual query performed in chado_stock_views_views_pre_render	(&$view) -file:tripal_stock.views.inc
-	$data['stock']['all_dbxref'] = array(
-  	'title' => t('All Stock Database References'),
-  	'help' => t('Database References associated with the current stock.'),
-  	'field' => array(
-    	'title' => t('All Database References'),
-    	'help' => t('Display all database references for the current stock.'),
-    	'handler' => 'views_handler_field_stock_dbxref_all',
-  	),
-	);
+  //Calculated Field: stock dbxrefs (ALL)
+  // uses a custom field handler which pulls results from the view
+  // actual query performed in chado_stock_views_views_pre_render  (&$view) -file:tripal_stock.views.inc
+  $data['stock']['all_dbxref'] = array(
+    'title' => t('All Stock Database References'),
+    'help' => t('Database References associated with the current stock.'),
+    'field' => array(
+      'title' => t('All Database References'),
+      'help' => t('Display all database references for the current stock.'),
+      'handler' => 'views_handler_field_stock_dbxref_all',
+    ),
+  );
   return $data;
-}
+}

+ 28 - 28
tripal_stock/views/template.node_join.views.inc

@@ -5,18 +5,18 @@
  *
  *  - simply replace all XXX with the original chado table you want to join to it's drupal nodes.
  *    (ie: If you want to join features to their drupal nodes then XXX=feature)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
+ *
+ *  NOTE: Creating the table definition file is not enough. You also need to call the
  *        retrieve_XXX_views_data() function from ../tripal_stock.views.inc:tripal_stock_views_data()
  *        by adding the following line:
  *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
+ *        to the function and including the file directly above the function (blow the function
  *        header by adding:
  *           require_once('views/XXX.views.inc');
  *
  *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
+ */
+
 /**
  *  @file
  *  This file defines the data array for a given chado table. This array
@@ -24,31 +24,31 @@
  *  with this module in:
  *  @see tripal_stock.views.inc --in tripal_stock_views_data()
  *
- *  Note: All chado tables are joined to their drupal nodes through the chado_XXX linking table. 
+ *  Note: All chado tables are joined to their drupal nodes through the chado_XXX linking table.
  *        This file simply defines this linking table and joins the three tables together.
  *        No modification of XXX.views.inc is needed.
  *
- *  Documentation on views integration can be found at 
+ *  Documentation on views integration can be found at
  *  http://views2.logrus.com/doc/html/index.html.
  */
- 
+
 /**
- * Purpose: this function returns the portion of the data array 
- *   which describes the chado_XXX drupal table, it's fields and any joins between it 
+ * Purpose: this function returns the portion of the data array
+ *   which describes the chado_XXX drupal table, it's fields and any joins between it
  *   and other tables
  * @see tripal_stock_views_data() --in tripal_stock.views.inc
  *
  * The main need for description of this table to views is to join chado data with drupal nodes
  *
  */
-function retrieve_chado_XXX_views_data () {
-	global $db_url;
+function retrieve_chado_XXX_views_data() {
+  global $db_url;
   $data = array();
-  
+
   // if the chado database is not local to the drupal database
   // then we need to set the database name.  This should always
   // be 'chado'.
-  if(is_array($db_url) and array_key_exists('chado',$db_url)){
+  if (is_array($db_url) and array_key_exists('chado', $db_url)) {
      // return empty data array b/c if chado is external then no join to the nodetable can be made
      return $data;
   }
@@ -57,28 +57,28 @@ function retrieve_chado_XXX_views_data () {
   $data['chado_XXX']['table'] = array(
     'field' => 'nid',
   );
-  
+
   //Relationship Definitions---------------------------------
   // Note: No joins need to be made from $data['XXX']['table']
-  
+
   // Join the chado_XXX table to XXX
   $data['chado_XXX']['table']['join']['XXX'] = array(
-  	'left_field' => 'XXX_id',
-  	'field' => 'XXX_id',
+    'left_field' => 'XXX_id',
+    'field' => 'XXX_id',
   );
-  
+
   // Join the node table to chado_XXX
   $data['node']['table']['join']['chado_XXX'] = array(
-  	'left_field' => 'nid',
-  	'field' => 'nid',
+    'left_field' => 'nid',
+    'field' => 'nid',
   );
-  
+
   // Join the node table to XXX
   $data['node']['table']['join']['XXX'] = array(
-  	'left_table' => 'chado_XXX',
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );  
+    'left_table' => 'chado_XXX',
+    'left_field' => 'nid',
+    'field' => 'nid',
+  );
 
-	return $data;
-}
+  return $data;
+}

+ 27 - 27
tripal_stock/views/template.table_defn.views.inc

@@ -5,7 +5,7 @@
  *
  *   - Every instance of XXX should be replaced with the name of your table
  *   - If this is a base table (you want a view where every row is a row from this table)
- *     then change $data['XXX']['table'] to $data['XXX']['table']['base'] 
+ *     then change $data['XXX']['table'] to $data['XXX']['table']['base']
  *     and $data['XXX']['table']['database'] to $data['XXX']['table']['base']['database']
  *   - Relationships between this table and others: YYY is the table you are trying to join to this
  *     one. You want to join a table to this one if this table contains a foreign key to the other
@@ -15,18 +15,18 @@
  *   - 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 
+ *
+ *  NOTE: Creating the table definition file is not enough. You also need to call the
  *        retrieve_XXX_views_data() function from ../tripal_stock.views.inc:tripal_stock_views_data()
  *        by adding the following line:
  *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
+ *        to the function and including the file directly above the function (blow the function
  *        header by adding:
  *           require_once('views/XXX.views.inc');
  *
  *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
+ */
+
 /**
  *  @file
  *  This file defines the data array for a given chado table. This array
@@ -34,12 +34,12 @@
  *  with this module in:
  *  @see tripal_stock.views.inc --in tripal_stock_views_data()
  *
- *  Documentation on views integration can be found at 
+ *  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 
+ * Purpose: this function returns the portion of the data array
  *   which describes the XXX table, it's fields and any joins between it and other tables
  * @see tripal_stock_views_data() --in tripal_stock.views.inc
  *
@@ -55,23 +55,23 @@
   // 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)){
+  if (is_array($db_url) and array_key_exists('chado', $db_url)) {
     $database = 'chado';
   }
-   
+
   //Basic table definition-----------------------------------
   $data['XXX']['table']['group'] = t('Chado XXX');
-  
+
   $data['XXX']['table'] = array(
     'field' => 'primary_id',
     'title' => t('Chado XXX'),
     'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
   );
-  if($database){
+  if ($database) {
      $data['XXX']['table']['database'] = $database;
   }
 
-  
+
   //Relationship Definitions---------------------------------
   //Join: YYY => XXX
   // Notice that this relationship tells the primary table to show it's fields to the
@@ -80,16 +80,16 @@
   $data['XXX']['table']['join']['YYY'] = array(
     'left_field' => 'foreign key in YYY table',
     'field' => 'primary key in XXX table',
-  );  
-  
+  );
+
   //Join: XXX => XY => YYY
   // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
+  // in the appropriate files (ie: for feature => library
   // describe in both feature.views.inc and library.views.inc)
   $data['XXX']['table']['join']['XY'] = array(
     'left_field' => 'matching XXX key in the XY table',
     'field' => 'primary key in XXX table',
-  );  
+  );
   $data['XXX']['table']['join']['YYY'] = array(
     'left_table' => 'XY',
     'left_field' => 'matching XXX key in the XY table',
@@ -99,9 +99,9 @@
     'left_field' => 'primary key in YYY table',
     'field' => 'matching YYY key in the XY table',
   );
-   
+
   //Table Field Definitions----------------------------------
-      
+
   //Field: XXX_id (primary key)
   $data['XXX']['field_name'] = array(
     'title' => t('XXX Primary Key'),
@@ -123,7 +123,7 @@
    * Remove this section when done
    */
 
-  //Field: plain_text_field (chado datatype)   
+  //Field: plain_text_field (chado datatype)
   $data['XXX']['plain_text_field'] = array(
     'title' => t('Human-Readable Name'),
     'help' => t('Description of this field.'),
@@ -142,7 +142,7 @@
     ),
   );
 
-  //Field: numeric_field (chado datatype)   
+  //Field: numeric_field (chado datatype)
   $data['XXX']['numeric_field'] = array(
     'title' => t('Human-Readable Name'),
     'help' => t('Description of this field.'),
@@ -158,7 +158,7 @@
     ),
   );
 
-  //Field: boolean_field (chado datatype)   
+  //Field: boolean_field (chado datatype)
   $data['XXX']['boolean_field'] = array(
     'title' => t('Human-Readable Name'),
     'help' => t('Description of this field.'),
@@ -174,7 +174,7 @@
     ),
   );
 
-  //Field: unix_timestamp (chado datatype)   
+  //Field: unix_timestamp (chado datatype)
   $data['XXX']['unix_timestamp'] = array(
     'title' => t('Human-Readable Name'),
     'help' => t('Description of this field.'),
@@ -190,7 +190,7 @@
     ),
   );
 
-  //Field: human_readable_date (chado datatype)   
+  //Field: human_readable_date (chado datatype)
   $data['XXX']['human_readable_date'] = array(
     'title' => t('Human-Readable Name'),
     'help' => t('Description of this field.'),
@@ -202,10 +202,10 @@
       'handler' => 'views_handler_sort_date',
     ),
   );
-   
+
    /*
     * End of Example Field definitions
     */
-    
+
   return $data;
-}
+}