Input simple raw data to obtain N relationships between nodes and output tree-like DOM Note: Please refer to the latest code on git.oschina.net (click the "source code" link)
- /**
- * The output is infinite classification. I wrote it myself ~
- *
- * @ Author binny_w@qq.com
- * @ Since 2013-09-24 AM
- */
- /* Example */
- /*
- $ ArrAll = array (
- Array ('id' => 1, 'name' => 'topic category _ 1', 'Name _ EN' => 'cat _ 1 ', 'parent _ id' => 0 ),
- Array ('id' => 2, 'name' => 'topic category _ 2', 'Name _ EN' => 'cat _ 2 ', 'parent _ id' => 0 ),
- Array ('id' => 3, 'name' => 'topic category _ 3', 'Name _ EN' => 'cat _ 3 ', 'parent _ id' => 1 ),
- Array ('id' => 4, 'name' => 'topic category _ 4', 'Name _ EN' => 'cat _ 4 ', 'parent _ id' => 1 ),
- Array ('id' => 5, 'name' => 'topic category _ 5', 'Name _ EN' => 'cat _ 5 ', 'parent _ id' => 2 ),
- Array ('id' => 6, 'name' => 'topic category _ 6', 'Name _ EN' => 'cat _ 6 ', 'parent _ id' => 4 ),
- Array ('id' => 7, 'name' => 'topic category _ 7', 'Name _ EN' => 'cat _ 7 ', 'parent _ id' => 6 ),
- Array ('id' => 8, 'name' => 'topic category _ 8', 'Name _ EN' => 'cat _ 8 ', 'parent _ id' => 7 ),
- Array ('id' => 9, 'name' => 'topic category _ 9', 'Name _ EN' => 'cat _ 9 ', 'parent _ id' => 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 _ framework') & die ('404 page ');
- Class TreeList {
-
- /**
- * Analyze all data that may be used
- */
- Public $ arrAll = array (); // raw data
- Public $ arrIdRelation = array (); // multidimensional relationship named by _ ID
- Public $ arrIdRelationSimple = array (); // simplify the multi-dimensional relationship by pressing _ ID as the key name to output a tree chart
- Public $ arrIdAll = array (); // The _ ID converted from the original data as the key name array.
- Public $ arrIdSon = array (); // all parent-child relationships
- Public $ arrIdLeaf = array (); // The _ ID of the leaf node
- Public $ arrIdRoot = array (); // _ ID of the root node
- Public $ arrIdChildren = array (); // descendant _ ID under each node
- Public $ arrIdBackPath = array (); // Each node returns to the root
- Public $ strItem ='
{$ StrSep} {$ name} '; // Structure of the output tree
-
- /**
- * Constructor to pass in 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 ='
|