You are here

function hs_book_hierarchical_select_children in Hierarchical Select 5.3

Implementation of hook_hierarchical_select_children().

1 call to hs_book_hierarchical_select_children()
hs_book_hierarchical_select_root_level in modules/hs_book.module
Implementation of hook_hierarchical_select_root_level().

File

modules/hs_book.module, line 109
Implementation of the Hierarchical Select API for the Book module.

Code

function hs_book_hierarchical_select_children($parent, $params) {

  // TRICKY: because the book form assumes that the value "0" corresponds to
  // the <top-level page> option (for creating a new menu item at the root
  // level) *AND* 0 is also a pseudo-value in the actual hierarchy (it
  // represents the root), we have to pretend in the code that -1 is the root
  // in the hierarchy instead of 0.
  if ($parent == 0) {
    return array();
  }
  if ($parent == -1) {
    $parent = 0;
  }
  $result = db_query(db_rewrite_sql('SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND b.parent = %d ORDER BY b.weight, n.title'), $parent);
  $children = array();
  while ($node = db_fetch_object($result)) {

    // Don't include the given book page in the hierarchy!
    if (isset($params['nid']) && $params['nid'] == $node->nid) {
      continue;
    }
    $children[$node->nid] = $node->title;
  }
  return $children;
}