0) { $message = str_replace(array_keys($variables), $variables, $message); } print $severity_string . ' (' . strtoupper($type) . '):' . $message . "\n"; } } /** * Get chado id for a node. E.g, if you want to get 'analysis_id' from the * 'analysis' table for a synced 'chado_analysis' node, (the same for * organisms and features): * $analysis_id = chado_get_id_for_node ('analysis', $node->nid) * $organism_id = chado_get_id_for_node ('organism', $node->nid) * $feature_id = chado_get_id_for_node ('feature', $node->nid) * * @param $table * @param $nid * * @ingroup tripal_chado_api */ function chado_get_id_for_node($table, $nid) { $sql = "SELECT " . $table . "_id as id FROM {chado_$table} WHERE nid = :nid"; return db_query($sql, array(':nid' => $nid))->fetchField(); } /** * Get node id for a chado feature/organism/analysis. E.g, if you want to * get the node id for an analysis, use: * $nid = chado_get_node_id ('analysis', $analysis_id) * Likewise, * $nid = chado_get_node_id ('organism', $organism_id) * $nid = chado_get_node_id ('feature', $feature_id) * * @ingroup tripal_chado_api */ function chado_get_node_id($table, $id) { $sql = "SELECT nid FROM {chado_$table} WHERE " . $table . "_id = :" . $table . "_id"; return db_query($sql, array(":" . $table . "_id" => $id))->fetchField(); } /** * Set the Tripal Database * * The tripal_db_set_active function is used to prevent namespace collisions * when chado and drupal are installed in the same database but in different * schemas. It is also used for backwards compatibility with older versions * of tripal or in cases where chado is located outside of the Drupal database. * or when using Drupal functions such as db_table_exists() * * @ingroup tripal_chado_api */ function tripal_db_set_active($dbname = 'default') { global $databases, $active_db; if ($dbname ) { if ($dbname == 'chado') { db_query('set search_path to chado,public'); return 'default'; } else { db_query('set search_path to public'); return 'chado'; } } // if the 'chado' database is in the $db_url variable then chado is // not in the same Drupal database, so we don't need to set any // search_path and can just change the database elseif (array_key_exists($dbname, $databases)) { return db_set_active($dbname); } } /** * Get max rank for a given set of criteria * This function was developed with the many property tables in chado in mind but will * work for any table with a rank * * @params tablename: the name of the chado table you want to select the max rank from * this table must contain a rank column of type integer * @params where_options: array( * => array( * 'type' => , * 'value' => , * 'exact' => , * ) * ) * where options should include the id and type for that table to correctly * group a set of records together where the only difference are the value and rank * @return the maximum rank * * @ingroup tripal_chado_api */ function tripal_core_get_max_chado_rank($tablename, $where_options) { $where_clauses = array(); $where_args = array(); //generate the where clause from supplied options // the key is the column name $i = 0; $sql = " SELECT max(rank) as max_rank, count(rank) as count FROM {".$tablename."} WHERE "; foreach ($where_options as $key => $value) { $where_clauses[] = "$key = :$key"; $where_args[":$key"] = $value; } $sql .= implode($where_clauses, ' AND '); $result = chado_query($sql, $where_args)->fetchObject(); if ($result->count > 0) { return $result->max_rank; } else { return -1; } } /** * Use this function to encapsulate text intended to be * visible only by the site administrator. A small tripal logo * appears alongside the text. Do not call this function directly, but * rather, use the theme() function: * * theme('tripal_admin_message', array('message' => $my_message)); * * @param $message * The message to be displayed to the site administrator * * @ingroup tripal_chado_api */ function theme_tripal_admin_message($variables) { $message = $variables['message']; if (!user_access('access administration pages')) { return ''; } return "
$message
"; }