123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711 |
- <?php
- /**
- * @file
- * The Tripal Core API
- *
- * This file provides the API needed for all other Tripal and Tripal dependent
- * modules.
- */
-
- /**
- * @defgroup tripal_api Tripal API
- * @{
- * Provides an application programming interface (API) for the tripal package
- *
- * The Tripal API currently provides generic insert/update/select functions for all chado content as
- * well as some module specific functions that insert/update/delete/select specific chado content.
- *
- * This API is currently in it's infancy so some necessary functions might be missing. If you come
- * across a missing function that you think should be included go to the sourceforge feature request * page and request it's inclusion in the API. Such feature requests with a working function * definition will be given priority.
- * @}
- */
- /**
- * @defgroup tripal_schema_api Tripal Schema API
- * @{
- * Provides an application programming interface (API) used to describe chado tables to
- * drupal/tripal
- * @}
- * @ingroup tripal_api
- */
- require_once "tripal_core.schema.api.inc";
- // just a temporary function for debugging
- function tripal_core_chado_insert_test(){
- $ivalues = array(
- 'organism_id' => array(
- 'genus' => 'Lens',
- 'species' => 'culinaris',
- ),
- 'name' => 'orange1.1g000034m.g',
- 'uniquename' => 'orange1.1g000034m.g9',
- 'type_id' => array (
- 'cv_id' => array (
- 'name' => 'sequence',
- ),
- 'name' => 'gene',
- 'is_obsolete' => 0
- ),
- );
- $umatch = array(
- 'organism_id' => array(
- 'genus' => 'Lens',
- 'species' => 'culinaris',
- ),
- 'uniquename' => 'orange1.1g000034m.g9',
- 'type_id' => array (
- 'cv_id' => array (
- 'name' => 'sequence',
- ),
- 'name' => 'gene',
- 'is_obsolete' => 0
- ),
- );
- $uvalues = array(
- 'name' => 'orange1.1g000034m.g',
- 'type_id' => array (
- 'cv_id' => array (
- 'name' => 'sequence',
- ),
- 'name' => 'mRNA',
- 'is_obsolete' => 0
- ),
- );
- $select_multiple = array(
- 'dbxref_id' => array(
- 'db_id' => 2,
- )
- );
- //$result = tripal_core_chado_insert('feature',$ivalues);
- //return "$result->feature_id";
- $result = tripal_core_chado_update('feature',$umatch,$uvalues);
- //$result = tripal_core_chado_select('feature',array('type_id', 'uniquename'),$select_multiple);
- return $result;
- }
- /**
- * Provides a generic routine for inserting into any Chado table
- *
- * Use this function to insert a record into any Chado table. The first
- * argument specifies the table for inserting and the second is an array
- * of values to be inserted. The array is mutli-dimensional such that
- * foreign key lookup values can be specified.
- *
- * @param $table
- * The name of the chado table for inserting
- * @param $values
- * An associative array containing the values for inserting.
- *
- * @return
- * On success this function returns TRUE. On failure, it returns FALSE.
- *
- * Example usage:
- * @code
- * $values = array(
- * 'organism_id' => array(
- * 'genus' => 'Citrus',
- * 'species' => 'sinensis',
- * ),
- * 'name' => 'orange1.1g000034m.g',
- * 'uniquename' => 'orange1.1g000034m.g',
- * 'type_id' => array (
- * 'cv_id' => array (
- * 'name' => 'sequence',
- * ),
- * 'name' => 'gene',
- * 'is_obsolete' => 0
- * ),
- * );
- * $result = tripal_core_chado_insert('feature',$values);
- * @endcode
- * The above code inserts a record into the feature table. The $values array is
- * nested such that the organism is selected 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_api
- */
- function tripal_core_chado_insert($table,$values){
- $insert_values = array();
-
- // get the table description
- $table_desc = module_invoke_all('chado_'.$table.'_schema');
- // iterate through the values array and create a new 'insert_values' array
- // that has all the values needed for insert with all foreign relationsihps
- // resolved.
- foreach($values as $field => $value){
- if(is_array($value)){
- // select the value from the foreign key relationship for this value
- $results = tripal_core_chado_get_foreign_key($table_desc,$field,$value);
- if (sizeof($results) > 1) {
- watchdog('tripal_core', 'tripal_core_chado_insert: Too many records match the criteria supplied for !foreign_key foreign key constraint (!criteria)', array('!foreign_key' => $field, '!criteria' => print_r($value,TRUE)), WATCHDOG_ERROR);
- } elseif (sizeof($results) < 1) {
- watchdog('tripal_core', 'tripal_core_chado_insert: no record matches criteria supplied for !foreign_key foreign key constraint (!criteria)', array('!foreign_key' => $field, '!criteria' => print_r($value,TRUE)), WATCHDOG_ERROR);
- } else {
- $insert_values[$field] = $results[0];
- }
- }
- else {
- $insert_values[$field] = $value;
- }
- }
- // check for violation of any unique constraints
- $ukeys = $table_desc['unique keys'];
- $ukselect_cols = array();
- $ukselect_vals = array();
- foreach($ukeys as $name => $fields){
- foreach($fields as $index => $field){
- // build the arrays for performing a select that will check the contraint
- array_push($ukselect_cols,$field);
- $ukselect_vals[$field] = $insert_values[$field];
- }
- // now check the constraint
- if(tripal_core_chado_select($table,$ukselect_cols,$ukselect_vals)){
- watchdog('tripal_core',"tripal_core_chado_insert: Cannot insert duplicate record into $table table: " . print_r($values,1),array(),'WATCHDOG_ERROR');
- return false;
- }
- }
- // if trying to insert a field that is the primary key, make sure it also is unique
- $pkey = $table_desc['primary key'][0];
- if($insert_values[$pkey]){
- if(tripal_core_chado_select($table,array($pkey),array($pkey => $insert_values[$pkey]))){
- watchdog('tripal_core',"tripal_core_chado_insert: Cannot insert duplicate primary key into $table table: " . print_r($values,1),array(),'WATCHDOG_ERROR');
- return false;
- }
- }
- // make sure required fields have a value
- $fields = $table_desc['fields'];
- foreach($fields as $field => $def){
- // a field is considered missing if it cannot be null and there is no default
- // value for it or it is of type 'serial'
- if($def['not null'] == 1 and !array_key_exists($field,$insert_values) and !$def['default'] and strcmp($def['type'],serial)!=0){
- watchdog('tripal_core',"tripal_core_chado_insert: Field $table.$field cannot be null: " . print_r($values,1),array(),'WATCHDOG_ERROR');
- return false;
- }
- }
- // Now build the insert SQL statement
- $ifields = array();
- $ivalues = array();
- $itypes = array();
- foreach ($insert_values as $field => $value){
- array_push($ifields,$field);
- array_push($ivalues,$value);
- if(strcmp($fields[$field]['type'],'serial')==0 or
- strcmp($fields[$field]['type'],'int')==0){
- array_push($itypes,"%d");
- } else {
- array_push($itypes,"'%s'");
- }
- }
- $sql = "INSERT INTO {$table} (" . implode(", ",$ifields) . ") VALUES (". implode(", ",$itypes) .")";
- // finally perform the insert.
- if(db_query($sql,$ivalues)){
- return true;
- }
- else {
- watchdog('tripal_core',"tripal_core_chado_insert: Cannot insert record into $table table: " . print_r($values,1),array(),'WATCHDOG_ERROR');
- return false;
- }
- return false;
- }
- /**
- * Provides a generic routine for updating into any Chado table
- *
- * Use this function to update a record in any Chado table. The first
- * argument specifies the table for inserting, the second is an array
- * of values to matched for locating the record for updating, and the third
- * argument give the values to update. The arrays are mutli-dimensional such
- * that foreign key lookup values can be specified.
- *
- * @param $table
- * The name of the chado table for inserting
- * @param $match
- * An associative array containing the values for locating a record to update.
- * @param $values
- * An associative array containing the values for updating.
- *
- * @return
- * On success this function returns TRUE. On failure, it returns FALSE.
- *
- * Example usage:
- * @code
- $umatch = array(
- 'organism_id' => array(
- 'genus' => 'Citrus',
- 'species' => 'sinensis',
- ),
- 'uniquename' => 'orange1.1g000034m.g7',
- 'type_id' => array (
- 'cv_id' => array (
- 'name' => 'sequence',
- ),
- 'name' => 'gene',
- 'is_obsolete' => 0
- ),
- );
- $uvalues = array(
- 'name' => 'orange1.1g000034m.g',
- 'type_id' => array (
- 'cv_id' => array (
- 'name' => 'sequence',
- ),
- 'name' => 'mRNA',
- 'is_obsolete' => 0
- ),
- );
- * $result = tripal_core_chado_update('feature',$umatch,$uvalues);
- * @endcode
- * The above code species that a feature with a given uniquename, organism_id,
- * and type_id (the unique constraint for the feature table) will be updated.
- * The organism_id is specified as a nested array that uses the organism_id
- * foreign key constraint to lookup the specified values to find the exact
- * organism_id. The same nested struture is also used for specifying the
- * values to update. The function will find the record that matches the
- * columns specified and update the record with the avlues in the $uvalues array.
- *
- * @ingroup tripal_api
- */
- function tripal_core_chado_update($table,$match,$values){
- $update_values = array(); // contains the values to be updated
- $update_matches = array(); // contains the values for the where clause
-
- // get the table description
- $table_desc = module_invoke_all('chado_'.$table.'_schema');
- // get the values needed for matching in the SQL statement
- foreach ($match as $field => $value){
- if(is_array($value)){
- $results = tripal_core_chado_get_foreign_key($table_desc,$field,$value);
- if (sizeof($results) > 1) {
- watchdog('tripal_core', 'tripal_core_chado_update: When trying to find record to update, too many records match the criteria supplied for !foreign_key foreign key constraint (!criteria)', array('!foreign_key' => $field, '!criteria' => print_r($value,TRUE)), WATCHDOG_ERROR);
- } elseif (sizeof($results) < 1) {
- watchdog('tripal_core', 'tripal_core_chado_update: When trying to find record to update, no record matches criteria supplied for !foreign_key foreign key constraint (!criteria)', array('!foreign_key' => $field, '!criteria' => print_r($value,TRUE)), WATCHDOG_ERROR);
- } else {
- $update_matches[$field] = $results[0];
- }
- }
- else {
- $update_matches[$field] = $value;
- }
- }
- // get the values used for updating
- foreach ($values as $field => $value){
- if(is_array($value)){
- $results = tripal_core_chado_get_foreign_key($table_desc,$field,$value);
- if (sizeof($results) > 1) {
- watchdog('tripal_core', 'tripal_core_chado_update: When trying to find update values, too many records match the criteria supplied for !foreign_key foreign key constraint (!criteria)', array('!foreign_key' => $field, '!criteria' => print_r($value,TRUE)), WATCHDOG_ERROR);
- } elseif (sizeof($results) < 1) {
- watchdog('tripal_core', 'tripal_core_chado_update: When trying to find update values, no record matches criteria supplied for !foreign_key foreign key constraint (!criteria)', array('!foreign_key' => $field, '!criteria' => print_r($value,TRUE)), WATCHDOG_ERROR);
- } else {
- $update_values[$field] = $results[0];
- }
- }
- else {
- $update_values[$field] = $value;
- }
- }
- // now build the SQL statement
- $sql = "UPDATE {$table} SET ";
- $fields = $table_desc['fields'];
- $uargs = array();
- foreach($update_values as $field => $value){
- if(strcmp($fields[$field]['type'],'serial')==0 or
- strcmp($fields[$field]['type'],'int')==0){
- $sql .= " $field = %d, ";
- } else {
- $sql .= " $field = '%s', ";
- }
- array_push($uargs,$value);
- }
- $sql = substr($sql,0,-2); // get rid of the trailing comma & space
- $sql .= " WHERE ";
- foreach($update_matches as $field => $value){
- if(strcmp($fields[$field]['type'],'serial')==0 or
- strcmp($fields[$field]['type'],'int')==0){
- $sql .= " $field = %d AND ";
- } else {
- $sql .= " $field = '%s' AND ";
- }
- array_push($uargs,$value);
- }
- $sql = substr($sql,0,-4); // get rid of the trailing 'AND'
-
- // finally perform the update. If successful, return the updated record
- if(db_query($sql,$uargs)){
- return true;
- }
- else {
- watchdog('tripal_core',"Cannot update record in $table table. Match:" . print_r($match,1) . ". Values: ". print_r($values,1),array(),'WATCHDOG_ERROR');
- return false;
- }
- return false;
- }
- /**
- * Provides a generic routine for selecting data from a Chado table
- *
- * Use this function to perform a simple select from any Chado table.
- *
- * @param $table
- * The name of the chado table for inserting
- * @param $columns
- * An array of column names
- * @param $values
- * An associative array containing the values for filtering the results.
- * @param $has_record
- * Set this argument to 'true' to have this function return a numeric
- * value for the number of recrods rather than the array of records. this
- * can be useful in 'if' statements to check the presence of particula records.
- *
- * @return
- * A database query result resource, FALSE if the query was not executed
- * correctly, or the number of records in the dataset if $has_record is set.
- *
- * Example usage:
- * @code
- * $columns = array('feature_id','name');
- * $values = array(
- * 'organism_id' => array(
- * 'genus' => 'Citrus',
- * 'species' => 'sinensis',
- * ),
- * 'uniquename' => 'orange1.1g000034m.g',
- * 'type_id' => array (
- * 'cv_id' => array (
- * 'name' => 'sequence',
- * ),
- * 'name' => 'gene',
- * 'is_obsolete' => 0
- * ),
- * );
- * $result = tripal_core_chado_select('feature',$columns,$values);
- * @endcode
- * The above code selects a record from the feature table using the three fields
- * that uniquely identify a feature. The $columns array simply lists the columns
- * to select. 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_api
- */
- function tripal_core_chado_select($table,$columns,$values,$has_record = 0){
- if (!is_array($columns)){
- watchdog('tripal_feature', 'the $columns argument for tripal_core_chado_select must be an array.');
- return false;
- }
- if (!is_array($values)){
- watchdog('tripal_feature', 'the $values argument for tripal_core_chado_select must be an array.');
- return false;
- }
- // get the table description
- $table_desc = module_invoke_all('chado_'.$table.'_schema');
- $select = '';
- $from = '';
- $where = '';
- $args = array();
- foreach($values as $field => $value){
- $select[] = $field;
- if(is_array($value)){
- // select the value from the foreign key relationship for this value
- $results = tripal_core_chado_get_foreign_key($table_desc,$field,$value);
- if (sizeof($results) < 1) {
- // foreign key records are required
- // thus if none matched then return false and alert the admin through watchdog
- watchdog('tripal_core',
- 'tripal_core_chado_select: no record in the table referenced by the foreign key (!field) exists. tripal_core_chado_select table=!table, columns=!columns, values=!values',
- array('!table' => $table,
- '!columns' => '<pre>' . print_r($columns, TRUE) . '</pre>',
- '!values' => '<pre>' . print_r($values, TRUE) . '</pre>',
- '!field' => $field,
- ),
- WATCHDOG_WARNING);
- return false;
-
- } elseif (sizeof($results) == 1) {
- $where[$field] = $results[0];
- } else {
- $where[$field] = $results;
- }
- }
- else {
- $where[$field] = $value;
- }
- }
- // now build the SQL select statement
- if (empty($where)) {
- // sometimes want to select everything
- $sql = "SELECT " . implode(',',$columns) . " ";
- $sql .= "FROM {$table} ";
- } else {
- $sql = "SELECT " . implode(',',$columns) . " ";
- $sql .= "FROM {$table} ";
- $sql .= "WHERE ";
- foreach($where as $field => $value){
- if (is_array($value)) {
- $sql .= "$field IN (".db_placeholders($value,'varchar').") AND ";
- foreach ($value as $v) { $args[] = $v; }
- } else {
- $sql .= "$field = '%s' AND ";
- $args[] = $value;
- }
- }
- $sql = substr($sql,0,-4); // get rid of the trailing 'AND'
- }
- $resource = db_query($sql,$args);
- $results = array();
- while ($r = db_fetch_object($resource)) {
- $results[] = $r;
- }
-
- if(!$has_record){
- return $results;
- } else{
- return count($results);
- }
- }
- /**
- * Gets the value of a foreign key relationship
- *
- * This function is used by tripal_core_chado_select, tripal_core_chado_insert,
- * and tripal_core_chado_update to iterate through the associate array of
- * values that gets passed to each of those routines. The values array
- * is nested where foreign key contraints are used to specify a value that. See
- * documentation for any of those functions for further information.
- *
- * @param $table_desc
- * A table description for the table with the foreign key relationship to be identified generated by
- * hook_chado_<table name>_schema()
- * @param $field
- * The field in the table that is the foreign key.
- * @param $values
- * An associative array containing the values
- *
- * @return
- * A string containg the results of the foreign key lookup, or FALSE if failed.
- *
- * Example usage:
- * @code
- *
- * $values = array(
- * 'genus' => 'Citrus',
- * 'species' => 'sinensis',
- * );
- * $value = tripal_core_chado_get_foreign_key('feature','organism_id',$values);
- *
- * @endcode
- * The above code selects a record from the feature table using the three fields
- * that uniquely identify a feature. The $columns array simply lists the columns
- * to select. 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_api
- */
- function tripal_core_chado_get_foreign_key($table_desc,$field,$values){
- // get the list of foreign keys for this table description and
- // iterate through those until we find the one we're looking for
- $fkeys = $table_desc['foreign keys'];
- if($fkeys){
- foreach($fkeys as $name => $def){
- if (is_array($def['table'])) {
- //foreign key was described 2X
- $message = "The foreign key ".$name." was defined twice. Please check modules to determine if hook_chado_".$table_desc['table']."_schema() was implemented and defined this foreign key when it wasn't supposed to. Modules this hook was implemented in: ".implode(', ', module_implements("chado_".$table_desc['table']."_schema")).".";
- watchdog('tripal_core', $message);
- drupal_set_message($message,'error');
- continue;
- }
- $table = $def['table'];
- $columns = $def['columns'];
- // iterate through the columns of the foreign key relationship
- foreach($columns as $left => $right){
- // does the left column in the relationship match our field?
- if(strcmp($field,$left)==0){
- // the column name of the foreign key matches the field we want
- // so this is the right relationship. Now we want to select
- $select_cols = array($right);
- $result = tripal_core_chado_select($table,$select_cols,$values);
- $fields = array();
- foreach ($result as $obj) {
- $fields[] = $obj->$right;
- }
- return $fields;
- }
- }
- }
- }
- else {
- // TODO: what do we do if we get to this point and we have a fk
- // relationship expected but we don't have any definition for one in the
- // table schema??
- $message = "There is no foreign key relationship defined for ".$field.". To define a foreign key relationship, determine the table this foreign key referrs to (<foreign table>) and then implement hook_chado_<foreign table>_schema(). See tripal_feature_chado_feature_schema for an example.";
- watchdog('tripal_core', $message);
- drupal_set_message($message,'error');
- }
- return false;
- }
- /**
- * Generates an object containing the full details of a record(s) in chado.
- *
- * @todo Enable specified fields to be excluded by default. Fields can be selected based on
- * table.name or type and criteria
- * @todo Add expand_x arrays
- * @todo Ensure expand_x arrays appear only in the base object and are cumulative (contain fields
- * from all nested objects
- *
- * This differs from the objects returned by tripal_core_chado_select in so far as all foreign key
- * relationships have been followed meaning you have more complete details. Thus this function
- * should be used whenever you need a full variable and tripal_core_chado_select should be used if
- * you only case about a few columns.
- *
- * @param $table
- * The name of the base table to generate a variable for
- * @param $values
- * A select values array that selects the records you want from the base table
- * (this has the same form as tripal_core_chado_select)
- * @return
- * Either an object (if only one record was selected from the base table)
- * or an array of objects (if more than one record was selected from the base table).
- *
- * Example Usage:
- * @code
- $values = array(
- 'name' => 'Medtr4g030710'
- );
- $features = tripal_core_generate_chado_var('feature', $values);
- * @endcode
- * This will return an object of the following form if there is only one feature with the name
- * Medtr4g030710:
- * @code
-
- * @endcode
- * Or it will return an array of feature objects if more than one feature has that name:
- * @code
-
- * @endcode
- *
- * Note to Module Designers: Fields can be excluded by default from these objects by implementing
- * one of the following hooks:
- * - hook_exclude_field_from_tablename_by_default (where tablename is the name of the table):
- * This hook allows you to add fields to be excluded on a per table basis. Simply implement
- * this hook to return an array of fields to be excluded. For example:
- * @code
- mymodule_exclude_field_from_feature_by_default() {
- return array('residues');
- }
- * @endcode
- * will ensure that feature.residues is ecluded from a feature object by default.
- * - hook_exclude_type_by_default:
- * This hook allows you to exclude fields from all tables that are of a given postgresql field
- * type. Simply implement this hook to return an array of postgresql types mapped to criteria.
- * Then all fields of that type where the criteria supplied returns TRUE will be excluded from
- * any table. Tokens available in criteria are <field_value> and <field_name>. For example:
- * @code
- mymodule_exclude_type_by_default() {
- return array('text' => 'length(<field_value>) > 50');
- }
- * @endcode
- * will exclude all text fields with a length > 50. Thus if $feature.residues is longer than 50 * it will be excluded, otherwise it will be added.
- *
- * @ingroup tripal_api
- */
- function tripal_core_generate_chado_var($table, $values) {
-
- // get description for the current table
- $table_desc = module_invoke_all('chado_'.$table.'_schema');
- $table_primary_key = $table_desc['primary key'][0];
- $table_columns = array_keys($table_desc['fields']);
-
- // get the values for the record in the current table
- $results = tripal_core_chado_select($table, $table_columns, $values);
- foreach ($results as $key => $object) {
- // check if the current table maps to a node type
- // if this table is connected to a node there will be a chado_tablename table in drupal
- if (db_table_exists('chado_'.$table)) {
- // that has a foreign key to this one ($table_desc['primary key'][0]
- // and to the node table (nid)
- $sql = "SELECT %s, nid FROM chado_%s WHERE %s=%d";
- $mapping = db_fetch_object(db_query(
- $sql,
- $table_primary_key,
- $table,
- $table_primary_key,
- $object->{$table_primary_key}
- ));
- if ($mapping->{$table_primary_key}) {
- $object->nid = $mapping->nid;
- $object->expandable_nodes[] = $table;
- }
- }
-
- // recursively follow foreign key relationships nesting objects as we go
- 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
-
- // get the record from the foreign table
- $foreign_values = array($primary_key => $object->{$foreign_key});
- $foreign_object = tripal_core_generate_chado_var($foreign_table, $foreign_values);
-
- // add the foreign record to the current object in a nested manner
- $object->{$foreign_key} = $foreign_object;
- $object->{$foreign_key}->tablename = $foreign_table;
- }
- }
-
- // remove any fields based on exceptions hooks
-
- // Flatten expandable_x arrays so only in the bottom object
-
-
- $results[$key] = $object;
- }
-
- // check only one result returned
- if (sizeof($results) == 1) {
- // add results to object
- return $results[0];
- } elseif (!empty($results)) {
- return $results;
- } else {
- // no results returned
- watchdog('tripal_core',
- 'tripal_core_generate_chado_var for %table: No record matches criteria values:%values',
- array('%table'=>$table, '%values'=>print_r($values,TRUE)),
- WATCHDOG_ERROR
- );
- }
-
- }
- /**
- *
- *
- * @ingroup tripal_api
- */
- function tripal_core_expand_chado_vars () {
- }
|