Tripal v1.0 (6.x-1.0)
|
00001 <?php 00007 00008 // Module: tripal_core 00010 00011 /************************************************************************* 00012 * Purpose: Get max rank for a given set of criteria 00013 * This function was developed with the many property tables in chado in mind 00014 * 00015 * @params tablename: the name of the chado table you want to select the max rank from 00016 * this table must contain a rank column of type integer 00017 * @params where_options: array( 00018 * <column_name> => array( 00019 * 'type' => <type of column: INT/STRING>, 00020 * 'value' => <the value you want to filter on>, 00021 * 'exact' => <if TRUE use =; if FALSE use ~>, 00022 * ) 00023 * ) 00024 * where options should include the id and type for that table to correctly 00025 * group a set of records together where the only difference are the value and rank 00026 * @return the maximum rank 00027 * 00028 */ 00029 function get_max_chado_rank($tablename, $where_options) { 00030 00031 $where= array(); 00032 //generate the where clause from supplied options 00033 // the key is the column name 00034 foreach ($where_options as $key => $val_array) { 00035 if (preg_match('/INT/', $val_array['type'])) { 00036 $where[] = $key . "=" . $val_array['value']; 00037 } 00038 else { 00039 if ($val_array['exact']) { 00040 $operator='='; } 00041 else { $operator='~'; } 00042 $where[] = $key . $operator . "'" . $val_array['value'] . "'"; 00043 } 00044 } 00045 00046 $result = db_fetch_object(chado_query( 00047 "SELECT max(rank) as max_rank, count(rank) as count FROM %s WHERE %s", 00048 $tablename, 00049 implode(' AND ', $where) 00050 )); 00051 //drupal_set_message("Max Rank Query=SELECT max(rank) as max_rank, count(rank) as count FROM ".$tablename." WHERE ".implode(' AND ',$where)); 00052 if ($result->count > 0) { 00053 return $result->max_rank; 00054 } 00055 else { 00056 return -1; 00057 } 00058 }