function _draggableviews_build_hierarchy in DraggableViews 7
Same name and namespace in other branches
- 6.3 draggableviews.inc \_draggableviews_build_hierarchy()
Build hierarchy
Although there shouldn't be any structure based errors after submit broken parents can be detected and repaired. All other structure based errors can not be detected. If there are any they will be detected by _draggableviews_quick_check_structure(..) and finally repaired by _draggableviews_analyze_structure(..).
Parameters
$info: The structured information array
1 call to _draggableviews_build_hierarchy()
- draggableviews_view_draggabletable_form_submit in ./
draggableviews.module - Implements hook_submit().
File
- ./
draggableviews.inc, line 247 - Draggableviews processing functions. Rough summary of what functions in this file do:
Code
function _draggableviews_build_hierarchy(&$info) {
$nodes =& $info['nodes'];
$input =& $info['input'];
foreach ($nodes as $nid => $prop) {
// get depth
if (($depth = _draggableviews_get_hierarchy_depth($nid, $input, $info)) === FALSE) {
// Error! The hierarchy structure is broken and could
// look like the following: (we're currently processing X)
// A
// --X
// --D
//
// The next steps:
// 1) bring it down to the root level
// 2) Set order fields to the minimum
$input[$nid]['parent'] = 0;
// We gracefully sidestep the order-loop
$depth = -1;
}
// Let's take a look at the following expample, to understand
// what is beeing done.
//
// A
// --B
// --C
// --X
// --D
// E
// Imagine we're currently processing X:
//
// We know that X is in depth=3, so we save the received
// weight value in the 3rd order field of node X.
//
// The 2nd order field must inherit the received weight of
// node C (the next parent). And the 1st order field must
// inherit the received weight of node A (the parent of C).
//
// When we finally order the view by weight1, weight2, weight3 then
// weight1 and weight2 from node X will always equal with
// those from node A and B, and weight3 defines the order of the 3rd level.
$temp_nid = $nid;
for ($i = $depth; $i >= 0; $i--) {
// we're operating top-down, so we determine the parents nid by the way
$nodes[$nid]['order'][$i] = $input[$temp_nid]['order'][0];
if (isset($info['hierarchy']) && $i > 0) {
if (!($temp_nid = $input[$temp_nid]['parent'])) {
// this line should never be reached assumed the depth
// was calculated correctly.
drupal_set_message(t('Undefined State called in draggableviews_build_hierarchy(..)'), 'error');
break;
}
}
}
if (isset($info['hierarchy'])) {
// Simply set the parent value
$nodes[$nid]['parent'] = $input[$nid]['parent'];
}
// Now set the next level to the minimum value. Otherwise
// it could happen that a child appears above its parent.
// The ? can be anything, unfortunately also > 5
//
// --A (3,5)
// B (3,?)
//
// To guaranteer that the ? is always the lowest, we choose
// the minimum.
$depth = $depth == -1 ? 0 : $depth;
$nodes[$nid]['order'][$depth + 1] = DRAGGABLEVIEWS_MIN_VALUE;
$nodes[$nid]['depth'] = $depth;
}
// Last but not least sort nodes and finally assign ascending numbers.
// This is necessary since this module supports paging.
_draggableviews_sort_nodes($nodes);
// calculate views page offset
$pager = $info['view']->query->pager;
$items_per_page = isset($pager->options['items_per_page']) ? $pager->options['items_per_page'] : 0;
$offset = $items_per_page * $pager->current_page + $pager->options['offset'];
_draggableviews_ascending_numbers($info, $offset, TRUE);
}