You are here

function _draggableviews_calculate_depths in DraggableViews 7

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

Calculate Depths

Nodes with broken parents will be brought down to the root level. Order values will be moved to the actual level. Order values of the next unused level will be set to the minimum value.

Parameters

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

Return value

TRUE if no errors occured.

2 calls to _draggableviews_calculate_depths()
draggableviews_views_pre_render in ./draggableviews.module
Implements hook_views_pre_render
_draggableviews_rebuild_hierarchy in ./draggableviews.inc
Rebuild hierarchy

File

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

Code

function _draggableviews_calculate_depths(&$info) {
  $error = FALSE;

  // Loop through all rows the view returned.
  foreach ($info['nodes'] as $nid => $prop) {
    if (!isset($info['nodes'][$nid]['parent']) || $info['nodes'][$nid]['parent'] < 0) {
      $info['nodes'][$nid]['parent'] = 0;
    }

    // Determine hierarchy depth of current row.
    $depth = _draggableviews_get_hierarchy_depth($nid, $info['nodes'], $info);
    if ($depth === FALSE) {
      $error = TRUE;
      $depth = 0;
      $info['nodes'][$nid]['parent'] = 0;
    }
    $info['nodes'][$nid]['depth'] = $depth;

    // Move the order value to the calculated level.
    if ($info['nodes'][$nid]['order'][0] > DRAGGABLEVIEWS_MIN_VALUE) {
      $info['nodes'][$nid]['order'][$depth] = $info['nodes'][$nid]['order'][0];
    }
    else {

      // The order value must be greater than the minimum value. Otherwise
      // children would appear above their parents.
      $info['nodes'][$nid]['order'][$depth] = DRAGGABLEVIEWS_MIN_VALUE + 1;
    }

    // Set the next level to the minimum value. Otherwise
    // it could happen that a child appears above its parent.
    $info['nodes'][$nid]['order'][$depth + 1] = DRAGGABLEVIEWS_MIN_VALUE;
    if ($depth > $info['depth']) {
      $info['depth'] = $depth;
    }
  }
  return !$error;
}