You are here

function _draggableviews_book_result_set_weight in DraggableViews 7.2

Set the weight array of item.

1 call to _draggableviews_book_result_set_weight()
draggableviews_book_views_post_execute in draggableviews_book/draggableviews_book.module
Implements hook_views_post_execute().

File

draggableviews_book/draggableviews_book.module, line 71

Code

function _draggableviews_book_result_set_weight(&$item, $result) {

  // If weight is already calculated we simply return it.
  if (!empty($item->weight)) {
    return $item->weight;
  }

  // Load weights array of parent (if parent item is available).
  $parent_weight = array();
  if (isset($result[$item->draggableviews_book_plid])) {
    $parent_weight = _draggableviews_book_result_set_weight($result[$item->draggableviews_book_plid], $result);
  }

  // Set the weight as sum of parents weights and
  // its own weight according to depth.
  $item->weight = $parent_weight + array(
    $item->draggableviews_book_depth => $item->draggableviews_book_weight,
  );
  return $item->weight;
}