You are here

function search_api_glossary_sort_glossary in Search API AZ Glossary 7.3

Same name and namespace in other branches
  1. 7 search_api_glossary.module \search_api_glossary_sort_glossary()
  2. 7.2 search_api_glossary.module \search_api_glossary_sort_glossary()

Sorts by A-Z then 0-9 and then # weight.

1 string reference to 'search_api_glossary_sort_glossary'
search_api_glossary_facetapi_sort_info in ./search_api_glossary.module
Implements hook_facetapi_sort_info().

File

./search_api_glossary.module, line 238
Search api glossary module file.

Code

function search_api_glossary_sort_glossary(array $a, array $b) {
  $a_value = isset($a['#indexed_value']) ? $a['#indexed_value'] : '';
  $b_value = isset($b['#indexed_value']) ? $b['#indexed_value'] : '';
  if ($a_value == $b_value) {
    return 0;
  }
  elseif (ctype_alpha($a_value) && ctype_alpha($b_value)) {
    return $a_value < $b_value ? -1 : 1;
  }
  elseif (($a_value == "#" || $a_value == "0-9") && ctype_alpha($b_value)) {
    return 1;
  }
  elseif (ctype_alpha($a_value) && ($b_value == "#" || $b_value == "0-9")) {
    return -1;
  }
  elseif ($a_value == "#" && $b_value == "0-9") {
    return 1;
  }
  elseif ($b_value == "0-9" && $a_value == "#") {
    return -1;
  }
}