Ejemplo n.º 1
0
$id = $tree->getIdByPath('myElement');
dumpHelper('$tree->getChildren(' . $id . ')', 'dump the children of "myElement"');
// you can also use:    $tree->data[$id]['children']
$id = $tree->getIdByPath('myElement/subElement');
dumpHelper('$tree->getNext(' . $id . ')', 'dump the "next" of "myElement/subElement"', true);
// you can also use:    $tree->data[$id]['next']
$id = $tree->getIdByPath('myElement/anotherSubElement');
dumpHelper('$tree->getPrevious(' . $id . ')', 'dump the "previous" of "myElement/anotherSubElement"', true);
// you can also use:    $tree->data[$id]['previous']
$id = $tree->getIdByPath('myElement');
$element = $tree->data[$id]['child']['next']['parent'];
// refer to yourself again, in a very complicated way :-)
dumpHelper('$element[\'id\']', 'demo of using the internal array, for referencing tree-nodes, see the code');
$id = $tree->getIdByPath('myElement');
$element = $tree->data[$id]['child']['next'];
// refer to the second child of 'myElement'
dumpHelper('$element[\'id\']', 'demo2 of using the internal array, for referencing tree-nodes, see the code');
$id = $tree->getIdByPath('myElement/anotherSubElement');
$tree->move($id, 0);
$tree->setup();
// rebuild the structure again, since we had changed it
dumpAllNicely('dump all, after "myElement/anotherSubElement" was moved under the root');
$moveId = $tree->getIdByPath('myElement');
$id = $tree->getIdByPath('anotherSubElement');
$tree->move($moveId, $id);
$tree->setup();
// rebuild the structure again, since we had changed it
dumpAllNicely('dump all, after "myElement" was moved under the "anotherSubElement"');
$tree->setRemoveRecursively(true);
$tree->remove(0);
print '<font color="red">ALL ELEMENTS HAVE BEEN REMOVED (uncomment this part to keep them in the DB after running this test script)</font>';
Ejemplo n.º 2
0
// this means the entire tree is available at all time !!!
// consider the resource usage and it's not to suggested to work
// on huge trees (upto 1000 elements it should be ok, depending on your environment and requirements)
// using 'setupMemory'
$tree = Tree::setupMemory('DBnested', 'mysql://root@localhost/test', $options);
// pass the options we had assigned up there
// add a new root element in the tree
$rootId = $tree->add(array('name' => 'myElement'));
// add an element under the new element we added
$id = $tree->add(array('name' => 'subElement'), $rootId);
// add another element under the parent element we added
$id = $tree->add(array('name' => 'anotherSubElement'), $rootId, $id);
// call 'setup', to build the inner array, so we can work on the structure using the
// given methods
$tree->setup();
dumpAllNicely('dump all after creation');
// get the path of the last inserted element
dumpHelper('$tree->getPath( ' . $id . ' )', 'dump the path from "myElement/anotherSubElement"');
$id = $tree->getIdByPath('myElement/subElement');
dumpHelper('$tree->getParent(' . $id . ')', 'dump the parent of "myElement/subElement"', true);
// you can also use:    $tree->data[$id]['parent']
$id = $tree->getIdByPath('myElement');
dumpHelper('$tree->getChild(' . $id . ')', 'dump the child of "myElement"', true);
// you can also use:    $tree->data[$id]['child']
$id = $tree->getIdByPath('myElement');
dumpHelper('$tree->getChildren(' . $id . ')', 'dump the children of "myElement"');
// you can also use:    $tree->data[$id]['children']
$id = $tree->getIdByPath('myElement/subElement');
dumpHelper('$tree->getNext(' . $id . ')', 'dump the "next" of "myElement/subElement"', true);
// you can also use:    $tree->data[$id]['next']
$id = $tree->getIdByPath('myElement/anotherSubElement');
Ejemplo n.º 3
0
            simpletemplate/prefilter
*/
require_once 'Tree/Tree.php';
// calling 'setupMemory' means to retreive a class, which works on trees,
// that are temporarily stored in the memory, in an array
// this means the entire tree is available at all time
// consider the resource usage and it's not to suggested to work
// on huge trees (upto 1000 elements it should be ok, depending on your environment and requirements)
// using 'setupMemory'
$tree = Tree::setupMemory('XML', 'config.xml');
// methods 'add' 'remove' and so on are not implemented yet, you can only read the tree for now
// and navigate inside of it
// call 'setup', to build the inner array, so we can work on the structure using the
// given methods
$tree->setup();
dumpAllNicely('dump all after "$tree-&gt;setup"');
// get the path of the last inserted element
print 'id=' . ($id = $tree->getIdByPath('simpletemplate/options/delimiter'));
dumpHelper($tree->getPath($id), 'dump the path from "simpletemplate/options/delimiter"');
$id = $tree->getIdByPath('simpletemplate/options');
dumpHelper(array($tree->getParent($id)), 'dump the parent of "simpletemplate/options"');
// you can also use:    $tree->data[$id]['parent']
$id = $tree->getIdByPath('simpletemplate');
dumpHelper(array($tree->getChild($id)), 'dump the child of "simpletemplate"');
// you can also use:    $tree->data[$id]['child']
$id = $tree->getIdByPath('simpletemplate/prefilter');
dumpHelper($tree->getChildren($id), 'dump the children of "simpletemplate/prefilter"');
// you can also use:    $tree->data[$id]['children']
$id = $tree->getIdByPath('simpletemplate/options');
dumpHelper(array($tree->getNext($id)), 'dump the "next" of "simpletemplate/options"');
// you can also use:    $tree->data[$id]['next']