You are here

function _draggableviews_get_hierarchy_depth in DraggableViews 7

Same name and namespace in other branches
  1. 6.3 draggableviews.inc \_draggableviews_get_hierarchy_depth()
  2. 6 draggableviews.inc \_draggableviews_get_hierarchy_depth()
  3. 6.2 draggableviews.inc \_draggableviews_get_hierarchy_depth()

Get Hierarchy Depth

This function detects broken parents. Cycles are detected (if a child is the parent of its parent).

Parameters

$nid: The nid of the node which should be processed.

$nodes: The nodes array. This can be both a nodes array or an input array. They share the same hierarchy properties.

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

Return value

The hierarchy depth if no occured, else FALSE.

2 calls to _draggableviews_get_hierarchy_depth()
_draggableviews_build_hierarchy in ./draggableviews.inc
Build hierarchy
_draggableviews_calculate_depths in ./draggableviews.inc
Calculate Depths

File

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

Code

function _draggableviews_get_hierarchy_depth($nid, $nodes, $info) {
  if (!isset($info['hierarchy'])) {
    return 0;
  }
  $depth = 0;
  $error = FALSE;
  $temp_nid = $nid;
  $used_nids = array(
    $temp_nid,
  );
  while (!($error = !isset($nodes[$temp_nid])) && ($temp_nid = $nodes[$temp_nid]['parent']) > 0) {

    // In order to detect cycles we use an array,
    // where all used nids are saved in. If a node id
    // occurs twice -> return FALSE.
    $cycle_found = array_search($temp_nid, $used_nids);

    // The isset(..) is necessary because in PHP-Versions <= 4.2.0 array_search() returns NULL
    // instead of FALSE if $temp_nid was not found.
    if (isset($cycle_found) && $cycle_found !== FALSE) {
      drupal_set_message(t("Draggableviews: A cycle was found."));
      return FALSE;
    }
    $used_nids[] = $temp_nid;
    $depth++;
  }
  if ($error) {

    // If loop breaked caused by an error.
    return FALSE;
  }
  return $depth;
}