123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <?php
- function tripal_get_organism($identifiers, $options = array()) {
-
- if (!isset($options['include_fk'])) {
-
- $options['include_fk'] = array();
- }
-
- if (!is_array($identifiers)) {
- tripal_report_error(
- 'tripal_organism_api',
- TRIPAL_ERROR,
- "tripal_get_organism: 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)
- )
- );
- }
- 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 (isset($identifiers['property'])) {
- $property = $identifiers['property'];
- unset($identifiers['property']);
- $organism = chado_get_record_with_property('organism', $property, $identifiers, $options);
- }
-
- else {
-
- $organism = chado_generate_var(
- 'organism',
- $identifiers,
- $options
- );
- }
-
- 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)
- )
- );
- }
-
- 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 {
- return $organism;
- }
- }
- function tripal_get_organism_select_options($syncd_only = TRUE) {
- if ($syncd_only) {
-
- $dsql = "SELECT * FROM {chado_organism}";
- $orgs = db_query($dsql);
-
- $csql = "SELECT * FROM {organism} " .
- "WHERE organism_id = :organism_id";
- $org_list = array();
-
- 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 {
-
- $csql = "SELECT * FROM {organism}";
- $orgs = chado_query($csql)->execute();
- $org_list = array();
-
- foreach ($orgs as $org) {
- $org_list[$org->organism_id] = $org->genus . ' ' . $org->species;
- }
- }
- return $org_list;
- }
- function tripal_get_organism_image($organism, $nid = NULL) {
- $url = '';
-
-
-
-
- $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;
- }
|