You are here

function book_copy_find_subtree in Book Copy 6

Given a book id and an optional subtree (nid) this function returns a list of node ids in book order that match the given criteria.

2 calls to book_copy_find_subtree()
book_copy_can_copy in ./book_copy.module
Given a book id and an optional subtree (nid) this function determines if the user can copy the given book.
book_copy_copy_book in ./book_copy.module
This function is intended to be called via drupals batch processing system and will clone an entire or partial book.

File

./book_copy.module, line 398

Code

function book_copy_find_subtree($bid, $subtree = 0) {
  $nodes = array();
  if (!empty($subtree)) {

    // only grab those nodes matching our sub-tree
    $mlid = db_result(db_query("SELECT ml.mlid FROM {menu_links} ml LEFT JOIN {book} b ON b.mlid = ml.mlid WHERE b.nid = %d", $subtree));
    $where = 'AND (ml.plid = %d OR ml.p1 = %d OR ml.p2 = %d OR ml.p3 = %d OR ml.p4 = %d OR ml.p5 = %d OR ml.p6 = %d OR ml.p7 = %d OR ml.p8 = %d OR ml.p9 = %d)';
    $args = array_fill(0, 10, $mlid);
    array_unshift($args, $bid);
  }
  else {
    $where = '';
    $args = array(
      $bid,
    );
  }
  $result = db_query("SELECT b.nid FROM {menu_links} ml LEFT JOIN {book} b ON b.mlid = ml.mlid WHERE b.bid = %d " . $where . " ORDER BY ml.depth, b.nid", $args);
  while ($nid = db_result($result)) {
    $nodes[] = $nid;
  }
  return $nodes;
}