obj =& get_instance(); $this->load->model('Content_Tree_Node_Model'); $this->rootNodeId = $rootNodeId; $this->flatNodeList = array(); $parents = array(); $this->db->order_by('RankOrder','ASC'); $query = $this->db->get('content'); foreach($query->result() as $node) { $this->flatNodeList[$node->ContentId] = new content_tree_node_model( $node->NavigationTitle, $node->ContentId, $node->UrlKey, $node->Type, $node->DynamicPath ); $parents[$node->ContentId] = $node->ParentId; } $this->flatNodeList[$this->rootNodeId] = new content_tree_node_model("ROOT_NODE", $this->rootNodeId, 0, ''); // -- create the tree structure foreach( $this->flatNodeList as $node ) { $parent = ($node->contentId)? $this->flatNodeList[ $parents[ $node->contentId ] ]: NULL; if( $parent != NULL ) { if( $parent->contentId != $this->rootNodeId ) { $node->setParent( $parent ); } $parent->addChild( $node ); } } $this->root = $this->flatNodeList[ $this->rootNodeId ]; } function getNodeById( $nodeId ) { if( array_key_exists( $nodeId, $this->flatNodeList ) ) { return $this->flatNodeList[ $nodeId ]; } } function getNodeByPath( $path, $seperator = "/" ) { foreach( $this->flatNodeList as $node ) { if( strtoupper( $node->getPath( $seperator ) ) == strtoupper( $path ) ) { return $node; } } } function getNodesArray( Content_Tree_Node_Model $startNode, $selectedId, $nodes = array() ) { if( ! $startNode ) { return $nodes; } $len = count( $startNode->children ); for( $i=0; $i<$len; $i++ ) { $nodes[] = $startNode->children[ $i ]; if( $startNode->children[ $i ]->hasChildren() ) { $nodes = $this->getNodesArray( $startNode->children[ $i ], $selectedId, $nodes); } } return $nodes; } function drawSelect( Content_Tree_Node_Model $startNode, $selectedId, $nodeDisplayFunction = null, $extra = null ) { if( ! $startNode ) { return; } $len = count( $startNode->children ); for( $i=0; $i<$len; $i++ ) { //$pad = $startNode->children[ $i ]->getPadding( "    " ); //$sel = $startNode->children[ $i ]->id == $selectedId ? 'selected="selected"' : ""; /*?>drawSelectNode( $startNode->children[ $i ], $selectedId ); } else { // use the custom display function $nodeDisplayFunction( $startNode->children[ $i ], $selectedId, $extra ); } if( $startNode->children[ $i ]->hasChildren() ) { $this->drawSelect( $startNode->children[ $i ], $selectedId, $nodeDisplayFunction, $extra ); } } } function drawSelectNode( Content_Tree_Node_Model $node, $selectedId ) { $pad = $node->getPadding( "    " ); $sel = $node->id == $selectedId ? 'selected="selected"' : ""; ?>children ); for( $i=0; $i<$len; $i++ ) { $pad = $startNode->children[ $i ]->getPadding( "    " ); $sel = $startNode->children[ $i ]->id == $selectedId ? 'selected="selected"' : ""; $dis = $startNode->children[ $i ]->parent->id > 0 ? 'disabled="disabled"' : "" ; ?>children[ $i ]->hasChildren() ) { $this->drawSingleLevelSelect( $startNode->children[ $i ], $selectedId ); } } } function drawTree( Content_Tree_Node_Model $startNode, $counter=0) { if( ! $startNode ) { return; } $str = ""; for( $i=0; $i < count($startNode->children); $i++ ) { $str .= '
  • '.$startNode->children[$i]->name.''; $counter++; if( $startNode->children[ $i ]->hasChildren() ) { $str .= ''; } $str .= '
  • '; } return $str; } function drawNavigation( $startNode, $counter=0, $startPath, $seperatorStr="") { if( ! $startNode ) { return; } $str = ""; $seperator = ($counter == 0)? $seperatorStr: ''; for( $i=0; $i < count($startNode->children); $i++ ) { if($startNode->children[$i]->isDynamic == '0'){ $str .= '
  • '.$startNode->children[$i]->name.''; } else if( strrpos($startNode->children[$i]->dynamicPath,'http://') === false && strrpos($startNode->children[$i]->dynamicPath,'https://') === false ){ $str .= '
  • '.$startNode->children[$i]->name.''; } else { $str .= '
  • '.$startNode->children[$i]->name.''; } $counter++; if( $startNode->children[ $i ]->hasChildren() ) { $str .= ''; } $str .= ( $i+1 < count($startNode->children) )? $seperator: ''; $str .= '
  • '; } return $str; } function iterateNodes( $startNode, $nodeDisplayFunction ) { if( ! $startNode ) { return; } $len = count( $startNode->children ); for( $i=0; $i<$len; $i++ ) { $nodeDisplayFunction( $startNode->children[ $i ] ); if( $startNode->children[ $i ]->hasChildren() ) { $this->iterateNodes( $startNode->children[ $i ], $nodeDisplayFunction ); } } } } ?>