Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 0.72 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. cakephp Tree behavior remove parent node except children
  2. <Node A>
  3.     - child 1 node A
  4.     - child 2 node A
  5.     - child 3 node A
  6.     - <Node B> (which is also a child 4 of Node A)
  7.         - child 1 node B
  8.         - child 2 node B
  9.        
  10. SELECT * FROM items WHERE left > (parent's left) AND right < (parent's right) AND right = left + 1 AND parent_id = (parent's ID)
  11.        
  12. $children = <call TreeBehavior children() method with $id = id of Node A and $direct = true>;
  13. $children_without_children = array();
  14. foreach ($children as $child) {
  15.     if (<call TreeBehavior childCount() method with $id = $child->id and $direct = true> === 0) {
  16.         $children_without_children[] = $child;
  17.     }
  18. }
  19.        
  20. $this->Node->removeFromTree($id, true);