function chado_sort_tokens_by_location

2.x tripal_core.chado_nodes.title_and_path.api.inc chado_sort_tokens_by_location($tokenA, $tokenB)
3.x tripal_core.chado_nodes.title_and_path.inc chado_sort_tokens_by_location($tokenA, $tokenB)

This sorts tokens first by depth (ie: stock.* is before stock.*>subtable.*) and then alphabetically within a level (ie: stock.name comes before stock.type_id)

This is a usort callback and shouldn't be called directly. To use: usort($tokens, 'chado_sort_tokens_by_location');

1 string reference to 'chado_sort_tokens_by_location'
chado_node_format_tokens in tripal_core/api/tripal_core.chado_nodes.title_and_path.api.inc
Format a set of tokens for consistent display

File

tripal_core/api/tripal_core.chado_nodes.title_and_path.api.inc, line 1508
Contains API functions to set titles and paths for all chado nodes

Code

function chado_sort_tokens_by_location($tokenA, $tokenB) {

  // First check if they're the same
  if ($tokenA['location'] == $tokenB['location']) {
    return 0;
  }

  // Then check if there's a difference in depth
  // For example, "stock > type_id" comes before "stock > type_id > name"
  $tokenA_depth = substr_count($tokenA['location'], '>');
  $tokenB_depth = substr_count($tokenB['location'], '>');
  if ($tokenA_depth != $tokenB_depth) {
    return ($tokenA_depth < $tokenB_depth) ? -1 : 1;
  }

  // If the depth is equal then just use alphabetical basic string compare
  return ($tokenA['location'] < $tokenB['location']) ? -1 : 1;
}