print_r($identifiers, TRUE) ) ); } elseif (empty($identifiers)) { tripal_report_error( 'tripal_organism_api', TRIPAL_ERROR, "tripal_get_organism: 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( '%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']); $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, "tripal_get_organism: The identifiers you passed in were not unique. You passed in %identifier.", array( '%identifier'=> print_r($identifiers, TRUE) ) ); } // Report an error if $organism is FALSE since then chado_generate_var has failed elseif ($organism === FALSE) { tripal_report_error( 'tripal_organism_api', TRIPAL_ERROR, "tripal_get_organism: 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( '%identifier'=> print_r($identifiers, TRUE) ) ); } // Else, as far we know, everything is fine so give them their organism :) else { return $organism; } } /** * Returns a list of organisms that are currently synced with Drupal to use in select lists * * @param $syncd_only * Whether or not to return all chado organisms or just those sync'd with drupal. Defaults * to TRUE (only sync'd organisms) * @return * An array of organisms sync'd with Drupal where each value is the organism scientific * name and the keys are organism_id's * * @ingroup tripal_organism_api */ function tripal_get_organism_select_options($syncd_only = TRUE) { if ($syncd_only) { // use this SQL for getting synced organisms $dsql = "SELECT * FROM {chado_organism}"; $orgs = db_query($dsql); // use this SQL statement for getting the organisms $csql = "SELECT * FROM {organism} " . "WHERE organism_id = :organism_id"; $org_list = array(); // iterate through the organisms and build an array of those that are synced foreach ($orgs as $org) { $args = array(':organism_id' => $org->organism_id); $org = chado_query($csql, $args)->fetchObject(); $org_list[$org->organism_id] = $org->genus . ' ' . $org->species; } } else { // use this SQL statement for getting the organisms $csql = "SELECT * FROM {organism}"; $orgs = chado_query($csql)->execute(); $org_list = array(); // iterate through the organisms and build an array of those that are synced foreach ($orgs as $org) { $org_list[$org->organism_id] = $org->genus . ' ' . $org->species; } } return $org_list; } /** * Return the URL for the organism image * * @param $organism * An organism table record * @param $nid * (Optional) the node id of the organism node. if not supplied it will be looked up * * @return * The fully qualified url to the image */ function tripal_get_organism_image($organism, $nid = NULL) { $url = ''; // first look for an image with the genus/species name. This is old-style tripal // and we keep it for backwards compatibility. If we don't find that file // then look for the image with the node ID in the name. If we don't find that then // no image tag is generated $base_path = realpath('.'); $image_dir = tripal_get_files_dir('tripal_organism') . "/images"; $image_name = $organism->genus . "_" . $organism->species . ".jpg"; if (file_exists("$base_path/$image_dir/$image_name")) { $url = file_create_url("$image_dir/$image_name"); } else { $image_name = $nid . ".jpg"; if (file_exists("$base_path/$image_dir/$image_name")) { $url = file_create_url("$image_dir/$image_name"); } } return $url; }