Forráskód Böngészése

Fixed merge conflicts

Stephen Ficklin 11 éve
szülő
commit
38d6b34898

+ 4 - 4
tripal_analysis/api/tripal_analysis.DEPRECATED.inc

@@ -95,9 +95,9 @@ function tripal_analysis_delete_property($analysis_id, $property, $cv_name = 'tr
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_analysis().
+ * This function has been replaced by analysis_retrieve().
  *
- * @see chado_get_analysis().
+ * @see analysis_retrieve().
  */
 function tripal_analysis_get_node($analysis_id) {
 
@@ -107,9 +107,9 @@ function tripal_analysis_get_node($analysis_id) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_analysis_get_node',
-      '%new_function' => 'chado_get_analysis'
+      '%new_function' => 'analysis_retrieve'
     )
   );
 
-  return chado_get_analysis(array('analysis_id' => $analysis_id));
+  return analysis_retrieve(array('analysis_id' => $analysis_id));
 }

+ 91 - 10
tripal_analysis/api/tripal_analysis.api.inc

@@ -46,28 +46,109 @@ function tripal_analysis_unregister_child($modulename) {
 }
 
 /**
- * Get the analysis node same as node_load would but allowing different arguements
+ * Retrieves an chado analysis variable
  *
  * @param $itentifier
  *   an array with the key stating what the identifier is. Supported keys (only on of the
  *   following unique keys is required):
  *    - analysis_id: the chado analysis.analysis_id primary key
  *    - nid: the drupal node.nid primary key
+ *   There are also some specially handled keys. They are:
+ *    - property: An array/object describing the property to select records for. It
+ *      should at least have either a type_name (if unique across cvs) or type_id. Other
+ *      supported keys include: cv_id/cv_name (of the type), value and rank
+ * @param $options
+ *   An array of options. Supported keys include:
+ *     - Any keys supported by chado_generate_var(). See that function definition for
+ *       additional details.
+ *
+ * NOTE: the $identifier parameter can really be any array similar to $values passed into
+ *   chado_select_record(). It should fully specify the stock record to be returned.
+ *
  * @return
  *   the analysis node matching the passed in identifier
+ *
+ * @ingroup tripal_analysis_api
  */
