Giter VIP home page Giter VIP logo

Comments (1)

irrelevantdotcom avatar irrelevantdotcom commented on July 19, 2024 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.