function _draggableviews_book_uasort in DraggableViews 7.2
Custom sort callback based on weights arrays.
1 string reference to '_draggableviews_book_uasort'
- draggableviews_book_views_post_execute in draggableviews_book/
draggableviews_book.module - Implements hook_views_post_execute().
File
- draggableviews_book/
draggableviews_book.module, line 93
Code
function _draggableviews_book_uasort($item1, $item2) {
for ($i = 0; $i < 10; $i++) {
// Item 1 is less than item 2.
if (isset($item1->weight[$i]) && !isset($item2->weight[$i])) {
return 1;
}
// Item 2 is less than item 1.
if (!isset($item1->weight[$i]) && isset($item2->weight[$i])) {
return -1;
}
if (isset($item1->weight[$i]) && isset($item2->weight[$i])) {
if ($item1->weight[$i] != $item2->weight[$i]) {
return $item1->weight[$i] < $item2->weight[$i] ? -1 : 1;
}
elseif (isset($item1->weight[$i + 1]) || isset($item2->weight[$i + 1])) {
// Loop again as there are more weights at a greater depth to compare.
continue;
}
else {
// By elimination, we know the weight and depth are the same. Sort by title.
return strcmp($item1->node_title, $item2->node_title);
}
}
}
}