public function catTree() { //create the model object /* * INGAT !! parent_id di mysql harus bisa negatif jangan unsigned */ $cal = new ProdCat(); //tentukan field untuk parent nya.. $cal->parentID = "cat_parent_id"; //tentukan field untuk namanya nya.. $cal->nameID = "cat_name"; //what to print in box $cal->printToEditBox = array("cat_name" => array("text", "not_empty"), "cat_metatitle" => array("text", "not_empty"), "cat_metadesc" => array("text", "not_empty"), "cat_metatag" => array("text", "not_empty")); //send the webclass $webClass = __CLASS__; //run the crud utility TreeStructure::run($cal, $webClass, __FUNCTION__); }
<? require_once("tree.php"); $tree = new TreeStructure(); $tree->addRoot("root","testRoot"); var_dump($tree->insertRootChild("child","firstChild")); var_dump($tree->insertRootChild("child","secondChild")); var_dump($tree->insertChild("child2","firstGrandChild",$tree->getRoot()->getChildAt(0))); var_dump($tree->insertChild("child2","secondGrandChild",$tree->getRoot()->getChildAt(0))); var_dump($tree->insertChild("child3","xFirstGrandChild",$tree->getRoot()->getChildAt(0)->getChildAt(1))); var_dump($tree->insertChild("child4","xxFirstGrandChild",$tree->getRoot()->getChildAt(0)->getChildAt(1)->getChildAt(0))); var_dump($tree->insertChild("child4","xxSecondGrandChild",$tree->getRoot()->getChildAt(0)->getChildAt(1)->getChildAt(0))); var_dump($tree); var_dump($tree->getRoot()->getChildren()); echo "==============================="; var_dump($tree->getRoot()->getChild("child","secondChild")); var_dump($tree->getRoot()->hasChildren()); //var_dump($tree->getRoot()->getChildAt(0)->getChildren()); var_dump($tree->getRoot()->getChildAt(0)->getChildAt(1)->getChildren()); //var_dump($tree->getRoot()->getChildAt(1)->hasChildren()); echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; $tree->findChild("child3","xFirstGrandChild",$tree->getRoot()); var_dump($tree->getChildFound()); $tree->insertChild("child4","xyfirstGrandChild",$tree->getChildFound()); $tree->getNodesByDepth(4,$tree->getRoot()); var_dump($tree->getChildsByDepth());
public static function printTreeRecursive($startNode, $anak2, $object, $t) { $arr = $object->printToEditBox; $namaID = $object->nameID; //$t = time().rand(0,10); if (count($anak2[$startNode]) > 0) { $t2 = time() . rand(0, 1000); ?> <ul id="rek_<?php echo $t2; ?> "> <?php foreach ($anak2[$startNode] as $n => $o) { //get the main id $menu_id = $o->main_id; $arrDikirim = array(); foreach ($arr as $n1 => $v) { $arrDikirim[$n1] = $o->{$n1}; } $str = base64_encode(json_encode($arrDikirim)); ?> <li id="<?php echo $t . "_" . $o->{$menu_id}; ?> " class="tree_item tree_item_drag"> <span ondblclick='printToEditBox_<?php echo $t; ?> ("<?php echo $str; ?> ","<?php echo $o->{$menu_id}; ?> ");'><?php echo $o->{$namaID}; ?> </span> <?php TreeStructure::printTreeRecursive($o->{$menu_id}, $anak2, $object, $t); ?> </li> <?php } ?> </ul> <script> $(document).ready(function(){ $('#rek_<?php echo $t2; ?> ').sortable(); $( "#rek_<?php echo $t2; ?> " ).disableSelection(); }); </script> <?php } }