You are here

function _draggableviews_rebuild_hierarchy in DraggableViews 7

Same name and namespace in other branches
  1. 6.3 draggableviews.inc \_draggableviews_rebuild_hierarchy()

Rebuild hierarchy

This function is called when the structure is broken.

Parameters

$info: The structured information array. Look at _draggableviews_info(..) to learn more.

1 call to _draggableviews_rebuild_hierarchy()
draggableviews_views_pre_render in ./draggableviews.module
Implements hook_views_pre_render

File

./draggableviews.inc, line 389
Draggableviews processing functions. Rough summary of what functions in this file do:

Code

function _draggableviews_rebuild_hierarchy(&$info) {

  // We backup the page settings and restore them after completing all operations.
  $pager = $info['view']->query->pager;
  if ($info['needs_pager_modifications']) {

    // We have to make sure that there's no hidden node with an order value that refers to the current page.
    // If the items to display per page are limitated we load the entire view.

    //@todo: We reduce the fields to a minimum because of performance issues.
    _draggableviews_reload_info($info, DRAGGABLEVIEWS_DBQUERY_LIMIT, 0, $pager->options['offset']);
  }

  // Calculate depth values.
  // Nodes with broken parents will be brought down to the root level.
  // These depth values will be used for both theming and repairing broken structures.
  _draggableviews_calculate_depths($info);

  // Detect and repair ordering errors.
  // The child node order values on the parent's level have to equal
  // with the parent's order values. If they don't equal they will be set properly.
  // In order to avoid ambiguous values we add unique float
  // values ($safe_offset < 1) to all order values. This assures that
  // child nodes always appear right after their parents even if there
  // are other nodes with the same order value on the parents level.
  $safe_offset = 0;
  foreach ($info['nodes'] as $nid => $values) {
    $info['nodes'][$nid]['order'][$values['depth']] += $safe_offset;
    $safe_offset += DRAGGABLEVIEWS_SAFE_OFFSET;
  }
  _draggableviews_check_order($info);

  // The last issue we have to deal with is the order itself.
  // We just sort the nodes by their current order values and
  // then we subsequently assign ascending numbers.
  _draggableviews_sort_nodes($info['nodes']);
  _draggableviews_ascending_numbers($info, $pager->options['offset'], TRUE);

  // Save hierarchy.
  _draggableviews_save_hierarchy($info);

  // The structure should be valid now.
  // Nonetheless let's make a final check for debugging reasons.
  if (!_draggableviews_quick_check_structure($info)) {
    drupal_set_message(t("Draggableviews: Rebuilding structure didn't work. The structure is broken."), "error");
  }
}