You are here

function _custom_breadcrumbs_sort_cmp in Custom Breadcrumbs 6.2

Same name and namespace in other branches
  1. 7.2 custom_breadcrumbs.admin.inc \_custom_breadcrumbs_sort_cmp()

Sorts two custom_breadcrumbs objects by name, type, or language.

Each column can be independently sorted as asc or desc.

Parameters

$bc1: First breadcrumb object.

$bc2: Second breadcrumb object.

Return value

0 if the two objects have equal ranking, 1 if the first object is greater than the second, -1 if the second object is greater than the first,

1 string reference to '_custom_breadcrumbs_sort_cmp'
custom_breadcrumbs_page in ./custom_breadcrumbs.admin.inc
Lists all current custom breadcrumbs and provides a link to the edit page.

File

./custom_breadcrumbs.admin.inc, line 112
Admin page callback file for the custom_breadcrumbs module.

Code

function _custom_breadcrumbs_sort_cmp($bc1, $bc2) {
  $custom_breadcrumbs_sort = variable_get('custom_breadcrumbs_sort', array(
    'direction' => array(
      'name' => 'asc',
      'breadcrumb_type' => 'asc',
      'language' => 'asc',
    ),
    'column' => 'name',
  ));
  $options = array(
    'name',
    'breadcrumb_type',
    'language',
  );
  $first = $custom_breadcrumbs_sort['column'];
  $keys = array_keys($options, $first);
  $key = array_pop($keys);
  unset($options[$key]);

  // Reindex the array.
  $options = array_values($options);
  $sortdir = array();
  foreach ($custom_breadcrumbs_sort['direction'] as $key => $sort) {
    $sortdir[$key] = $sort == 'asc' ? 1 : -1;
  }
  if ($bc1->{$first} == $bc2->{$first}) {
    if ($bc1->{$options}[0] == $bc2->{$options}[0]) {
      if ($bc1->{$options}[1] == $bc2->{$options}[1]) {
        return 0;
      }
      return $bc1->{$options}[1] > $bc2->{$options}[1] ? $sortdir[$options[1]] : -1 * $sortdir[$options[1]];
    }
    return $bc1->{$options}[0] > $bc2->{$options}[0] ? $sortdir[$options[0]] : -1 * $sortdir[$options[0]];
  }
  return $bc1->{$first} > $bc2->{$first} ? $sortdir[$first] : -1 * $sortdir[$first];
}