From: <za...@us...> - 2003-07-24 23:46:29
|
Update of /cvsroot/tikiwiki/tiki/lib/tree In directory sc8-pr-cvs1:/tmp/cvs-serv29504/lib/tree Added Files: Tag: release_eta_carinea_rc1 categ_admin_tree.php categ_browse_tree.php tree.php Log Message: Continue categories admin/browse redesign --- NEW FILE: categ_admin_tree.php --- <?php /** \file * $Header: /cvsroot/tikiwiki/tiki/lib/tree/Attic/categ_admin_tree.php,v 1.1.2.1 2003/07/24 23:46:24 zaufi Exp $ * * \brief Categories browse tree * * \author za...@se... * */ require_once('lib/tree/tree.php'); /** * \brief Class to render categories browse tree */ class CatAdminTreeMaker extends TreeMaker { /// Collect javascript cookie set code (internaly used after make_tree() method) var $jsscriptblock; /// Generated ID (private usage only) var $itemID; /// Have childs?? (set by 'flipper code' used by 'data code') var $have_child; /// Constructor function CatAdminTreeMaker($prefix) { $this->TreeMaker($prefix); $this->jsscriptblock = ''; $this->have_child = false; } /// Generate HTML code for tree. Need to redefine to add javascript cookies block function make_tree($rootid, $ar) { global $debugger; $r = $this->make_tree_r($rootid, $ar); // $debugger->var_dump('$r'); // return tree with java script block that opens the nodes as remembered in cookies return $r."<script language='Javascript' type='text/javascript'> ".$this->jsscriptblock." </script>\n"; } // // Change default (no code 'cept user data) generation behaviour // // Need to generate: // // [node start = <div class=treenode><table><tr>] // [flipper] user data [edit][del] // [node data end = </div>] // [node child start = <div class=tree>] // [childs code] // [node child end = </div>] // // Unsymmetrical calls is not important :) // function node_start_code($nodeinfo) { return '<div class="treenode"><table width="100%"><tr>'; } // function node_flipper_code($nodeinfo) { $this->itemID = $this->prefix.'id'.$nodeinfo["id"]; $this->jsscriptblock .= "setFlipWithSign('".$this->itemID."'); "; $this->have_child = true; return '<td width=4%><a class="link" id="flipper'.$this->itemID.'" href="javascript:flipWithSign(\''.$this->itemID.'\')">[+]</a></td>'; } // function node_data_start_code($nodeinfo) { return '<td>'; } // function node_data_end_code($nodeinfo) { return '</td><td align="center" width=8%>'.$nodeinfo["children"].'</td><td align="center" width=8%>'.$nodeinfo["objects"].'</td><td width=10%><small></small><td width=5%>'.$nodeinfo["edit"].'</td><td width=5%>'.$nodeinfo["remove"].'</td></tr></table></div>'; } // function node_child_start_code($nodeinfo) { return '<div class="tree" id="'.$this->itemID.'" style="display: none;">'; } // function node_child_end_code($nodeinfo) { return '</div>'; } // function node_end_code($nodeinfo) { return ''; } } ?> --- NEW FILE: categ_browse_tree.php --- <?php /** \file * $Header: /cvsroot/tikiwiki/tiki/lib/tree/Attic/categ_browse_tree.php,v 1.1.2.1 2003/07/24 23:46:24 zaufi Exp $ * * \brief Categories browse tree * * \author za...@se... * */ require_once('lib/tree/tree.php'); /** * \brief Class to render categories browse tree */ class CatBrowseTreeMaker extends TreeMaker { /// Collect javascript cookie set code (internaly used after make_tree() method) var $jsscriptblock; /// Generated ID (private usage only) var $itemID; /// Constructor function CatBrowseTreeMaker($prefix) { $this->TreeMaker($prefix); $this->jsscriptblock = ''; } /// Generate HTML code for tree. Need to redefine to add javascript cookies block function make_tree($rootid, $ar) { global $debugger; $r = $this->make_tree_r($rootid, $ar); // $debugger->var_dump('$r'); // return tree with java script block that opens the nodes as remembered in cookies return $r."<script language='Javascript' type='text/javascript'> ".$this->jsscriptblock." </script>\n"; } // // Change default (no code 'cept user data) generation behaviour // // Need to generate: // // [node start = <div class=treenode>] // [flipper] user data // [node data end = </div>] // [node child start = <div class=tree>] // [childs code] // [node child end = </div>] // // Unsymmetrical calls is not important :) // function node_start_code($nodeinfo) { return '<div class="treenode">'; } // function node_flipper_code($nodeinfo) { $this->itemID = $this->prefix.'id'.$nodeinfo["id"]; $this->jsscriptblock .= "setFlipWithSign('".$this->itemID."'); "; return '<a class="link" id="flipper'.$this->itemID.'" href="javascript:flipWithSign(\''.$this->itemID.'\')">[+]</a> '; } // function node_data_start_code($nodeinfo) { return ''; } // function node_data_end_code($nodeinfo) { return '</div>'; } // function node_child_start_code($nodeinfo) { return '<div class="tree" id="'.$this->itemID.'" style="display: none;">'; } // function node_child_end_code($nodeinfo) { return '</div>'; } // function node_end_code($nodeinfo) { return ''; } } ?> --- NEW FILE: tree.php --- <?php /** \file * $Header: /cvsroot/tikiwiki/tiki/lib/tree/Attic/tree.php,v 1.1.2.1 2003/07/24 23:46:24 zaufi Exp $ * * \brief Base tree maker * * \author za...@se... * */ require_once('lib/debug/debugger.php'); /** * \brief Base class for all tree makers * * Define base interface and provide common algotithm for tree generation * * Format of element in array for make_tree() call: * id => number of ID of current node * parent => number of ID of parant node * data => user provided data to be placed as node text * */ class TreeMaker { /// Unique prefix for cookies generated for this tree var $prefix; /// Constructor function TreeMaker($prefix) { $this->prefix = $prefix; } /// Generate HTML code for tree function make_tree($rootid, $ar) { return $this->make_tree_r($rootid, $ar); } /// Recursive make (do not call directly) function make_tree_r($rootid, & $ar) { global $debugger; $debugger->msg("TreeMaker::make_tree_r: Root ID=".$rootid); $result = ''; if (count($ar) > 0) { $cli = array(); $tmp = array(); foreach ($ar as $i) if ($rootid == $i["parent"]) $cli[] = $i; else $tmp[] = $i; // foreach ($cli as $i) { $child_result = $this->make_tree_r($i["id"], $tmp); $have_childs = (strlen($child_result) > 0); // // NOTE: The main rule is to call all methods in // stricty defined order!! // $nsc = $this->node_start_code($i); $flipper = ''; if ($have_childs) $flipper = $this->node_flipper_code($i); $ndsc = $this->node_data_start_code($i); $ndec = $this->node_data_end_code($i); $ncsc = ''; $ncec = ''; if ($have_childs) { $ncsc = $this->node_child_start_code($i); $ncec = $this->node_child_end_code($i); } $nec = $this->node_end_code($i); // Form result $result .= $nsc.$flipper.$ndsc.$i["data"].$ndec.$ncsc.$child_result.$ncec.$nec; } } return $result; } /** * To change behavior (look and feel :) of generated tree * it is enough to redefine follwing methods.. * (thanx that PHP have implicit vurtual functions :) * * General layout of generated tree code looks like this: * * [node start code] * [node flipper code] (1) * [node data start code] * [node data end code] * [node childs start code] (1) * [node childs end code] (1) * [node end code] * * (1) -- this code will be generated if node have childs * * NOTE: Methods called exactly in that order. This fact can be * (and actualy do) used by child classes to define * and use some variables depends on pervious call... * * NOTE: This is abstract base class... it doing nothig * except defining algirithm... * So to make smth other use inheritance and redifine * corresponding function :) */ function node_start_code($nodeinfo) { return ''; } // function node_flipper_code($nodeinfo) { return ''; } // function node_data_start_code($nodeinfo) { return ''; } // function node_data_end_code($nodeinfo) { return ''; } // function node_child_start_code($nodeinfo) { return ''; } // function node_child_end_code($nodeinfo) { return ''; } // function node_end_code($nodeinfo) { return ''; } } ?> |