-function chado_get_analysis($identifier) {
+function analysis_retrieve($identifier, $options) {
 
-  // If the analysis_id is passed in then use it to get the nid
-  if (isset($identifier['analysis_id'])) {
-    $identifier['nid'] = chado_get_nid_from_id('analysis', $identifier['analysis_id']);
+  // Set Defaults
+  if (!isset($options['include_fk'])) {
+    // Tells chado_generate_var not to follow any foreign keys
+    $options['include_fk'] = array();
   }
 
-  // Using the nid, get the node
-  if (isset($identifier['nid'])) {
-    return node_load($identifier['nid']);
+  // Error Checking of parameters
+  if (!is_array($identifiers)) {
+    tripal_report_error(
+      'tripal_stock_api',
+      TRIPAL_ERROR,
+      "chado_get_stock: The identifier passed in is expected to be an array with the key
+        matching a column name in the stock table (ie: stock_id or name). You passed in %identifier.",
+      array(
+        '%identifier'=> print_r($identifiers, TRUE)
+      )
+    );
   }
+  elseif (empty($identifiers)) {
+    tripal_report_error(
+      'tripal_stock_api',
+      TRIPAL_ERROR,
+      "chado_get_stock: You did not pass in anything to identify the stock you want. The identifier
+        is expected to be an array with the key matching a column name in the stock table
+        (ie: stock_id or name). You passed in %identifier.",
+      array(
+        '%identifier'=> print_r($identifiers, TRUE)
+      )
+    );
+  }
+
+  // If one of the identifiers is property then use chado_get_record_with_property()
+  if (isset($identifiers['property'])) {
+    $property = $identifiers['property'];
+    unset($identifiers['property']);
+    $analysis = chado_get_record_with_property('analysis', $property, $identifiers, $options);
+  }
+
+  // Else we have a simple case and we can just use chado_generate_var to get the analysis
+  else {
 
-  // If there is neither the nid or analysis_id then return FALSE to indicate we failed
-  return FALSE;
+    // Try to get the analysis
+    $analysis = chado_generate_var(
+      'analysis',
+      $identifiers,
+      $options
+    );
+  }
+
+  // Ensure the analysis is singular. If it's an array then it is not singular
+  if (is_array($analysis)) {
+    tripal_report_error(
+      'tripal_analysis_api',
+      TRIPAL_ERROR,
+      "analysis_retrieve: The identifiers you passed in were not unique. You passed in %identifier.",
+      array(
+        '%identifier'=> print_r($identifiers, TRUE)
+      )
+    );
+  }
+
+  // Report an error if $analysis is FALSE since then chado_generate_var has failed
+  elseif ($analysis === FALSE) {
+    tripal_report_error(
+      'tripal_analysis_api',
+      TRIPAL_ERROR,
+      "analysis_retrieve: chado_generate_var() failed to return a analysis based on the identifiers
+        you passed in. You should check that your identifiers are correct, as well as, look
+        for a chado_generate_var error for additional clues. You passed in %identifier.",
+      array(
+        '%identifier'=> print_r($identifiers, TRUE)
+      )
+    );
+  }
+
+  // Else, as far we know, everything is fine so give them their analysis :)
+  else {
+    return $analysis;
+  }
 }

+ 4 - 4
tripal_contact/api/tripal_contact.DEPRECATED.inc

@@ -95,9 +95,9 @@ function tripal_contact_delete_property($contact_id, $property) {
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_insert_contact().
+ * This function has been replaced by contact_insert().
  *
- * @see chado_insert_contact().
+ * @see contact_insert().
  */
 function tripal_contact_add_contact($name, $description, $type, $properties) {
 
@@ -107,11 +107,11 @@ function tripal_contact_add_contact($name, $description, $type, $properties) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_contact_add_contact',
-      '%new_function' => 'chado_insert_contact'
+      '%new_function' => 'contact_insert'
     )
   );
 
-  return chado_insert_contact(array(
+  return contact_insert(array(
     'name' => $name,
     'description' => $description,
     'type_name' => $type,

+ 1 - 1
tripal_contact/api/tripal_contact.api.inc

@@ -33,7 +33,7 @@
  *
  * @ingroup tripal_contact_api
  */
-function chado_insert_contact($values) {
+function contact_insert($values) {
 
   $name = $values['name'];
   $description = $values['description'];

+ 369 - 61
tripal_core/api/tripal_core.chado_variables.api.inc

@@ -16,9 +16,9 @@
  * drupal_eval() which suppresses syntax errors and throws watchdog entries of type php. There are
  * also watchdog entries of type tripal_core stating the exact criteria evaluated. Criteria can
  * contain the following tokens:
- *   - >field_name<
+ *   - <field_name>
  *       Replaced by the name of the field to be excluded
- *   - &gt;field_value&lt;
+ *   - <field_value>
  *       Replaced by the value of the field in the current record
  * Also keep in mind that if your criteria doesn't contain the &gt;field_value&lt;  token then it will be
  * evaluated before the query is executed and if the field is excluded it won't be included in the
@@ -30,7 +30,7 @@
  * @ingroup tripal_chado_query_api
  */
 function tripal_core_exclude_type_by_default() {
-  return array('text' => 'strlen("&gt;field_value&lt; ") > 100');
+  return array('text' => 'strlen("<field_value> ") > 250');
 }
 
 /**
@@ -45,21 +45,21 @@ function tripal_core_exclude_type_by_default() {
  * drupal_eval() which suppresses syntax errors and throws watchdog entries of type php. There are
  * also watchdog entries of type tripal_core stating the exact criteria evaluated. Criteria can
  * contain the following tokens:
- *   - &gt;field_name&lt;
+ *   - <field_name>
  *       Replaced by the name of the field to be excluded
- *   - &gt;field_value&lt;
+ *   - <field_value>
  *       Replaced by the value of the field in the current record
- * Also keep in mind that if your criteria doesn't contain the &gt;field_value&lt;  token then it will be
+ * Also keep in mind that if your criteria doesn't contain the <field_value>  token then it will be
  * evaluated before the query is executed and if the field is excluded it won't be included in the
  * query.
  *
  * @return
- *   An array of type => criteria where the type is excluded if the criteria evaluates to TRUE
+ *   An array of field => criteria where the type is excluded if the criteria evaluates to TRUE
  *
  * @ingroup tripal_chado_query_api
  */
 function tripal_core_exclude_field_from_feature_by_default() {
-  return array();
+  return array('residues' => 'TRUE');
 }
 
 /**
@@ -161,7 +161,7 @@ function chado_generate_var($table, $values, $base_options = array()) {
   if (array_key_exists('return_array', $base_options)) {
     $return_array = 1;
   }
-  $include_fk = 0;
+  $include_fk = FALSE;
   if (array_key_exists('include_fk', $base_options)) {
     $include_fk = $base_options['include_fk'];
   }
@@ -185,7 +185,10 @@ function chado_generate_var($table, $values, $base_options = array()) {
   $table_columns = array_keys($table_desc['fields']);
 
   // Expandable fields without value needed for criteria--------------------------------------------
+  // Add in the default expandable arrays
+  // These are used for later expanding fields, tables, foreign keys and nodes
   $all->expandable_fields = array();
+  $all->expandable_foreign_keys = array();
   if (array_key_exists('referring_tables', $table_desc) and $table_desc['referring_tables']) {
     $all->expandable_tables = $table_desc['referring_tables'];
   }
@@ -194,19 +197,40 @@ function chado_generate_var($table, $values, $base_options = array()) {
   }
   $all->expandable_nodes = array();
 
-  /*
+
   // Get fields to be removed by name.................................
+  // This gets all implementations of hook_exclude_field_from_<table>_by_default()
+  // where <table> is the current table a variable is being created for.
+
+  // This allows modules to specify that some fields should be excluded by default
+  // For example, tripal core provides a tripal_core_exclude_field_from_feature_by_default()
+  // which says that we usually don't want to include the residues field by default since
+  // it can be very large and cause performance issues.
+
+  // If a field is excluded by default it can always be expanded at a later point by calling
+  // chado_expand_var($chado_var, 'field', <field name as shown in expandable_fields array>);
+
+  // First get an array of all the fields to be removed for the current table
+  // module_invoke_all() is drupal's way of invoking all implementations of the specified
+  // hook and merging all of the results.
+
+  // $fields_to_remove should be an array with the keys matching field names
+  // and the values being strings to be executed using php_eval() to determine whether
+  // to exclude the field (evaluates to TRUE) or not (evaluates to FALSE)
   $fields_to_remove = module_invoke_all('exclude_field_from_' . $table . '_by_default');
+
+  // Now, for each field to be removed
   foreach ($fields_to_remove as $field_name => $criteria) {
-    //replace &gt;field_name&lt;  with the current field name &
-    $criteria = preg_replace('/&gt;field_name&lt; /', addslashes($field_name), $criteria);
+
+    //replace <field_name> with the current field name
+    $criteria = preg_replace('/<field_name> /', addslashes($field_name), $criteria);
     // if field_value needed we can't deal with this field yet
-    if (preg_match('/&gt;field_value&lt; /', $criteria)) {
+    if (preg_match('/<field_value> /', $criteria)) {
       break;
     }
 
     //if criteria then remove from query
-    // @coder-ignore: only module designers can populate $criteria -not security risk
+    // @coder-ignore: only module designers can populate $criteria -not a security risk
     $success = php_eval('<?php return ' . $criteria . '; ?>');
     if ($success) {
       unset($table_columns[array_search($field_name, $table_columns)]);
@@ -215,29 +239,54 @@ function chado_generate_var($table, $values, $base_options = array()) {
     }
   }
 
-  //Get fields to be removed by type................................
+  // Get fields to be removed by type................................
+  // This gets all implementations of hook_exclude_type_by_default().
+
+  // This allows modules to specify that some types of fields should be excluded by default
+  // For example, tripal core provides a tripal_core_exclude_type_by_default() which says
+  // that text fields are often very large and if they are longer than 250 characters then
+  // we want to exclude them by default
+
+  // If a field is excluded by default it can always be expanded at a later point by calling
+  // chado_expand_var($chado_var, 'field', <field name as shown in expandable_fields array>);
+
+  // First get an array of all the types of fields to be removed for the current table
+  // module_invoke_all() is drupal's way of invoking all implementations of the specified
+  // hook and merging all of the results.
+
+  // $types_to_remove should be an array with the keys matching field names
+  // and the values being strings to be executed using php_eval() to determine whether
+  // to exclude the field (evaluates to TRUE) or not (evaluates to FALSE)
+  // (ie: array('text' => 'strlen("<field_value> ") > 100');
   $types_to_remove = module_invoke_all('exclude_type_by_default');
+
+  // Get a list of all the types of fields
+  // the key is the type of field and the value is an array of fields of this type
   $field_types = array();
   foreach ($table_desc['fields'] as $field_name => $field_array) {
     $field_types[$field_array['type']][] = $field_name;
   }
+
+  // We want to use the types to remove in conjunction with our table field descriptions
+  // to determine which fields might need to be removed
   foreach ($types_to_remove as $field_type => $criteria) {
+
     // if there are fields of that type to remove
-    if (is_array($field_types[$field_type])) {
-      //replace &gt;field_name&lt;  with the current field name &
-      $criteria = preg_replace('/&gt;field_name&lt; /', addslashes($field_name), $criteria);
+    if (isset($field_types[$field_type])) {
+
+      // Do any processing needed on the php criteria
+      //replace <field_name>  with the current field name
+      $criteria = preg_replace('/<field_name> /', addslashes($field_name), $criteria);
       foreach ($field_types[$field_type] as $field_name) {
         // if field_value needed we can't deal with this field yet
-        if (preg_match('/&gt;field_value&lt; /', $criteria)) {
+        if (preg_match('/<field_value>/', $criteria)) {
           $fields_to_remove[$field_name] = $criteria;
           continue;
         }
-        // if field_value needed we can't deal with this field yet
-        if (preg_match('/&gt;field_value&lt; /', $criteria)) {
-          break;
-        }
-        //if criteria then remove from query
-        // @coder-ignore: only module designers can populate $criteria -not security risk
+
+        // if criteria then remove from query
+        // (as long as <field_value> is not needed for the criteria to be evaluated)
+        // @coder-ignore: only module designers can populate $criteria -not a security risk
         $success = php_eval('<?php return ' . $criteria . '; ?>');
         if ($success) {
           unset($table_columns[array_search($field_name, $table_columns)]);
@@ -246,7 +295,7 @@ function chado_generate_var($table, $values, $base_options = array()) {
       } //end of foreach field of that type
     }
   } //end of foreach type to be removed
-*/
+
   // get the values for the record in the current table---------------------------------------------
   $results = chado_select_record($table, $table_columns, $values, $base_options);
 
@@ -254,6 +303,7 @@ function chado_generate_var($table, $values, $base_options = array()) {
     foreach ($results as $key => $object) {
       // Add empty expandable_x arrays
       $object->expandable_fields = $all->expandable_fields;
+      $object->expandable_foreign_keys = $all->expandable_foreign_keys;
       $object->expandable_tables = $all->expandable_tables;
       $object->expandable_nodes = $all->expandable_nodes;
       // add curent table
@@ -277,23 +327,39 @@ function chado_generate_var($table, $values, $base_options = array()) {
       }
 
       // remove any fields where criteria needs to be evalulated---------------------------------------
-/*      foreach ($fields_to_remove as $field_name => $criteria) {
+      // The fields to be removed can be populated by implementing either
+      // hook_exclude_field_from_<table>_by_default() where <table> is the current table
+      // OR hook_exclude_type_by_default() where there are fields of the specified type in the current table
+      // It only reaches this point if the criteria specified for whether or not to
+      // exclude the field includes <field_value> which means it has to be evaluated after
+      // the query has been executed
+      foreach ($fields_to_remove as $field_name => $criteria) {
+
+        // If the field is an object then we don't support exclusion of it
+        // For example, if the field is a foreign key
         if (!isset($object->{$field_name})) {
           break;
         }
-        $criteria = preg_replace('/&gt;field_value&lt; /', addslashes($object->{$field_name}), $criteria);
+
+        // replace <field_value> with the actual value of the field from the query
+        $criteria = preg_replace('/<field_value>/', addslashes($object->{$field_name}), $criteria);
+
+        // evaluate the criteria, if TRUE is returned then exclude the field
+        // excluded fields can be expanded later by calling
+        // chado_expand_var($var, 'field', <field name as shown in expandable_fields array>);
         $success = php_eval('<?php return ' . $criteria . '; ?>');
         if ($success) {
           unset($object->{$field_name});
           $object->expandable_fields[] = $table . '.' . $field_name;
         }
       }
-*/
+
       // recursively follow foreign key relationships nesting objects as we go------------------------
       if ($table_desc['foreign keys']) {
         foreach ($table_desc['foreign keys'] as $foreign_key_array) {
           $foreign_table = $foreign_key_array['table'];
           foreach ($foreign_key_array['columns'] as $foreign_key => $primary_key) {
+
             // Note: Foreign key is the field in the current table whereas primary_key is the field in
             // the table referenced by the foreign key
             //Dont do anything if the foreign key is empty
@@ -301,17 +367,20 @@ function chado_generate_var($table, $values, $base_options = array()) {
               continue;
             }
 
-            if ($include_fk) {
+            if (is_array($include_fk)) {
               // don't recurse if the callee has supplied an $fk_include list and this
               // FK table is not in the list.
               if (is_array($include_fk) and !array_key_exists($foreign_key, $include_fk)) {
-                continue;
-              }
-              // if we have the option but it is not an array then we don't recurse any furutehr
-              if (!is_array($include_fk)) {
+                $object->expandable_foreign_keys[] = $table . '.' . $foreign_key . ' => ' . $foreign_table;
                 continue;
               }
             }
+            // if we have the option but it is not an array then we don't recurse any furutehr
+            if ($include_fk === TRUE) {
+              $object->expandable_foreign_keys[] = $table . '.' . $foreign_key . ' => ' . $foreign_table;
+              continue;
+            }
+
             // get the record from the foreign table
             $foreign_values = array($primary_key => $object->{$foreign_key});
             $options = array();
@@ -332,6 +401,14 @@ function chado_generate_var($table, $values, $base_options = array()) {
               );
               unset($object->{$foreign_key}->expandable_fields);
             }
+            if (property_exists($object->{$foreign_key}, 'expandable_foreign_keys') and
+                is_array($object->{$foreign_key}->expandable_foreign_keys)) {
+              $object->expandable_foreign_keys = array_merge(
+                $object->expandable_foreign_keys,
+                $object->{$foreign_key}->expandable_foreign_keys
+              );
+              unset($object->{$foreign_key}->expandable_foreign_keys);
+            }
             if (property_exists($object->{$foreign_key}, 'expandable_tables') and
                 is_array($object->{$foreign_key}->expandable_tables)) {
               $object->expandable_tables = array_merge(
@@ -484,20 +561,33 @@ function chado_expand_var($object, $type, $to_expand, $table_options = array())
         $tablename = $matches[1];
         $fieldname = $matches[2];
         $table_desc = chado_get_schema($tablename);
-        $values = array();
-        foreach ($table_desc['primary key'] as $key) {
-          if(property_exists($object, $key)) {
-            $values[$key] = $object->{$key};
-          }
-        }
+
+        // BASE CASE: the field is from the current table
         if ($base_table == $tablename) {
-          //get the field
+          // Use the table description to fully describe the current object
+          // in a $values array to be used to select the field from chado
+          $values = array();
+          foreach ($table_desc['primary key'] as $key) {
+            if(property_exists($object, $key)) {
+              $values[$key] = $object->{$key};
+            }
+          }
+
+          // Retrieve the field from Chado
           $results = chado_select_record($tablename, array($fieldname), $values);
-          $object->{$fieldname} = $results[0]->{$fieldname};
-          $object->expanded = $to_expand;
+
+          // Check that the field was retrieved correctly
+          if (isset($results[0])) {
+            $object->{$fieldname} = $results[0]->{$fieldname};
+            $object->expanded = $to_expand;
+          }
+          // If it wasn't retrieved correctly, we need to warn the administrator
+
         }
+        // RECURSIVE CASE: the field is in a nested object
         else {
-          //We need to recurse -the field is in a nested object
+          // We want to look at each field and if it's an object then we want to
+          // attempt to expand the field in it via recursion
           foreach ((array) $object as $field_name => $field_value) {
             if (is_object($field_value)) {
               $object->{$field_name} = chado_expand_var(
@@ -509,22 +599,110 @@ function chado_expand_var($object, $type, $to_expand, $table_options = array())
           } //end of for each field in the current object
         }
       }
+      // Otherwise we weren't able to extract the parts of the field to expand
+      // Thus we will warn the administrator
       else {
         tripal_report_error('tripal_core', TRIPAL_ERROR,
           'chado_expand_var: Field (%field) not in the right format. " .
-          "It should be <tablename>.<fieldname>');
+          "It should be <tablename>.<fieldname>', array('%field' => $to_expand));
       }
       break;
+
+    case "foreign_key": //--------------------------------------------------------------------------
+      if (preg_match('/(\w+)\.(\w+) => (\w+)/', $to_expand, $matches)) {
+        $table_name = $matches[1];
+        $field_name = $matches[2];
+        $foreign_table = $matches[3];
+        $table_desc = chado_get_schema($table_name);
+
+        // BASE CASE: The foreign key is from the current table
+        if ($base_table == $table_name) {
+
+          // Get the value of the foreign key from the object
+          $field_value = $object->{$field_name};
+
+          // Get the name of the field in the foreign table using the table description
+          // For example, with the feature.type_id => cvterm.cvterm_id we need cvterm_id
+          $foreign_field_name = FALSE;
+          foreach ($table_desc['foreign keys'][$foreign_table]['columns'] as $left => $right) {
+            if ($right == $field_name) {
+              $foreign_field_name = $left;
+            }
+          }
+
+          // Check that we were able to determine the field name in the foreign table
+          if ($foreign_field_name) {
+
+            // Generate a chado variable of the foreign key
+            // For example, if the foreign key to expand is feature.type_id
+            // then we want to generate a chado cvterm variable that matches the feature.type_id
+            $foreign_var = chado_generate_var(
+              $foreign_table, // thus in the example above, generate a cvterm var
+              array($foreign_field_name => $field_value), // where the cvterm.cvterm_id = feature.type_id value
+              $table_options //pass in the same options given to this function
+            );
+
+            // Check that the foreign object was returned
+            if ($foreign_var) {
+
+              // It was so now we can add this chado variable to our current object
+              // in place of the key value
+              $object->{$field_name} = $foreign_var;
+              $object->expanded = $to_expand;
+
+            }
+            // Otherwise we weren't able to expand the foreign key
+            else {
+              tripal_report_error('tripal_core', TRIPAL_ERROR,
+                'chado_expand_var: unable to retrieve the object desribed by the foreign key
+                while trying to expand %fk.',
+                array('%fk' => $to_expand));
+            }
+          }
+          // Else we were unable to determine the field name in the foreign table
+          else {
+            tripal_report_error('tripal_core', TRIPAL_ERROR,
+              'chado_expand_var: unable to determine the field name in the table the foreign
+              key points to while trying to expand %fk.',
+              array('%fk' => $to_expand));
+          }
+
+        }
+        // RECURSIVE CASE: Check any nested objects
+        else {
+
+          foreach ((array) $object as $field_name => $field_value) {
+            if (is_object($field_value)) {
+              $object->{$field_name} = chado_expand_var(
+              $field_value,
+              'foreign_key',
+              $to_expand
+              );
+            }
+          } //end of for each field in the current object
+
+        }
+      }
+      // Otherwise we weren't able to extract the parts of the foreign key to expand
+      // Thus we will warn the administrator
+      else {
+        tripal_report_error('tripal_core', TRIPAL_ERROR,
+          'chado_expand_var: foreign_key (%fk) not in the right format. " .
+          "It should be <tablename>.<fieldname>', array('%fk' => $to_expand));
+      }
+      break;
+
     case "table": //--------------------------------------------------------------------------------
       $foreign_table = $to_expand;
 
-      // don't expand the table it already is expanded
+      // RECURSIVE BASE CASE: don't expand the table it already is expanded
       if (array_key_exists($foreign_table, $object)) {
         return $object;
       }
       $foreign_table_desc = chado_get_schema($foreign_table);
 
-      // If it's connected to the base table via a FK constraint
+      // BASE CASE: If it's connected to the base table via a FK constraint
+      // then we have all the information needed to expand it now
       if (array_key_exists($base_table, $foreign_table_desc['foreign keys'])) {
         foreach ($foreign_table_desc['foreign keys'][$base_table]['columns'] as $left => $right) {
           // if the FK value in the base table is not there then we can't expand it, so just skip it.
@@ -574,11 +752,16 @@ function chado_expand_var($object, $type, $to_expand, $table_options = array())
           }
         }
       }
-      // if the foreign table is not connected to the base table through a FK constraint
+      // RECURSIVE CASE: if the table is not connected directly to the current base table
+      // through a foreign key relationship, then maybe it has a relationship to
+      // one of the nested objects.
       else {
+
         // We need to recurse -the table has a relationship to one of the nested objects
+        // We assume it's a nested object if the value of the field is an object
         $did_expansion = 0;
         foreach ((array) $object as $field_name => $field_value) {
+
           // if we have a nested object ->expand the table in it
           // check to see if the $field_name is a valid chado table, we don't need
           // to call chado_expand_var on fields that aren't tables
@@ -588,6 +771,7 @@ function chado_expand_var($object, $type, $to_expand, $table_options = array())
             $object->{$field_name} = chado_expand_var($field_value, 'table', $foreign_table);
           }
         }
+
         // if we did not expand this table we should return a message that the foreign table
         // could not be expanded
         if (!$did_expansion) {
@@ -598,11 +782,19 @@ function chado_expand_var($object, $type, $to_expand, $table_options = array())
         }
       }
       break;
+
     case "node": //---------------------------------------------------------------------------------
-      //if the node to be expanded is for our base table, then just expand it
+
+      // BASE CASE: if the node to be expanded is for our base table, then just expand it
       if ($object->tablename == $to_expand) {
+
+        // Load the node based on the current objects nid (node primary key)
         $node = node_load($object->nid);
+
+        // If we have successfully loaded the node...
         if ($node) {
+
+          // Move expandable arrays from the object into the node
           $object->expanded = $to_expand;
           $node->expandable_fields = $object->expandable_fields;
           unset($object->expandable_fields);
@@ -610,16 +802,29 @@ function chado_expand_var($object, $type, $to_expand, $table_options = array())
           unset($object->expandable_tables);
           $node->expandable_nodes = $object->expandable_nodes;
           unset($object->expandable_nodes);
+
+          // The node becomes the base object with the obejct added to it.
+          // For example, we may start with a feature object with a name, uniquename , type, etc.
+          // After expanding we will return the node and at $node->feature you will find the original object
           $node->{$base_table} = $object;
           $object = $node;
+
         }
+        // Else we were unable to load the node
         else {
+
+          // Warn the administrator
           tripal_report_error('tripal_core', TRIPAL_ERROR, 'chado_expand_var: No node matches the nid (%nid) supplied.',
             array('%nid' => $object->nid));
         } //end of if node
+
       }
+      // RECURSIVE CASE: check to see if the node to be expanded associates with a
+      // chado table within one of the nested objects.
       else {
-        //We need to recurse -the node to expand is one of the nested objects
+
+        // We need to recurse -the node to expand is one of the nested objects
+        // We assume it's a nested object if the field value is an object
         foreach ((array) $object as $field_name => $field_value) {
           if (is_object($field_value)) {
             $object->{$field_name} = chado_expand_var(
@@ -631,41 +836,144 @@ function chado_expand_var($object, $type, $to_expand, $table_options = array())
         } //end of for each field in the current object
       }
       break;
+
+    // The $type to be expanded is not yet supported
     default:
       tripal_report_error('tripal_core', TRIPAL_ERROR, 'chado_expand_var: Unrecognized type (%type). Should be one of "field", "table", "node".',
         array('%type' => $type));
       return FALSE;
   }
 
-  // move extended array downwards
+  // Move expandable arrays downwards -------------------------------
+  // If the type was either table or foreign key then a new chado variable was generated
+  // this variable will have it's own expandable array's which need to be moved down
+  // and merged with the base objects expandable arrays
+
+  // Thus, check all nested objects for expandable arrays
+  // and if they have them, move them downwards
+  foreach ( (array)$object as $field_name => $field_value) {
+    if (is_object($field_value)) {
+
+      // The current nested object has expandable arrays
+      if (isset($field_value->expandable_fields)) {
+
+        // Move expandable fields downwards
+        if (isset($field_value->expandable_fields) and is_array($field_value->expandable_fields)) {
+
+          // If the current object has it's own expandable fields then merge them
+          if (isset($object->expandable_fields)) {
+            $object->expandable_fields = array_merge(
+              $object->expandable_fields,
+              $object->{$field_name}->expandable_fields
+            );
+            unset($object->{$field_name}->expandable_fields);
+
+          }
+          // Otherwise, just move the expandable fields downwards
+          else {
+            $object->expandable_fields = $object->{$field_name}->expandable_fields;
+            unset($object->{$field_name}->expandable_fields);
+          }
+
+        }
+
+        // Move expandable foreign keys downwards
+        if (isset($field_value->expandable_foreign_keys) and is_array($field_value->expandable_foreign_keys)) {
+
+          // If the current object has it's own expandable foreign keys then merge them
+          if (isset($object->expandable_foreign_keys)) {
+            $object->expandable_foreign_keys = array_merge(
+              $object->expandable_foreign_keys,
+              $object->{$field_name}->expandable_foreign_keys
+            );
+            unset($object->{$field_name}->expandable_foreign_keys);
+
+          }
+          // Otherwise, just move the expandable foreign keys downwards
+          else {
+            $object->expandable_foreign_keys = $object->{$field_name}->expandable_foreign_keys;
+            unset($object->{$field_name}->expandable_foreign_keys);
+          }
+        }
+
+        // Move expandable tables downwards
+        if (isset($field_value->expandable_tables) and is_array($field_value->expandable_tables)) {
+
+          // If the current object has it's own expandable tables then merge them
+          if (isset($object->expandable_tables)) {
+            $object->expandable_tables = array_merge(
+              $object->expandable_tables,
+              $object->{$field_name}->expandable_tables
+            );
+            unset($object->{$field_name}->expandable_tables);
+
+          }
+          // Otherwise, just move the expandable tables downwards
+          else {
+            $object->expandable_tables = $object->{$field_name}->expandable_tables;
+            unset($object->{$field_name}->expandable_tables);
+          }
+        }
+
+        // Move expandable nodes downwards
+        if (isset($field_value->expandable_nodes) and is_array($field_value->expandable_nodes)) {
+
+          // If the current object has it's own expandable tables then merge them
+          if (isset($object->expandable_nodes)) {
+            $object->expandable_nodes = array_merge(
+              $object->expandable_nodes,
+              $object->{$field_name}->expandable_nodes
+            );
+            unset($object->{$field_name}->expandable_nodes);
+
+          }
+          // Otherwise, just move the expandable tables downwards
+          else {
+            $object->expandable_nodes = $object->{$field_name}->expandable_nodes;
+            unset($object->{$field_name}->expandable_nodes);
+          }
+        }
+      }
+    }
+  }
+
+  // Move extended array downwards ----------------------------------
+  // This tells us what we have expanded (ie: that we succeeded)
+  // and is needed to remove the entry from the expandable array
+
+  // If there is no expanded field in the current object then check any of the nested objects
+  // and move it down
   if (!property_exists($object, 'expanded')) {
-    //if there's no extended field then go hunting for it
+
+    // It's a nested object if the value is an object
     foreach ( (array)$object as $field_name => $field_value) {
       if (is_object($field_value)) {
+
+        // Check if the current nested object has an expanded array
         if (isset($field_value->expanded)) {
+
+          // If so, then move it downwards
           $object->expanded = $field_value->expanded;
           unset($field_value->expanded);
         }
       }
     }
   }
-  //try again becasue now we might have moved it down
+
+  // Check again if there is an expanded field in the current object
+  // We check again because it might have been moved downwards above
   if (property_exists($object, 'expanded')) {
+
+    // If so, then remove the expanded identifier from the correct expandable array
     $expandable_name = 'expandable_' . $type . 's';
     if (property_exists($object, $expandable_name) and $object->{$expandable_name}) {
       $key_to_remove = array_search($object->expanded, $object->{$expandable_name});
       unset($object->{$expandable_name}[$key_to_remove]);
       unset($object->expanded);
+
     }
-    else {
-      // if there is an expandable array then we've reached the base object
-      // if we get here and don't have anything expanded then something went wrong
-      //      tripal_report_error('tripal_core', TRIPAL_ERROR,
-      //        'chado_expand_var: Unable to expand the %type %to_expand',
-      //        array('%type'=>$type, '%to_expand'=>$to_expand),
-      //      );
-    } //end of it we've reached the base object
   }
 
+  // Finally, Return the object!
   return $object;
 }

+ 5 - 5
tripal_core/tripal_core.module

@@ -453,7 +453,7 @@ function tripal_core_theme($existing, $type, $theme, $path) {
     ),
     // Relationships Nore Form
     'chado_node_relationships_form_table' => array(
-      'function' => 'theme_chado_add_node_form_relationships_tables',
+      'function' => 'theme_chado_add_node_form_relationships_table',
       'render element' => 'element',
     ),
 
@@ -565,17 +565,17 @@ function tripal_core_node_view_alter(&$build) {
   // make some changes to each block of content so that we can associate
   // a table of contents and add administrator and curator messages
   if (preg_match('/chado_/', $node->type)) {
-    
+
     // iterate through all the elements of the $build array and for those
     // that are wanting to provide content for this node
     $markup = array();
     foreach ($build as $key => $value) {
-      
+
       // skip the body element as the Tripal node types do not use it
       if ($key == 'body') {
         continue;
       }
-      
+
       // examine elements without a '#' prefix as these should be adding
       // contents to the page. Skip the table of contents and links as those
       // will be placed elsewhere
@@ -650,7 +650,7 @@ function tripal_core_node_view_alter(&$build) {
             site's default theme, edit then " .
             l('clear the Drupal cache', 'admin/config/development/performance', array('attributes' => array('target' => '_blank'))) . ".
             Currently, the content above is provided by this template: <br><br>$path",
-            TRIPAL_INFO, 
+            TRIPAL_INFO,
             array('return_html' => 1)
           );
         }

+ 40 - 38
tripal_cv/api/tripal_cv.DEPRECATED.inc

@@ -7,9 +7,9 @@
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_cv().
+ * This function has been replaced by cv_retrieve().
  *
- * @see chado_get_cv().
+ * @see cv_retrieve().
  */
 function tripal_cv_get_cv($select_values) {
 
@@ -19,19 +19,19 @@ function tripal_cv_get_cv($select_values) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_cv_get_cv',
-      '%new_function' => 'chado_get_cv'
+      '%new_function' => 'cv_retrieve'
     )
   );
 
-  return chado_get_cv($select_values);
+  return cv_retrieve($select_values);
 }
 
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_cv().
+ * This function has been replaced by cv_retrieve().
  *
- * @see chado_get_cv().
+ * @see cv_retrieve().
  */
 function tripal_cv_get_cv_by_name($name) {
 
@@ -41,19 +41,19 @@ function tripal_cv_get_cv_by_name($name) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_cv_get_cv_by_name',
-      '%new_function' => 'chado_get_cv'
+      '%new_function' => 'cv_retrieve'
     )
   );
 
-  return chado_get_cv(array('name' => $name));
+  return cv_retrieve(array('name' => $name));
 }
 
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_cv().
+ * This function has been replaced by cv_retrieve().
  *
- * @see chado_get_cv().
+ * @see cv_retrieve().
  */
 function tripal_cv_get_cv_by_id($cv_id) {
 
@@ -63,19 +63,19 @@ function tripal_cv_get_cv_by_id($cv_id) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_cv_get_cv_by_id',
-      '%new_function' => 'chado_get_cv'
+      '%new_function' => 'cv_retrieve'
     )
   );
 
-  return chado_get_cv(array('cv_id' => $id));
+  return cv_retrieve(array('cv_id' => $id));
 }
 
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_cv().
+ * This function has been replaced by cv_retrieve().
  *
- * @see chado_get_cv().
+ * @see cv_retrieve().
  */
 function tripal_cv_get_cv_id($cv_name) {
 
@@ -85,11 +85,11 @@ function tripal_cv_get_cv_id($cv_name) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_cv_get_cv_id',
-      '%new_function' => 'chado_get_cv'
+      '%new_function' => 'cv_retrieve'
     )
   );
 
-  $cv = chado_get_cv(array('name' => $cv_name));
+  $cv = cv_retrieve(array('name' => $cv_name));
   if (isset($cv->cv_id)) {
     return $cv->cv_id;
   }
@@ -123,9 +123,9 @@ function tripal_cv_get_cv_options() {
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_cvterm().
+ * This function has been replaced by cvterm_retrieve().
  *
- * @see chado_get_cvterm().
+ * @see cvterm_retrieve().
  */
 function tripal_cv_get_cvterm_by_id($cvterm_id) {
 
@@ -135,19 +135,19 @@ function tripal_cv_get_cvterm_by_id($cvterm_id) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_cv_get_cvterm_by_id',
-      '%new_function' => 'chado_get_cvterm'
+      '%new_function' => 'cvterm_retrieve'
     )
   );
 
-  return chado_get_cvterm(array('cvterm_id' => $cvterm_id));
+  return cvterm_retrieve(array('cvterm_id' => $cvterm_id));
 }
 
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_cvterm().
+ * This function has been replaced by cvterm_retrieve().
  *
- * @see chado_get_cvterm().
+ * @see cvterm_retrieve().
  */
 function tripal_cv_get_cvterm_by_name($name, $cv_id = NULL, $cv_name = 'tripal') {
 
@@ -157,7 +157,7 @@ function tripal_cv_get_cvterm_by_name($name, $cv_id = NULL, $cv_name = 'tripal')
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_cv_get_cvterm_by_name',
-      '%new_function' => 'chado_get_cvterm'
+      '%new_function' => 'cvterm_retrieve'
     )
   );
 
@@ -171,27 +171,29 @@ function tripal_cv_get_cvterm_by_name($name, $cv_id = NULL, $cv_name = 'tripal')
     );
   }
 
-  return chado_get_cvterm($identifiers);
+  return cvterm_retrieve($identifiers);
 }
 
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_cvterm().
+ * This function has been replaced by cvterm_retrieve().
  *
- * @see chado_get_cvterm().
+ * @see cvterm_retrieve().
  */
 function tripal_cv_get_cvterm_by_synonym($synonym, $cv_id = NULL, $cv_name = 'tripal') {
 
-  tripal_report_error('tripal_deprecated', TRIPAL_NOTICE,
+  tripal_report_error(
+    'tripal_deprecated',
+    TRIPAL_NOTICE,
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
-      '%old_function'=>'tripal_cv_get_cvterm_by_synonym', 
-      '%new_function' => 'chado_get_cvterm'
+      '%old_function'=>'tripal_cv_get_cvterm_by_synonym',
+      '%new_function' => 'cvterm_retrieve'
     )
   );
 
-  return chado_get_cvterm(array(
+  return cvterm_retrieve(array(
     'synonym' => array(
       'name' => $synonym,
       'cv_id' => $cv_id,
@@ -247,9 +249,9 @@ function tripal_cv_update_cvtermpath($cvid, $job_id = NULL) {
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_insert_cv().
+ * This function has been replaced by cv_insert().
  *
- * @see chado_insert_cv().
+ * @see cv_insert().
  */
 function tripal_cv_add_cv($name, $definition) {
 
@@ -259,19 +261,19 @@ function tripal_cv_add_cv($name, $definition) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_cv_add_cv',
-      '%new_function' => 'chado_insert_cv'
+      '%new_function' => 'cv_insert'
     )
   );
 
-  return chado_insert_cv($name, $definition);
+  return cv_insert($name, $definition);
 }
 
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_insert_cvterm().
+ * This function has been replaced by cvterm_insert().
  *
- * @see chado_insert_cvterm().
+ * @see cvterm_insert().
  */
 function tripal_cv_add_cvterm($term, $defaultcv = '_global', $is_relationship = 0, $update = 1, $dbname = 'internal') {
 
@@ -281,7 +283,7 @@ function tripal_cv_add_cvterm($term, $defaultcv = '_global', $is_relationship =
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_cv_add_cvterm',
-      '%new_function' => 'chado_insert_cvterm'
+      '%new_function' => 'cvterm_insert'
     )
   );
 
@@ -294,7 +296,7 @@ function tripal_cv_add_cvterm($term, $defaultcv = '_global', $is_relationship =
     unset($term['def']);
   }
 
-  return chado_insert_cvterm(
+  return cvterm_insert(
     $term,
     array(
       'update_existing' => $update

+ 73 - 31
tripal_cv/api/tripal_cv.api.inc

@@ -22,7 +22,7 @@
  */
 
 /**
- * Retrieves a chado controlled vocabulary object
+ * Retrieves a chado controlled vocabulary variable
  *
  * @param $identifier
  *   An array with the key stating what the identifier is. Supported keys (only on of the
@@ -44,14 +44,20 @@
  *
  * @ingroup tripal_cv_api
  */
-function chado_get_cv($identifiers, $options = array()) {
+function cv_retrieve($identifiers, $options = array()) {
+
+  // Set Defaults
+  if (!isset($options['include_fk'])) {
+    // Tells chado_generate_var not to follow any foreign keys
+    $options['include_fk'] = array();
+  }
 
   // Error Checking of parameters
   if (!is_array($identifiers)) {
     tripal_report_error(
       'tripal_cv_api',
       TRIPAL_ERROR,
-      "chado_get_cv: The identifier passed in is expected to be an array with the key
+      "cv_retrieve: The identifier passed in is expected to be an array with the key
         matching a column name in the cv table (ie: cv_id or name). You passed in %identifier.",
       array(
         '%identifier'=> print_r($identifiers, TRUE)
@@ -62,7 +68,7 @@ function chado_get_cv($identifiers, $options = array()) {
     tripal_report_error(
       'tripal_cv_api',
       TRIPAL_ERROR,
-      "chado_get_cv: You did not pass in anything to identify the cv you want. The identifier
+      "cv_retrieve: You did not pass in anything to identify the cv you want. The identifier
         is expected to be an array with the key matching a column name in the cv table
         (ie: cv_id or name). You passed in %identifier.",
       array(
@@ -83,7 +89,7 @@ function chado_get_cv($identifiers, $options = array()) {
     tripal_report_error(
       'tripal_cv_api',
       TRIPAL_ERROR,
-      "chado_get_cv: The identifiers you passed in were not unique. You passed in %identifier.",
+      "cv_retrieve: The identifiers you passed in were not unique. You passed in %identifier.",
       array(
         '%identifier'=> print_r($identifiers, TRUE)
       )
@@ -95,7 +101,7 @@ function chado_get_cv($identifiers, $options = array()) {
     tripal_report_error(
       'tripal_cv_api',
       TRIPAL_ERROR,
-      "chado_get_cv: chado_generate_var() failed to return a cv based on the identifiers
+      "cv_retrieve: chado_generate_var() failed to return a cv based on the identifiers
         you passed in. You should check that your identifiers are correct, as well as, look
         for a chado_generate_var error for additional clues. You passed in %identifier.",
       array(
@@ -133,15 +139,20 @@ function cv_get_select_options() {
 }
 
 /**
- * Retrieves a chado controlled vocabulary term object
+ * Retrieves a chado controlled vocabulary term variable
  *
  * @param $identifier
- *   An array for uniquely selecting a cvterm. It is compatible with chado_generate_var 
- *   and chado_select_record functions. To uniquely identify a cvterm, specify either 
- *   a 'cvterm_id' key or a 'cv_id' and 'name' keys. Additionally, to find a cvterm
- *   using a synonym, use a 'synonym' key which is an array with the following keys:
- *  'name' (the name of the synonym) and either 'cv_id' (the cv_id of the synonym) or 
- *  'cv_name' (the name of the cv of the synonym)
+ *   An array with the key stating what the identifier is. Supported keys (only on of the
+ *   following unique keys is required):
+ *    - cvterm_id: the chado cv.cvterm_id primary key
+ *    - name: the chado cv.name field (assume unique)
+ *   There are also some specially handled keys. They are:
+ *    - synonym: an array with 'name' => the name of the synonym of the cvterm you want
+ *        returned; 'cv_id' => the cv_id of the synonym; 'cv_name' => the name of the cv
+ *        of the synonym
+ *    - property: An array/object describing the property to select records for. It
+ *      should at least have either a type_name (if unique across cvs) or type_id. Other
+ *      supported keys include: cv_id/cv_name (of the type), value and rank
  * @param $options
  *   An array of options. Supported keys include:
  *     - Any keys supported by chado_generate_var(). See that function definition for
@@ -157,22 +168,36 @@ function cv_get_select_options() {
  *
  * @ingroup tripal_cv_api
  */
-function chado_get_cvterm($identifiers, $options = array()) {
+function cvterm_retrieve($identifiers, $options = array()) {
+
+  // Set Defaults
+  if (!isset($options['include_fk'])) {
+    // Tells chado_generate_var to only get the cv
+    $options['include_fk'] = array('cv_id' => TRUE);
+  }
 
   // Error Checking of parameters
   if (!is_array($identifiers)) {
-    tripal_report_error('tripal_cv_api', TRIPAL_ERROR,
-      "chado_get_cvterm: The identifier passed in is expected to be an array with the key
+    tripal_report_error(
+      'tripal_cv_api',
+      TRIPAL_ERROR,
+      "cvterm_retrieve: The identifier passed in is expected to be an array with the key
         matching a column name in the cvterm table (ie: cvterm_id or name). You passed in %identifier.",
-      array('%identifier'=> print_r($identifiers, TRUE))
+      array(
+        '%identifier'=> print_r($identifiers, TRUE)
+      )
     );
   }
   elseif (empty($identifiers)) {
-    tripal_report_error('tripal_cv_api', TRIPAL_ERROR,
-      "chado_get_cvterm: You did not pass in anything to identify the cvterm you want. The identifier
+    tripal_report_error(
+      'tripal_cv_api',
+      TRIPAL_ERROR,
+      "cvterm_retrieve: You did not pass in anything to identify the cvterm you want. The identifier
         is expected to be an array with the key matching a column name in the cvterm table
         (ie: cvterm_id or name). You passed in %identifier.",
-      array('%identifier'=> print_r($identifiers, TRUE))
+      array(
+        '%identifier'=> print_r($identifiers, TRUE)
+      )
     );
   }
 
@@ -201,24 +226,41 @@ function chado_get_cvterm($identifiers, $options = array()) {
     $identifiers = array('cvterm_id' => $synonym[0]->cvterm_id);
   }
 
-  // Try to get the cvterm
-  $cvterm = chado_generate_var('cvterm', $identifiers, $options);
+  // If one of the identifiers is property then use chado_get_record_with_property()
+  if (isset($identifiers['property'])) {
+    $property = $identifiers['property'];
+    unset($identifiers['property']);
+    $cvterm = chado_get_record_with_property('cvterm', $property, $identifiers, $options);
+  }
+  // Else we have a simple case and we can just use chado_generate_var to get the cvterm
+  else {
+    // Try to get the cvterm
+    $cvterm = chado_generate_var('cvterm', $identifiers, $options);
+  }
 
   // Ensure the cvterm is singular. If it's an array then it is not singular
   if (is_array($cvterm)) {
-    tripal_report_error('tripal_cv_api', TRIPAL_ERROR,
-      "chado_get_cvterm: The identifiers you passed in were not unique. You passed in %identifier.",
-      array('%identifier'=> print_r($identifiers, TRUE))
+    tripal_report_error(
+      'tripal_cv_api',
+      TRIPAL_ERROR,
+      "cvterm_retrieve: The identifiers you passed in were not unique. You passed in %identifier.",
+      array(
+        '%identifier'=> print_r($identifiers, TRUE)
+      )
     );
   }
 
   // Report an error if $cvterm is FALSE since then chado_generate_var has failed
   elseif ($cvterm === FALSE) {
-    tripal_report_error('tripal_cv_api', TRIPAL_ERROR,
-      "chado_get_cvterm: chado_generate_var() failed to return a cvterm based on the identifiers
+    tripal_report_error(
+      'tripal_cv_api',
+      TRIPAL_ERROR,
+      "cvterm_retrieve: chado_generate_var() failed to return a cvterm based on the identifiers
         you passed in. You should check that your identifiers are correct, as well as, look
         for a chado_generate_var error for additional clues. You passed in %identifier.",
-      array('%identifier'=> print_r($identifiers, TRUE))
+      array(
+        '%identifier'=> print_r($identifiers, TRUE)
+      )
     );
   }
 
@@ -313,7 +355,7 @@ function chado_update_cvtermpath($cvid, $job_id = NULL) {
  *
  * @ingroup tripal_cv_api
  */
-function chado_insert_cv($name, $definition) {
+function cv_insert($name, $definition) {
 
   // insert/update values
   $ins_values = array(
@@ -392,7 +434,7 @@ function chado_insert_cv($name, $definition) {
  *
  * @ingroup tripal_cv_api
  */
-function chado_insert_cvterm($term, $options) {
+function cvterm_insert($term, $options) {
 
   // Set Defaults
   if (isset($term['cv_name'])) {
@@ -874,7 +916,7 @@ function chado_associate_cvterm($basetable, $record_id, $cvterm) {
     }
     elseif ($options['insert_cvterm']) {
       // Insert the cvterm
-      $insert = chado_insert_cvterm($values);
+      $insert = cvterm_insert($values);
       if (isset($insert->cvterm_id)) {
         $cvterm['cvterm_id'] = $insert->cvterm_id;
       }

+ 28 - 28
tripal_db/api/tripal_db.DEPRECATED.inc

@@ -7,9 +7,9 @@
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_db().
+ * This function has been replaced by db_retrieve().
  *
- * @see chado_get_db().
+ * @see db_retrieve().
  */
 function tripal_db_get_db($select_values) {
 
@@ -19,19 +19,19 @@ function tripal_db_get_db($select_values) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_db_get_db',
-      '%new_function' => 'chado_get_db'
+      '%new_function' => 'db_retrieve'
     )
   );
 
-  return chado_get_db($select_values);
+  return db_retrieve($select_values);
 }
 
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_db().
+ * This function has been replaced by db_retrieve().
  *
- * @see chado_get_db().
+ * @see db_retrieve().
  */
 function tripal_db_get_db_by_db_id($db_id) {
 
@@ -41,19 +41,19 @@ function tripal_db_get_db_by_db_id($db_id) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_db_get_db_by_db_id',
-      '%new_function' => 'chado_get_db'
+      '%new_function' => 'db_retrieve'
     )
   );
 
-  return chado_get_db(array('db_id' => $db_id));
+  return db_retrieve(array('db_id' => $db_id));
 }
 
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_db().
+ * This function has been replaced by db_retrieve().
  *
- * @see chado_get_db().
+ * @see db_retrieve().
  */
 function tripal_db_get_db_by_name($name) {
 
@@ -63,11 +63,11 @@ function tripal_db_get_db_by_name($name) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_db_get_db_by_name',
-      '%new_function' => 'chado_get_db'
+      '%new_function' => 'db_retrieve'
     )
   );
 
-  return chado_get_db(array('name' => $name));
+  return db_retrieve(array('name' => $name));
 }
 
 /**
@@ -95,9 +95,9 @@ function tripal_db_get_db_options() {
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_db().
+ * This function has been replaced by db_retrieve().
  *
- * @see chado_get_dbxref().
+ * @see dbxref_retrieve().
  */
 function tripal_db_get_dbxref($select_values) {
 
@@ -107,19 +107,19 @@ function tripal_db_get_dbxref($select_values) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_db_get_dbxref',
-      '%new_function' => 'chado_get_dbxref'
+      '%new_function' => 'dbxref_retrieve'
     )
   );
 
-  return chado_get_dbxref($select_values);
+  return dbxref_retrieve($select_values);
 }
 
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_db().
+ * This function has been replaced by db_retrieve().
  *
- * @see chado_get_dbxref().
+ * @see dbxref_retrieve().
  */
 function tripal_db_get_dbxref_by_accession($accession, $db_id=0) {
 
@@ -129,7 +129,7 @@ function tripal_db_get_dbxref_by_accession($accession, $db_id=0) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_db_get_dbxref_by_accession',
-      '%new_function' => 'chado_get_dbxref'
+      '%new_function' => 'dbxref_retrieve'
     )
   );
 
@@ -141,15 +141,15 @@ function tripal_db_get_dbxref_by_accession($accession, $db_id=0) {
       'db_id' => $db_id
     );
   }
-  return chado_get_dbxref($identifiers);
+  return dbxref_retrieve($identifiers);
 }
 
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_insert_db().
+ * This function has been replaced by db_insert().
  *
- * @see chado_insert_db().
+ * @see db_insert().
  */
 function tripal_db_add_db($dbname, $description = '', $url = '', $urlprefix = '', $update = 0) {
 
@@ -159,11 +159,11 @@ function tripal_db_add_db($dbname, $description = '', $url = '', $urlprefix = ''
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_db_add_db',
-      '%new_function' => 'chado_insert_db'
+      '%new_function' => 'db_insert'
     )
   );
 
-  return chado_insert_db(
+  return db_insert(
     array(
       'name' => $dbname,
       'description' => $description,
@@ -179,9 +179,9 @@ function tripal_db_add_db($dbname, $description = '', $url = '', $urlprefix = ''
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_insert_dbxref().
+ * This function has been replaced by dbxref_insert().
  *
- * @see chado_insert_dbxref().
+ * @see dbxref_insert().
  */
 function tripal_db_add_dbxref($db_id, $accession, $version = '', $description = '') {
 
@@ -191,11 +191,11 @@ function tripal_db_add_dbxref($db_id, $accession, $version = '', $description =
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_db_add_dbxref',
-      '%new_function' => 'chado_insert_dbxref'
+      '%new_function' => 'dbxref_insert'
     )
   );
 
-  return chado_insert_dbxref(array(
+  return dbxref_insert(array(
     'db_id' => $db_id,
     'accession' => $accession,
     'version' => $version,

+ 47 - 22
tripal_db/api/tripal_db.api.inc

@@ -14,7 +14,7 @@
  */
 
 /**
- * Retrieves a chado db object
+ * Retrieves a chado db variable
  *
  * Example Usage:
  * @code
@@ -54,14 +54,20 @@
  *
  * @ingroup tripal_db_api
  */
-function chado_get_db($identifiers, $options = array()) {
+function db_retrieve($identifiers, $options = array()) {
+
+  // Set Defaults
+  if (!isset($options['include_fk'])) {
+    // Tells chado_generate_var not to follow any foreign keys
+    $options['include_fk'] = array();
+  }
 
   // Error Checking of parameters
   if (!is_array($identifiers)) {
     tripal_report_error(
       'tripal_db_api',
       TRIPAL_ERROR,
-      "chado_get_db: The identifier passed in is expected to be an array with the key
+      "db_retrieve: The identifier passed in is expected to be an array with the key
         matching a column name in the db table (ie: db_id or name). You passed in %identifier.",
       array(
         '%identifier'=> print_r($identifiers, TRUE)
@@ -72,7 +78,7 @@ function chado_get_db($identifiers, $options = array()) {
     tripal_report_error(
       'tripal_db_api',
       TRIPAL_ERROR,
-      "chado_get_db: You did not pass in anything to identify the db you want. The identifier
+      "db_retrieve: You did not pass in anything to identify the db you want. The identifier
         is expected to be an array with the key matching a column name in the db table
         (ie: db_id or name). You passed in %identifier.",
       array(
@@ -93,7 +99,7 @@ function chado_get_db($identifiers, $options = array()) {
     tripal_report_error(
       'tripal_db_api',
       TRIPAL_ERROR,
-      "chado_get_db: The identifiers you passed in were not unique. You passed in %identifier.",
+      "db_retrieve: The identifiers you passed in were not unique. You passed in %identifier.",
       array(
         '%identifier'=> print_r($identifiers, TRUE)
       )
@@ -105,7 +111,7 @@ function chado_get_db($identifiers, $options = array()) {
     tripal_report_error(
       'tripal_db_api',
       TRIPAL_ERROR,
-      "chado_get_db: chado_generate_var() failed to return a db based on the identifiers
+      "db_retrieve: chado_generate_var() failed to return a db based on the identifiers
         you passed in. You should check that your identifiers are correct, as well as, look
         for a chado_generate_var error for additional clues. You passed in %identifier.",
       array(
@@ -143,7 +149,7 @@ function db_get_select_options() {
 }
 
 /**
- * Retrieves a chado database reference object
+ * Retrieves a chado database reference variable
  *
  * Example Usage:
  * @code
@@ -171,10 +177,14 @@ function db_get_select_options() {
  * @endcode
  *
  * @param $identifier
- *   An array with the key stating what the identifier is. Supported keys (only on of the
+ *   An array with the key stating what the identifier is. Supported keys (only one of the
  *   following unique keys is required):
  *    - dbxref_id: the chado dbxref.dbxref_id primary key
  *    - accession: the chado dbxref.accession field (assume unique)
+ *   There are also some specially handled keys. They are:
+ *    - property: An array/object describing the property to select records for. It
+ *      should at least have either a type_name (if unique across cvs) or type_id. Other
+ *      supported keys include: cv_id/cv_name (of the type), value and rank
  * @param $options
  *   An array of options. Supported keys include:
  *     - Any keys supported by chado_generate_var(). See that function definition for
@@ -190,14 +200,20 @@ function db_get_select_options() {
  *
  * @ingroup tripal_db_api
  */
-function chado_get_dbxref($identifiers, $options = array()) {
+function dbxref_retrieve($identifiers, $options = array()) {
+
+  // Set Defaults
+  if (!isset($options['include_fk'])) {
+    // Tells chado_generate_var not only expand the db
+    $options['include_fk'] = array('db_id' => TRUE);
+  }
 
   // Error Checking of parameters
   if (!is_array($identifiers)) {
     tripal_report_error(
       'tripal_db_api',
       TRIPAL_ERROR,
-      "chado_get_dbxref: The identifier passed in is expected to be an array with the key
+      "dbxref_retrieve: The identifier passed in is expected to be an array with the key
         matching a column name in the dbxref table (ie: dbxref_id or name). You passed in %identifier.",
       array(
         '%identifier'=> print_r($identifiers, TRUE)
@@ -208,7 +224,7 @@ function chado_get_dbxref($identifiers, $options = array()) {
     tripal_report_error(
       'tripal_db_api',
       TRIPAL_ERROR,
-      "chado_get_dbxref: You did not pass in anything to identify the dbxref you want. The identifier
+      "dbxref_retrieve: You did not pass in anything to identify the dbxref you want. The identifier
         is expected to be an array with the key matching a column name in the dbxref table
         (ie: dbxref_id or name). You passed in %identifier.",
       array(
@@ -217,19 +233,28 @@ function chado_get_dbxref($identifiers, $options = array()) {
     );
   }
 
-  // Try to get the dbxref
-  $dbxref = chado_generate_var(
-    'dbxref',
-    $identifiers,
-    $options
-  );
+  // If one of the identifiers is property then use chado_get_record_with_property()
+  if (isset($identifiers['property'])) {
+    $property = $identifiers['property'];
+    unset($identifiers['property']);
+    $dbxref = chado_get_record_with_property('dbxref', $property, $identifiers, $options);
+  }
+
+  // Else we have a simple case and we can just use chado_generate_var to get the analysis
+  else {
+    $dbxref = chado_generate_var(
+      'dbxref',
+      $identifiers,
+      $options
+    );
+  }
 
   // Ensure the dbxref is singular. If it's an array then it is not singular
   if (is_array($dbxref)) {
     tripal_report_error(
       'tripal_db_api',
       TRIPAL_ERROR,
-      "chado_get_dbxref: The identifiers you passed in were not unique. You passed in %identifier.",
+      "dbxref_retrieve: The identifiers you passed in were not unique. You passed in %identifier.",
       array(
         '%identifier'=> print_r($identifiers, TRUE)
       )
@@ -241,7 +266,7 @@ function chado_get_dbxref($identifiers, $options = array()) {
     tripal_report_error(
       'tripal_db_api',
       TRIPAL_ERROR,
-      "chado_get_dbxref: chado_generate_var() failed to return a dbxref based on the identifiers
+      "dbxref_retrieve: chado_generate_var() failed to return a dbxref based on the identifiers
         you passed in. You should check that your identifiers are correct, as well as, look
         for a chado_generate_var error for additional clues. You passed in %identifier.",
       array(
@@ -279,7 +304,7 @@ function chado_get_dbxref($identifiers, $options = array()) {
  *
  * @ingroup tripal_db_api
  */
-function chado_insert_db($values, $options) {
+function chado_db_insert($values, $options) {
 
   // Default Values
   $dbname = $values['name'];
@@ -339,7 +364,7 @@ function chado_insert_db($values, $options) {
  *
  * @ingroup tripal_db_api
  */
-function chado_insert_dbxref($values) {
+function dbxref_insert($values) {
 
   $db_id = $values['db_id'];
   $accession = $values['accession'];
@@ -437,7 +462,7 @@ function chado_associate_dbxref($basetable, $record_id, $dbxref, $options = arra
     }
     elseif ($options['insert_dbxref']) {
       // Insert the dbxref
-      $insert = chado_insert_dbxref($values);
+      $insert = dbxref_insert($values);
       if (isset($insert->dbxref_id)) {
         $dbxref['dbxref_id'] = $insert->dbxref_id;
       }

+ 8 - 8
tripal_organism/api/tripal_organism.DEPRECATED.inc

@@ -7,9 +7,9 @@
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_organism().
+ * This function has been replaced by organism_retrieve().
  *
- * @see chado_get_organism().
+ * @see organism_retrieve().
  */
 function tripal_organism_get_organism_by_nid($nid) {
 
@@ -19,19 +19,19 @@ function tripal_organism_get_organism_by_nid($nid) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_organism_get_organism_by_nid',
-      '%new_function' => 'chado_get_organism'
+      '%new_function' => 'organism_retrieve'
     )
   );
 
-  return chado_get_organism(array('nid' => $nid));
+  return organism_retrieve(array('nid' => $nid));
 }
 
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_organism().
+ * This function has been replaced by organism_retrieve().
  *
- * @see chado_get_organism().
+ * @see organism_retrieve().
  */
 function tripal_organism_get_organism_by_organism_id($organism_id) {
 
@@ -41,11 +41,11 @@ function tripal_organism_get_organism_by_organism_id($organism_id) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_organism_get_organism_by_organism_id',
-      '%new_function' => 'chado_get_organism'
+      '%new_function' => 'organism_retrieve'
     )
   );
 
-  return chado_get_organism(array('organism_id' => $organism_id));
+  return organism_retrieve(array('organism_id' => $organism_id));
 }
 
 /**

+ 33 - 12
tripal_organism/api/tripal_organism.api.inc

@@ -13,13 +13,17 @@
  */
 
 /**
- * Retrieves a chado organism object
+ * Retrieves a chado organism variable
  *
  * @param $identifier
  *   An array with the key stating what the identifier is. Supported keys (only on of the
  *   following unique keys is required):
  *    - organism_id: the chado organism.organism_id primary key
  *    - genus & species: the chado organism.genus field & organism.species field
+ *   There are also some specially handled keys. They are:
+ *    - property: An array/object describing the property to select records for. It
+ *      should at least have either a type_name (if unique across cvs) or type_id. Other
+ *      supported keys include: cv_id/cv_name (of the type), value and rank
  * @param $options
  *   An array of options. Supported keys include:
  *     - Any keys supported by chado_generate_var(). See that function definition for
@@ -35,14 +39,20 @@
  *
  * @ingroup tripal_organism_api
  */
-function chado_get_organism($identifiers, $options = array()) {
+function organism_retrieve($identifiers, $options = array()) {
+
+  // Set Defaults
+  if (!isset($options['include_fk'])) {
+    // Tells chado_generate_var not to follow any foreign keys
+    $options['include_fk'] = array();
+  }
 
   // Error Checking of parameters
   if (!is_array($identifiers)) {
     tripal_report_error(
       'tripal_organism_api',
       TRIPAL_ERROR,
-      "chado_get_organism: The identifier passed in is expected to be an array with the key
+      "organism_retrieve: The identifier passed in is expected to be an array with the key
         matching a column name in the organism table (ie: organism_id or name). You passed in %identifier.",
       array(
         '%identifier'=> print_r($identifiers, TRUE)
@@ -53,7 +63,7 @@ function chado_get_organism($identifiers, $options = array()) {
     tripal_report_error(
       'tripal_organism_api',
       TRIPAL_ERROR,
-      "chado_get_organism: You did not pass in anything to identify the organism you want. The identifier
+      "organism_retrieve: You did not pass in anything to identify the organism you want. The identifier
         is expected to be an array with the key matching a column name in the organism table
         (ie: organism_id or name). You passed in %identifier.",
       array(
@@ -62,19 +72,30 @@ function chado_get_organism($identifiers, $options = array()) {
     );
   }
 
-  // Try to get the organism
-  $organism = chado_generate_var(
-    'organism',
-    $identifiers,
-    $options
-  );
+  // If one of the identifiers is property then use chado_get_record_with_property()
+  if (isset($identifiers['property'])) {
+    $property = $identifiers['property'];
+    unset($identifiers['property']);
+    $organism = chado_get_record_with_property('organism', $property, $identifiers, $options);
+  }
+
+  // Else we have a simple case and we can just use chado_generate_var to get the analysis
+  else {
+
+    // Try to get the organism
+    $organism = chado_generate_var(
+      'organism',
+      $identifiers,
+      $options
+    );
+  }
 
   // Ensure the organism is singular. If it's an array then it is not singular
   if (is_array($organism)) {
     tripal_report_error(
       'tripal_organism_api',
       TRIPAL_ERROR,
-      "chado_get_organism: The identifiers you passed in were not unique. You passed in %identifier.",
+      "organism_retrieve: The identifiers you passed in were not unique. You passed in %identifier.",
       array(
         '%identifier'=> print_r($identifiers, TRUE)
       )
@@ -86,7 +107,7 @@ function chado_get_organism($identifiers, $options = array()) {
     tripal_report_error(
       'tripal_organism_api',
       TRIPAL_ERROR,
-      "chado_get_organism: chado_generate_var() failed to return a organism based on the identifiers
+      "organism_retrieve: chado_generate_var() failed to return a organism based on the identifiers
         you passed in. You should check that your identifiers are correct, as well as, look
         for a chado_generate_var error for additional clues. You passed in %identifier.",
       array(

+ 1 - 1
tripal_pub/api/tripal_pub.api.inc

@@ -456,7 +456,7 @@ function chado_does_pub_exist($pub_details) {
         'name' => 'tripal_pub',
       ),
     );
-    $pub_type = chado_get_cvterm($identifiers);
+    $pub_type = cvterm_retrieve($identifiers);
   }
   else {
     tripal_report_error('tripal_pub', TRIPAL_ERROR, "chado_does_pub_exist(): The Publication Type is a " .

+ 2 - 2
tripal_pub/includes/importers/tripal_pub.PMID.inc

@@ -620,7 +620,7 @@ function tripal_pub_PMID_parse_publication_type($xml, &$pub) {
             )
           );
           $options = array('case_insensitive_columns' => array('name'));
-          $pub_cvterm = chado_get_cvterm($identifiers, $options);
+          $pub_cvterm = cvterm_retrieve($identifiers, $options);
           if (!$pub_cvterm) {
             // see if this we can find the name using a synonym
             $identifiers = array(
@@ -629,7 +629,7 @@ function tripal_pub_PMID_parse_publication_type($xml, &$pub) {
                 'cv_name' => 'tripal_pub'
               )
             );
-            $pub_cvterm = chado_get_cvterm($identifiers, $options);
+            $pub_cvterm = cvterm_retrieve($identifiers, $options);
             if (!$pub_cvterm) {
               tripal_report_error('tripal_pubmed', TRIPAL_ERROR, 
                 'Cannot find a valid vocabulary term for the publication type: "%term".',

+ 3 - 3
tripal_pub/includes/tripal_pub.pub_importers.inc

@@ -969,7 +969,7 @@ function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE,
         'name' => 'tripal_pub'
       ),
     );
-    $pub_type = chado_get_cvterm($identifiers);
+    $pub_type = cvterm_retrieve($identifiers);
   }
   else {
     tripal_report_error('tripal_pub', TRIPAL_ERROR, 
@@ -1063,7 +1063,7 @@ function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE,
         'name' => 'tripal_pub'
       ),
     );
-    $cvterm = chado_get_cvterm($identifiers);
+    $cvterm = cvterm_retrieve($identifiers);
     
     // if we could not find the cvterm by name then try by synonym
     //$cvterm = tripal_cv_get_cvterm_by_name($key, NULL, 'tripal_pub');
@@ -1074,7 +1074,7 @@ function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE,
           'cv_name' => 'tripal_pub'
         )
       );
-      $cvterm = chado_get_cvterm($identifiers);
+      $cvterm = cvterm_retrieve($identifiers);
     }
     if (!$cvterm) {
       tripal_report_error('tripal_pub', TRIPAL_ERROR, "Cannot find term: '%prop'. Skipping.", array('%prop' => $key));

+ 21 - 21
tripal_stock/api/tripal_stock.DEPRECATED.inc

@@ -7,9 +7,9 @@
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_stock().
+ * This function has been replaced by stock_retrieve().
  *
- * @see chado_get_stock().
+ * @see stock_retrieve().
  */
 function tripal_stock_get_stock_by_nid($nid) {
 
@@ -19,19 +19,19 @@ function tripal_stock_get_stock_by_nid($nid) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_stock_get_stock_by_nid',
-      '%new_function' => 'chado_get_stock'
+      '%new_function' => 'stock_retrieve'
     )
   );
 
-  return chado_get_stock(array('nid' => $nid));
+  return stock_retrieve(array('nid' => $nid));
 }
 
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_stock().
+ * This function has been replaced by stock_retrieve().
  *
- * @see chado_get_stock().
+ * @see stock_retrieve().
  */
 function tripal_stock_get_stock_by_stock_id($stock_id) {
 
@@ -41,19 +41,19 @@ function tripal_stock_get_stock_by_stock_id($stock_id) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_stock_get_stock_by_stock_id',
-      '%new_function' => 'chado_get_stock'
+      '%new_function' => 'stock_retrieve'
     )
   );
 
-  return chado_get_stock(array('stock_id' => $stock_id));
+  return stock_retrieve(array('stock_id' => $stock_id));
 }
 
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_multiple_stocks().
+ * This function has been replaced by stock_retrieve_multiple().
  *
- * @see chado_get_multiple_stocks().
+ * @see stock_retrieve_multiple().
  */
 function tripal_stock_get_all_stocks() {
 
@@ -82,9 +82,9 @@ function tripal_stock_get_all_stocks() {
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_multiple_stocks().
+ * This function has been replaced by stock_retrieve_multiple().
  *
- * @see chado_get_multiple_stocks().
+ * @see stock_retrieve_multiple().
  */
 function tripal_stock_get_stocks($values) {
 
@@ -94,19 +94,19 @@ function tripal_stock_get_stocks($values) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_stock_get_stocks',
-      '%new_function' => 'chado_get_multiple_stocks'
+      '%new_function' => 'stock_retrieve_multiple'
     )
   );
 
-  return chado_get_multiple_stocks($values);
+  return stock_retrieve_multiple($values);
 }
 
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_stock().
+ * This function has been replaced by stock_retrieve().
  *
- * @see chado_get_stock().
+ * @see stock_retrieve().
  */
 function tripal_stock_get_stocks_by_stockprop($stockprop_values, $stock_values) {
 
@@ -116,18 +116,18 @@ function tripal_stock_get_stocks_by_stockprop($stockprop_values, $stock_values)
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_stock_get_stocks_by_stockprop',
-      '%new_function' => 'chado_get_stock'
+      '%new_function' => 'stock_retrieve'
     )
   );
 
   $stock_values['property'] = $stockprop_values;
-  return chado_get_multiple_stocks($stock_values);
+  return stock_retrieve_multiple($stock_values);
 }
 
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by chado_get_stock().
+ * This function has been replaced by stock_retrieve().
  *
  * Return all stocks with a given name identifier
  *  which might match stock.name, stock.uniquename, dbxref.accession,
@@ -141,7 +141,7 @@ function tripal_stock_get_stocks_by_stockprop($stockprop_values, $stock_values)
  * @return
  *   An array of stock node objects
  *
- * @see chado_get_stock().
+ * @see stock_retrieve().
  */
 function tripal_stock_get_stock_by_name_identifier($name, $organism_id) {
 
@@ -151,7 +151,7 @@ function tripal_stock_get_stock_by_name_identifier($name, $organism_id) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_stock_get_stock_by_name_identifier',
-      '%new_function' => 'chado_get_stock'
+      '%new_function' => 'stock_retrieve'
     )
   );
 

+ 23 - 11
tripal_stock/api/tripal_stock.api.inc

@@ -13,7 +13,7 @@
  */
 
 /**
- * Retrieves a chado stock object
+ * Retrieves a chado stock variable
  *
  * @param $identifier
  *   An array with the key stating what the identifier is. Supported keys (only one of the
@@ -39,14 +39,20 @@
  *
  * @ingroup tripal_stock_api
  */
-function chado_get_stock($identifiers, $options = array()) {
+function stock_retrieve($identifiers, $options = array()) {
+
+  // Set Defaults
+  if (!isset($options['include_fk'])) {
+    // Tells chado_generate_var to only expand 1 level
+    $options['include_fk'] = array('type_id' => TRUE, 'dbxref_id' => TRUE);
+  }
 
   // Error Checking of parameters
   if (!is_array($identifiers)) {
     tripal_report_error(
       'tripal_stock_api',
       TRIPAL_ERROR,
-      "chado_get_stock: The identifier passed in is expected to be an array with the key
+      "stock_retrieve: The identifier passed in is expected to be an array with the key
         matching a column name in the stock table (ie: stock_id or name). You passed in %identifier.",
       array(
         '%identifier'=> print_r($identifiers, TRUE)
@@ -57,7 +63,7 @@ function chado_get_stock($identifiers, $options = array()) {
     tripal_report_error(
       'tripal_stock_api',
       TRIPAL_ERROR,
-      "chado_get_stock: You did not pass in anything to identify the stock you want. The identifier
+      "stock_retrieve: You did not pass in anything to identify the stock you want. The identifier
         is expected to be an array with the key matching a column name in the stock table
         (ie: stock_id or name). You passed in %identifier.",
       array(
@@ -89,7 +95,7 @@ function chado_get_stock($identifiers, $options = array()) {
     tripal_report_error(
       'tripal_stock_api',
       TRIPAL_ERROR,
-      "chado_get_stock: The identifiers you passed in were not unique. You passed in %identifier.",
+      "stock_retrieve: The identifiers you passed in were not unique. You passed in %identifier.",
       array(
         '%identifier'=> print_r($identifiers, TRUE)
       )
@@ -101,7 +107,7 @@ function chado_get_stock($identifiers, $options = array()) {
     tripal_report_error(
       'tripal_stock_api',
       TRIPAL_ERROR,
-      "chado_get_stock: chado_generate_var() failed to return a stock based on the identifiers
+      "stock_retrieve: chado_generate_var() failed to return a stock based on the identifiers
         you passed in. You should check that your identifiers are correct, as well as, look
         for a chado_generate_var error for additional clues. You passed in %identifier.",
       array(
@@ -117,7 +123,7 @@ function chado_get_stock($identifiers, $options = array()) {
 }
 
 /**
- * Retrieves a chado stock object
+ * Retrieves a chado stock variable
  *
  * @param $identifier
  *   An array with the key stating what the identifier is. Supported keys include any
@@ -133,14 +139,20 @@ function chado_get_stock($identifiers, $options = array()) {
  *
  * @ingroup tripal_stock_api
  */
-function chado_get_multiple_stocks($identifiers, $options = array()) {
+function stock_retrieve_multiple($identifiers, $options = array()) {
+
+  // Set Defaults
+  if (!isset($options['include_fk'])) {
+    // Tells chado_generate_var to only expand 1 level
+    $options['include_fk'] = array('type_id' => TRUE, 'dbxref_id' => TRUE);
+  }
 
   // Error Checking of parameters
   if (!is_array($identifiers)) {
     tripal_report_error(
       'tripal_stock_api',
       TRIPAL_ERROR,
-      "chado_get_stock: The identifier passed in is expected to be an array with the key
+      "stock_retrieve: The identifier passed in is expected to be an array with the key
         matching a column name in the stock table (ie: stock_id or name). You passed in %identifier.",
       array(
         '%identifier'=> print_r($identifiers, TRUE)
@@ -151,7 +163,7 @@ function chado_get_multiple_stocks($identifiers, $options = array()) {
     tripal_report_error(
       'tripal_stock_api',
       TRIPAL_ERROR,
-      "chado_get_stock: You did not pass in anything to identify the stock you want. The identifier
+      "stock_retrieve: You did not pass in anything to identify the stock you want. The identifier
         is expected to be an array with the key matching a column name in the stock table
         (ie: stock_id or name). You passed in %identifier.",
       array(
@@ -183,7 +195,7 @@ function chado_get_multiple_stocks($identifiers, $options = array()) {
     tripal_report_error(
       'tripal_stock_api',
       TRIPAL_ERROR,
-      "chado_get_stock: chado_generate_var() failed to return a stock based on the identifiers
+      "stock_retrieve: chado_generate_var() failed to return a stock based on the identifiers
         you passed in. You should check that your identifiers are correct, as well as, look
         for a chado_generate_var error for additional clues. You passed in %identifier.",
       array(