[ Index ] |
|
Code source de SPIP Agora 1.4 |
1 <?php /** $Id: GraphViz_example.php,v 1.1 2003/12/28 21:23:41 datenpunk Exp $ */ 2 /** 3 * Tests the DB_NestedSet class using the TreeMenu renderer 4 * 5 * Requires that you have installed GraphViz. It is available on a 6 * variety of platforms, including windows and linux. 7 * 8 * You can go to www.graphviz.org 9 * 10 * You also need PEAR::Image_GraphViz 11 * pear install Image_GraphViz 12 * 13 * @author Jason Rust <jrust@rustyparts.com> 14 * @author Arnaud Limbourg <arnaud@php.net> 15 */ 16 /** 17 * Dump of the example mysql table and data: 18 # 19 # Table structure for table `nested_set` 20 # 21 22 drop table if exists nested_set; 23 CREATE TABLE `nested_set` ( 24 `id` int(10) unsigned NOT NULL default '0', 25 `parent_id` int(10) unsigned NOT NULL default '0', 26 `order_num` tinyint(4) unsigned NOT NULL default '0', 27 `level` int(10) unsigned NOT NULL default '0', 28 `left_id` int(10) unsigned NOT NULL default '0', 29 `right_id` int(10) unsigned NOT NULL default '0', 30 `parent` int(10) default null, 31 `name` varchar(60) NOT NULL default '', 32 PRIMARY KEY (`id`), 33 KEY `right` (`right_id`), 34 KEY `left` (`left_id`), 35 KEY `order` (`order_num`), 36 KEY `level` (`level`), 37 KEY `parent_id` (`parent_id`), 38 KEY `right_left` (`id`,`parent_id`,`left_id`,`right_id`) 39 ) TYPE=MyISAM; 40 41 # 42 # Dumping data for table `nested_set` 43 # 44 45 INSERT INTO `nested_set` VALUES (5, 5, 1, 1, 1, 10, 0, 'Root A'); 46 INSERT INTO `nested_set` VALUES (7, 7, 1, 1, 1, 4, 0, 'Root B'); 47 INSERT INTO `nested_set` VALUES (6, 5, 1, 2, 2, 5, 5, 'Sub1 of A'); 48 INSERT INTO `nested_set` VALUES (1, 5, 2, 2, 6, 9, 5, 'Sub2 of A'); 49 INSERT INTO `nested_set` VALUES (2, 5, 1, 3, 3, 4, 6,'Child of Sub1'); 50 INSERT INTO `nested_set` VALUES (3, 5, 1, 3, 7, 8, 1, 'Child of Sub2'); 51 INSERT INTO `nested_set` VALUES (4, 7, 1, 2, 2, 3, 7, 'Sub of B'); 52 # -------------------------------------------------------- 53 54 # 55 # Table structure for table `nested_set_locks` 56 # 57 58 CREATE TABLE `nested_set_locks` ( 59 `lockID` char(32) NOT NULL default '', 60 `lockTable` char(32) NOT NULL default '', 61 `lockStamp` int(11) NOT NULL default '0', 62 PRIMARY KEY (`lockID`,`lockTable`) 63 ) TYPE=MyISAM COMMENT='Table locks for comments'; 64 65 */ 66 67 require_once('DB/NestedSet.php'); 68 require_once('DB/NestedSet/Output.php'); 69 70 $dsn = 'mysql://user:pass@localhost/test_viz'; 71 72 // Please pu the full path to the dot command 73 $dot_command = 'c:/progra~1/att/graphviz/bin/dot.exe'; 74 75 $params = array( 76 'id' => 'id', 77 'parent_id' => 'rootid', 78 'left_id' => 'l', 79 'right_id' => 'r', 80 'order_num' => 'norder', 81 'level' => 'level', 82 'name' => 'name', 83 'parent' => 'parent' 84 ); 85 86 $nestedSet =& DB_NestedSet::factory('DB', $dsn, $params); 87 // we want the nodes to be displayed ordered by name, so we add the secondarySort attribute 88 $nestedSet->setAttr(array( 89 'node_table' => 'nested_set', 90 'lock_table' => 'nested_set_locks' 91 ) 92 ); 93 // get data (important to fetch it as an array, using the true flag) 94 $data = $nestedSet->getAllNodes(true); 95 96 // add labels to the arrows between two links 97 foreach ($data as $id => $node) { 98 $data[$id]['edgeLabel'] = 'from ' . $node['parent'] . ' to ' . $node['id']; 99 } 100 101 $params = array( 102 'structure' => $data, 103 'nodeLabel' => 'name' 104 ); 105 106 $output =& DB_NestedSet_Output::factory($params, 'graphviz'); 107 $output->printTree($dot_command, 'png'); 108 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 14:40:03 2007 | par Balluche grâce à PHPXref 0.7 |