By passing in simple raw data, you can derive n relationships between nodes, and you can output tree-like DOM Note: Please refer to the latest code on git.oschina.net (click "Source Sources" link)
- /**
- * Output Unlimited classification, I wrote the Oh ~
- *
- * @author binny_w@qq.com
- * @since 2013-09-24 AM
- */
- /* Use example */
- /*
- $arrAll = Array (
- Array (' id ' = + 1, ' name ' = ' = ' column category _1 ', ' name_en ' = ' cat_1 ', ' parent_id ' and ' = 0 '),
- Array (' id ' = + 2, ' name ' = ' = ' column category _2 ', ' name_en ' = ' cat_2 ', ' parent_id ' and ' = 0 '),
- Array (' id ' = + 3, ' name ' = ' = ' column category _3 ', ' name_en ' = ' cat_3 ', ' parent_id ' and ' = 1 '),
- Array (' id ' = + 4, ' name ' = ' = ' column category _4 ', ' name_en ' = ' cat_4 ', ' parent_id ' and ' = 1 '),
- Array (' id ' = + 5, ' name ' = ' = ' column category _5 ', ' name_en ' = ' cat_5 ', ' parent_id ' and ' = 2 '),
- Array (' id ' = + 6, ' name ' = ' = ' column category _6 ', ' name_en ' = ' cat_6 ', ' parent_id ' and ' = 4 '),
- Array (' id ' = + 7, ' name ' = ' = ' column category _7 ', ' name_en ' = ' cat_7 ', ' parent_id ' and ' = 6 '),
- Array (' id ' = + 8, ' name ' = ' = ' column category _8 ', ' name_en ' = ' cat_8 ', ' parent_id ' and ' = 7 '),
- Array (' id ' = + 9, ' name ' = ' = ' column category _9 ', ' name_en ' = ' cat_9 ', ' parent_id ' and ' = 6 ')
- );
- $objT = new Treelist ($ARRALL);
- Print_r ($objT->arrall);
- Print_r ($objT->arridall);
- Print_r ($objT->arridchildren);
- Print_r ($objT->arridson);
- Print_r ($objT->arridleaf);
- Print_r ($objT->arridrelation);
- Print_r ($objT->arridrelationsimple);
- Print_r ($objT->arridroot);
- Print_r ($objT->arridbackpath);
- Print ($objT->gettable ());
- Print ($objT->getselect (' Cat ', Array (1, 8), true));
- */
- !defined (' In_frame ') && die (' 404 Page ');
- Class Treelist {
- /**
- * Analyze all data that may be used
- */
- Public $arrAll = Array (); Raw data
- Public $arrIdRelation = Array (); Multi-dimensional relationships by _id as key names
- Public $arrIdRelationSimple = Array (); Simplification of multidimensional relationships by _id as key names, used to output tree graphs
- Public $arrIdAll = Array (); An array of _id that convert raw data into a key name
- Public $arrIdSon = Array (); All parent-child relationships
- Public $arrIdLeaf = Array (); _id of leaf nodes
- Public $arrIdRoot = Array (); _id of the root node
- Public $arrIdChildren = Array (); Descendants of _id under each node
- Public $arrIdBackPath = Array (); Each node is inverted back to the root
- Public $strItem = '
{$STRSEP} {$name} '; Structure of the output tree
- /**
- * constructor, incoming raw data
- */
- Public function __construct ($arrData) {
- $this->arrall = $arrData;
- $this->processdata ();
- }
- /**
- * Simple Tree
- */
- Public Function gethtml () {
- return $this->genhtml ();
- }
- /**
- * Use table to draw trees
- */
- Public Function getTable () {
- $this->stritem = '
|