/** * Method to get a tree for sharing nodes * @param string $contextId The Context Id * @param string $mode The type of tree , either DHTML or Dropdown * @return string * @access public */ function getTree($contextId, $mode = NULL, $modeParams = NULL) { $icon = 'folder_up.gif'; $expandedIcon = 'folder-expanded.gif'; $link = ''; $rootnodeid = $this->objDBContext->getRootNodeId($contextId); $rootlabel = ''; //Create a new menu $menu = new treemenu(); $contentlink = $this->URI(array('action', 'contenthome'), $this->module); //create base node $basenode = new treenode(array('text' => $rootlabel, 'link' => $contentlink, 'icon' => 'base.gif', 'expandedIcon' => 'base.gif')); $this->objDBContentNodes->resetTable(); $nodesArr = $this->objDBContentNodes->getAll("WHERE tbl_context_parentnodes_id='{$rootnodeid}'"); $this->objDBContentNodes->changeTable('tbl_context_nodes_has_tbl_context_page_content'); foreach ($nodesArr as $node) { if ($node['parent_Node'] == null) { $basenode->addItem($this->getChildNodes($nodesArr, $node['id'], stripslashes($this->shortenString($node['title'])))); } } $this->objDBContentNodes->resetTable(); $menu->addItem($basenode); //$menu->addItem($this->recurTree($rootnodeid,$rootlabel)); // Create the presentation class $treeMenu =& new dhtml($menu, array('images' => $this->objSkin->getSkinURL() . '/treeimages/imagesAlt2', 'defaultClass' => 'treeMenuDefault')); if ($mode == 'listbox') { $listBox =& new listbox($menu, array('linkTarget' => '_self', 'submitText' => $modeParams['submitText'], 'promoText' => $modeParams['promoText'])); return $listBox->getMenu(); } return '<h5>' . $this->objDBContext->getTitle() . '</h5>' . $treeMenu->getMenu(); }
/** * Import method for creating HTML_TreeMenu objects/structures * out of existing tree objects/structures. Currently supported * are Wolfram Kriesings' PEAR Tree class, and Richard Heyes' (me!) * Tree class (available here: http://www.phpguru.org/). This * method is intended to be used statically, eg: * $treeMenu = &HTML_TreeMenu::createFromStructure($myTreeStructureObj); * * @param array $params An array of parameters that determine * how the import happens. This can consist of: * structure => The tree structure * type => The type of the structure, currently * can be either 'heyes' or 'kriesing' * nodeOptions => Default options for each node * * @return object The resulting HTML_TreeMenu object */ function createFromStructure($params) { if (!isset($params['nodeOptions'])) { $params['nodeOptions'] = array(); } switch (@$params['type']) { /** * Wolfram Kriesings' PEAR Tree class */ case 'kriesing': $className = strtolower(get_class($params['structure']->dataSourceClass)); $isXMLStruct = strpos($className, '_xml') !== false ? true : false; // Get the entire tree, the $nodes are sorted like in the tree view // from top to bottom, so we can easily put them in the nodes $nodes = $params['structure']->getNode(); // Make a new menu and fill it with the values from the tree $treeMenu = new treemenu(); $curNode[0] =& $treeMenu; // we need the current node as the reference to the foreach ($nodes as $aNode) { $events = array(); $data = array(); // In an XML, all the attributes are saved in an array, but since they might be // used as the parameters, we simply extract them here if we handle an XML-structure if ($isXMLStruct && sizeof($aNode['attributes'])) { foreach ($aNode['attributes'] as $key => $val) { if (!$aNode[$key]) { // dont overwrite existing values $aNode[$key] = $val; } } } // Process all the data that are saved in $aNode and put them in the data and/or events array foreach ($aNode as $key => $val) { if (!is_array($val)) { // Dont get the recursive data in here! they are always arrays if (substr($key, 0, 2) == 'on') { // get the events $events[$key] = $val; } // I put it in data too, so in case an options starts with 'on' its also passed to the node ... not too cool i know $data[$key] = $val; } } // Normally the text is in 'name' in the Tree class, so we check both but 'text' is used if found $data['text'] = $aNode['text'] ? $aNode['text'] : $aNode['name']; // Add the item to the proper node $thisNode =& $curNode[$aNode['level']]->addItem(new treenode($data, $events)); $curNode[$aNode['level'] + 1] =& $thisNode; } break; /** * Richard Heyes' (me!) second (array based) Tree class */ /** * Richard Heyes' (me!) second (array based) Tree class */ case 'heyes_array': // Need to create a HTML_TreeMenu object ? if (!isset($params['treeMenu'])) { $treeMenu =& new treemenu(); $parentID = 0; } else { $treeMenu =& $params['treeMenu']; $parentID = $params['parentID']; } // Loop thru the trees nodes foreach ($params['structure']->getChildren($parentID) as $nodeID) { $data = $params['structure']->getData($nodeID); $parentNode =& $treeMenu->addItem(new treenode(array_merge($params['nodeOptions'], $data))); // Recurse ? if ($params['structure']->hasChildren($nodeID)) { $recurseParams['type'] = 'heyes_array'; $recurseParams['parentID'] = $nodeID; $recurseParams['nodeOptions'] = $params['nodeOptions']; $recurseParams['structure'] =& $params['structure']; $recurseParams['treeMenu'] =& $parentNode; treemenu::createFromStructure($recurseParams); } } break; /** * Richard Heyes' (me!) original OO based Tree class */ /** * Richard Heyes' (me!) original OO based Tree class */ case 'heyes': default: // Need to create a HTML_TreeMenu object ? if (!isset($params['treeMenu'])) { $treeMenu =& new treemenu(); } else { $treeMenu =& $params['treeMenu']; } // Loop thru the trees nodes foreach ($params['structure']->nodes->nodes as $node) { $tag = $node->getTag(); $parentNode =& $treeMenu->addItem(new treenode(array_merge($params['nodeOptions'], $tag))); // Recurse ? if (!empty($node->nodes->nodes)) { $recurseParams['structure'] = $node; $recurseParams['nodeOptions'] = $params['nodeOptions']; $recurseParams['treeMenu'] =& $parentNode; treemenu::createFromStructure($recurseParams); } } break; } return $treeMenu; }
/** * Method to show a directory tree * ...still working here */ function showDirTree() { $this->icon = 'folder.gif'; $this->expandedIcon = 'folder-expanded.gif'; $menu = new treemenu(); $contentlink = ''; $basenode = new treenode(array('text' => '\\...', 'link' => $contentlink, 'icon' => 'base.gif', 'expandedIcon' => 'base.gif')); //create other nodes and add them to the base node $nodes =& $basenode->addItem($this->_setDirNodes($basenode, $this->objAltConfig->getsiteRootPath())); //add base node to the menu $menu->addItem($basenode); $treeMenu =& new dhtml($menu, array('images' => $this->objSkin->getSkinURL() . '/treeimages/imagesAlt2', 'defaultClass' => 'treeMenuDefault')); $this->setVar('dirtree', $treeMenu->getMenu()); //echo $this->recurseDir($this->objConfig->siteRootPath()); }
/** * Method to show the folders of the current user as a tree drop down * @param string $default Record Id of the Current Folder to highlight * @return string */ function getTreedropdown($selected = '') { //Create a new tree $menu = new treemenu(); $allFilesNode = new treenode(array('text' => 'My Files', 'link' => 'ROOT')); $refArray = array(); $refArray['/users/' . $this->objUser->userId()] =& $allFilesNode; $folders = $this->getUserFolders($this->objUser->userId()); if (!empty($this->contextCode)) { $folders = $this->getAllFolders('context', $this->contextCode, $this->objUser->userId()); $refArray['/context/' . $this->contextCode] =& $allFilesNode; } if (count($folders) > 0) { foreach ($folders as $folder) { $node =& new treenode(array('text' => basename($folder['folderpath']), 'link' => $folder['id'])); $parent = '/' . dirname($folder['folderpath']); if (array_key_exists($parent, $refArray)) { $refArray['/' . dirname($folder['folderpath'])]->addItem($node); } $refArray['/' . $folder['folderpath']] =& $node; } } $menu->addItem($allFilesNode); $this->appendArrayVar('headerParams', $this->getJavascriptFile('TreeMenu.js', 'tree')); $this->setVar('pageSuppressXML', TRUE); $objSkin =& $this->getObject('skin', 'skin'); $treeMenu =& new htmldropdown($menu, array('inputName' => 'parentfolder', 'id' => 'input_parentfolder', 'selected' => $selected)); return $treeMenu->getMenu(); }