function _custom_breadcrumbs_sort_cmp in Custom Breadcrumbs 7.2
Same name and namespace in other branches
- 6.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
object $bc1: First breadcrumb object.
object $bc2: Second breadcrumb object.
Return value
int 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 140 - 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 (!empty($bc1->{$options[0]}) && !empty($bc2->{$options[0]}) && $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];
}