Comments (1)
Answering my own question.
deleteNode() kills off all it's own children, so that part is easy.
Duplication... Wrote this and it seems to work for me:
`
public function duplicateBranch($id_node, $new_parent){
// fetch node and all decendants into an array.
$branch = $this->_db_retrieve($id_node, 0);
$idmap = array();
$idmap[0] = $new_parent;
foreach ($branch as $twig) {
// get all record data
$details = $this->getNodeData($twig[0]);
// remove system fields
unset ($details['tree_id'], $details['id'], $details['lft'], $details['rgt']);
// add new child.
$newtwig = $this->appendChild($idmap[$twig[1]], $details);
$idmap[$twig[0]] = $newtwig;
}
return $idmap[$id_node];
}
/* This function fetches a node and all it's decendents into a flat array.
Unlike getDecendents, this includes the parent id for each node.
By the nature of the search, each node's parents will be before it in the list
This will be slower than getDecendents as it does a query for each level.
*/
function _db_retrieve($id_node, $parent){
$r = array();
$r[] = array($id_node, $parent);
foreach ($this->getChildren($id_node) as $id_child) {
$r = array_merge($r, $this->_db_retrieve($id_child, $id_node));
}
return $r;
}
`
from baobab.
Related Issues (15)
- Vertebrates HOT 1
- Any plan to add PDO support? HOT 3
- Boabab build error
- View definition error
- Composer autoload fails on Linux
- How to create binary tree?
- How can we find the parent's last child? HOT 4
- Retrieve from tree to display a nav menu ? HOT 2
- Get all trees HOT 6
- SQL query: Error HOT 1
- Concurrent user
- Is there a node version about this? HOT 1
- Error with no detail on DeleteNode HOT 3
- Is there a way to rebuilding or repairing tree ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from baobab.