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 analysis you want. The identifier is expected to be an array with the key matching a column name in the analysis table (ie: stock_id or name). You passed in %identifier.", [ '%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( ['table' => 'analysis', 'base_records' => $identifiers], ['type_name' => $property] ); } // Else we have a simple case and we can just use chado_generate_var to get // the analysis. else { // 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, "chado_get_analysis: The identifiers you passed in were not unique. You passed in %identifier.", [ '%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, "chado_get_analysis: 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.", [ '%identifier' => print_r($identifiers, TRUE), ] ); } // Else, as far we know, everything is fine so give them their analysis :) else { return $analysis; } } /** * Returns a list of analyses that are currently synced with Drupal to use in * select lists. * * @param $syncd_only * Whether or not to return all chado analyses or just those sync'd with * drupal. Defaults to TRUE (only sync'd analyses). * * @return * An array of analyses sync'd with Drupal where each value is the analysis * scientific name and the keys are analysis_id's. * * @ingroup tripal_analysis_api */ function chado_get_analysis_select_options($syncd_only = TRUE) { $analysis_list = []; $analysis_list[] = 'Select an analysis'; if ($syncd_only) { $sql = " SELECT * FROM [chado_analysis] CA INNER JOIN {analysis} A ON A.analysis_id = CO.analysis_id ORDER BY A.name "; $analyses = chado_query($sql); // iterate through the analyses and build an array of those that are synced. foreach ($analyses as $analysis) { $analysis_list[$analysis->analysis_id] = $analysis->name; } } else { // use this SQL statement for getting the analyses $csql = "SELECT * FROM {analysis} ORDER BY name"; $analyses = chado_query($csql); // iterate through the analyses and build an array of those that are synced. foreach ($analyses as $analysis) { $analysis_list[$analysis->analysis_id] = $analysis->name; } } return $analysis_list; }