$root=new Root; $root->title='Mobile Phones'; $root->saveNode(); $root=new Root; $root->title='Cars'; $root->saveNode();
where is the Root Class?
Can you give a example? TKS~

Posted 18 July 2011 - 10:57 PM
$root=new Root; $root->title='Mobile Phones'; $root->saveNode(); $root=new Root; $root->title='Cars'; $root->saveNode();
Posted 19 July 2011 - 01:19 PM
lees, on 18 July 2011 - 10:57 PM, said:
$root=new Root; $root->title='Mobile Phones'; $root->saveNode(); $root=new Root; $root->title='Cars'; $root->saveNode();
$root=new Root
$root=new Category
Posted 03 September 2011 - 08:23 AM
Posted 03 September 2011 - 08:56 AM
Posted 03 September 2011 - 10:04 AM
public function getTreeViewData($rootNodeId = null, $isReturnRootNode = true){ $keyField = 'id'; if ($rootNodeId == null) $rawTree = $this->getTreeWithoutManyRoots(); else $rawTree = $this->getTreeWithManyRoots($rootNodeId); // Init variables needed for the array conversion $tree = array(); $node =& $tree; $position = array(); $lastitem = ''; $depth = 1; foreach($rawTree as $rawItem){ // If its a deeper item, then make it subitems of the current item if ($rawItem->getLevelValue() > $depth) { $position[] =& $node; //$lastitem; $depth = $rawItem->getLevelValue(); $node =& $node[$lastitem]['children']; } // If its less deep item, then return to a level up else { while ($rawItem->getLevelValue() < $depth) { end($position); $node =& $position[key($position)]; array_pop($position); $depth = $node[key($node)]['node']->getLevelValue(); } } // Add the item to the final array $node[$rawItem->$keyField]['node'] = $rawItem; $node[$rawItem->$keyField]['id'] = (int) 'node'.$rawItem->owner->id; $node[$rawItem->$keyField]['text'] = (string) $rawItem->owner->name; // save the last items' name $lastitem = $rawItem->$keyField; } // we don't care about the root node if (!$isReturnRootNode){ reset($tree); $tree = $tree[key($tree)]['children']; //array_shift($tree); } return $tree; } protected function getTreeWithoutManyRoots(){ $owner=$this->getOwner(); return $owner->findAll(array('order'=>$this->hasManyRoots ?$this->rootAttribute . ', ' . $this->leftAttribute :$this->leftAttribute)); } protected function getTreeWithManyRoots($rootId){ $owner=$this->getOwner(); return $owner->findAll( array( 'condition' => $this->rootAttribute.'=:rootId', 'order'=>$this->leftAttribute, 'params' => array(':rootId'=>$rootId) )); } protected function hasChildNodes(){ return $this->getLeftValue() != ($this->getRightValue() - 1); } protected function getLeftValue(){ $fieldName = $this->leftAttribute; $owner=$this->getOwner(); return $owner->$fieldName; } protected function getRightValue(){ $fieldName = $this->rightAttribute; $owner=$this->getOwner(); return $owner->$fieldName; } protected function getLevelValue(){ $fieldName = $this->levelAttribute; $owner=$this->getOwner(); return $owner->$fieldName; } protected function getRootValue(){ $fieldName = $this->rootAttribute; $owner=$this->getOwner(); return $owner->$fieldName; }
Posted 22 September 2011 - 11:09 AM
/** * Build the path to node(s) * @param string $column name of model attribute column * @param string $option accept all|leafs|branches|this * @param bool $inclRoot include root to part * @param string $separator path separator * @return array list of paths */ public function paths($column, $option = 'this', $inclRoot = TRUE, $separator = ' • ') { $result = NULL; if ($option == 'this') { $path = NULL; foreach ($this->ancestors()->findAll(array('order' => $this->leftAttribute)) as $node) { $path[] = $node->attributes[$column]; } if ($inclRoot) { $result[$node->primaryKey] = implode($separator, $path); } else { $result[$node->primaryKey] = implode($separator, array_slice($path, 1, count($path))); } } elseif (in_array ($option, array('all','branches','leafs'))) { $nodes = $this->findAll(array('order' => $this->leftAttribute)); $actualLevel = 1; $aPath = array(); foreach ($nodes as $k => $node) { $include = FALSE; if ($option == 'all') { $include = TRUE; } elseif ($option == 'branches' && !$node->isLeaf()) { $include = TRUE; } elseif ($option == 'leafs' && $node->isLeaf()) { $include = TRUE; } if ($node->{$this->levelAttribute} < $actualLevel) { $path = array_slice($path, 0, $node->{$this->levelAttribute} - 1); } $path[$node->{$this->levelAttribute}] = $node[$column]; $actualLevel = $node->{$this->levelAttribute}; if ($include) { if ($inclRoot) { $result[$node->primaryKey] = implode($separator, $path); } else { $result[$node->primaryKey] = implode($separator, array_slice($path, 1, count($path))); } } } } return $result; }
Posted 25 September 2011 - 05:51 PM
Posted 03 June 2012 - 05:07 PM
Posted 04 June 2012 - 07:35 AM
$roots=Category::model()->roots()->findAll(); foreach($roots as $root) { $tree = Category::model()->findAll( array( 'condition'=>'root='.$root->id, 'order'=>'lft' ) ); } // I need to merge all the trees, but don't know how $this->renderPartial( '//partials/category/_gridViewCategory', array( 'tree'=>$tree, ) );
Posted 15 July 2012 - 09:05 AM
Posted 21 July 2012 - 06:30 AM
Posted 23 July 2012 - 01:09 AM
samdark, on 21 July 2012 - 06:30 AM, said:
node , lft, rgh, level, id_parent root 1, 1, 2, 0, null root 2, 3, 4, 0, null root 3, 5, 6, 0, null root 4, 7, 8, 0, null root 5, 9, 10, 0, null
Posted 12 August 2012 - 06:28 AM
R N1 N2 lft, rgh, level 1, 6, 0 2, 3, 0 4, 5, 0
lft, rgh, level 100, 600, 0 200, 300, 0 400, 500, 0
Posted 15 September 2012 - 12:58 PM
Posted 15 September 2012 - 01:35 PM
$root = Page::model()->findByPk( $rootId ); $pages = $root->descendants()->findAll();
Posted 15 September 2012 - 05:24 PM
Ben, on 15 September 2012 - 01:35 PM, said:
$root = Page::model()->findByPk( $rootId ); $pages = $root->descendants()->findAll();
Posted 20 September 2012 - 02:50 PM