function _nodehierarchy_normalize_child_order in Node Hierarchy 6
Same name and namespace in other branches
- 5 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 954
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.
// Load list of NH-managed types.. so we can limit our work to nodes which matter.
$typelist = _nodehierarchy_get_types();
if (empty($typelist)) {
$query = "SELECT h.* FROM {nodehierarchy} h WHERE h.parent = %d ORDER BY h.order_by ASC";
$qparam = $parent_nid;
}
else {
$qplaceholders = db_placeholders($typelist, 'varchar');
$query = "SELECT h.* FROM {nodehierarchy} h join {node} n on h.nid=n.nid WHERE h.parent = %d AND n.type IN ({$qplaceholders}) ORDER BY h.order_by ASC";
$qparam = array_merge(array(
$parent_nid,
), $typelist);
}
$result = db_query($query, $qparam);
$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);
_nodehierarchy_set_menu_order($parent_nid, $hierarchy->nid, $hierarchy->order_by);
}
/*
if ($menu_changed) {
menu_rebuild();
}
*/
}
}