You are here

function _nodehierarchy_get_descendant_count in Node Hierarchy 6.3

Same name and namespace in other branches
  1. 6.2 nodehierarchy.module \_nodehierarchy_get_descendant_count()
  2. 7.2 nodehierarchy.module \_nodehierarchy_get_descendant_count()

Count the descendants of the given node.

File

./nodehierarchy.module, line 1230
A module to make nodes hierarchical.

Code

function _nodehierarchy_get_descendant_count($parent) {
  if ($plids = _nodehierarchy_get_node_mlids($parent)) {
    $where = array();
    $args = array();

    // Build all nine ORs to check if the plid is anywhere in the descendent paths.
    for ($i = 1; $i < MENU_MAX_DEPTH; $i++) {
      foreach ($plids as $plid) {
        $where[] = "p{$i} = %d";
        $args[] = $plid;
      }
    }

    // Add one more plid for the exclusion clause.
    $args[] = $plid;
    return db_result(db_query("SELECT count(mlid) as descendent_count FROM {menu_links} WHERE (" . implode(' OR ', $where) . ") AND mlid != %d AND module = 'nodehierarchy'", $args));
  }
  return 0;
}