function _nodehierarchy_normalize_child_order in Node Hierarchy 5
Same name and namespace in other branches
- 6 nodehierarchy.module \_nodehierarchy_normalize_child_order()
Normalize the order of the children of the given node.
2 calls to _nodehierarchy_normalize_child_order()
- nodehierarchy_insert_node in ./
nodehierarchy.module - Insert or update a node. Set it's parent
- nodehierarchy_movechild in ./
nodehierarchy.module - Move a child up or down by the given ammount.
File
- ./
nodehierarchy.module, line 901 - A module to make nodes hierarchical.
Code
function _nodehierarchy_normalize_child_order($parent_nid) {
if ($parent_nid !== NULL) {
$menu_changed = FALSE;
// Done either on insert or update of a hierarchy. we want to make order by
// values into integers to get in the updated one and remain consistent.
$result = db_query("SELECT * FROM {nodehierarchy} h WHERE h.parent = %d ORDER BY h.order_by ASC", $parent_nid);
$i = 1;
while ($hierarchy = db_fetch_object($result)) {
$hierarchy->order_by = $i;
$i++;
db_query("UPDATE {nodehierarchy} SET order_by = %d WHERE nid = %d", $hierarchy->order_by, $hierarchy->nid);
$menu_changed = _nodehierarchy_set_menu_order($parent_nid, $hierarchy->nid, $hierarchy->order_by) || $menu_changed;
}
if ($menu_changed) {
menu_rebuild();
}
}
}