DB_NestedSet
[ class tree: DB_NestedSet ] [ index: DB_NestedSet ] [ all elements ]

Source for file CoolMenu_example.php

Documentation is available at CoolMenu_example.php

  1. <?php
  2. /**
  3.  * This example shows how to use the CoolMenu output driver
  4.  *
  5.  * @author Andy Crain <apcrain@fuse.net>
  6.  */
  7.  
  8. // This example assumes that you have allready set up DB_NestedSet and allready
  9. // inserted nodes.
  10.  
  11. // First you have to get CoolMenu
  12. // It's available for free at http://www.dhtmlcentral.com/projects/coolmenus
  13. // There are a lot of parameters required by CoolMenu, so the options array required
  14. // by this driver is fairly large. There are many combinations of parameters that
  15. // determine menu output, so it is strongly recommended you read the CoolMenu documents.
  16.  
  17. require_once('DB/NestedSet.php');
  18. require_once('DB/NestedSet/Output.php');
  19.  
  20. // Choose a database abstraction layer. 'DB' and 'MDB' are supported.
  21. $nese_driver 'DB';
  22.  
  23. // Set the DSN - see http://pear.php.net/manual/en/core.db.tut_dsn.php for details
  24. $nese_dsn 'type://user:password@server/db';
  25.  
  26. // Specify the database columns which will be used to specify a node
  27. // Use an associative array. On the left side write down the name of the column.
  28. // On the right side write down how the property will be called in a node object
  29. // Some params are needed
  30. $nese_params = array
  31. (
  32.     "STRID"         =>      "id",      // "id" must exist
  33.     "ROOTID"        =>      "rootid",  // "rootid" must exist
  34.     "l"             =>      "l",       // "l" must exist
  35.     "r"             =>      "r",       // "r" must exist
  36.     "STREH"         =>      "norder",  // "order" must exist
  37.     "LEVEL"         =>      "level",   // "level" must exist
  38.     "STRNA"         =>      "name",
  39.     "STLNK"         =>      "link"     // Custom - specify as many fields you want
  40. );
  41.  
  42. // Now create an instance of DB_NestedSet
  43. $NeSe DB_NestedSet::factory($nese_driver$nese_dsn$nese_params);
  44. if(PEAR::isError($NeSe)) {
  45.     echo $NeSe->getCode().": ".$NeSe->getMessage();
  46. }
  47.  
  48.  
  49. $NeSe->setAttr(array(
  50.         'node_table' => 'foo',
  51.         'lock_table' => 'bar',
  52.         'sequence_table' => 'foobar'
  53.     )
  54. );
  55.  
  56.  
  57. // Fetch the tree as array
  58. $nodes $NeSe->getAllNodes(true);
  59.  
  60. // Set the basic params
  61. $params = array(
  62. 'menu_id' => 1,
  63. 'structure' => $nodes,
  64. 'options' => array(
  65. ),
  66. 'textField' => 'mytextfield'// Use the name column for the menu names
  67. 'linkField' => 'mylinkfield'// Use the link column for the links
  68. 'currentLevel' => 1       // Start the ouput with this level
  69. );
  70.  
  71. // This array contains the options needed
  72. // for printing out the menu.
  73.  
  74.  
  75.  
  76. /*
  77. The options array holds everything CoolMenu needs to know to build a menu.
  78.  
  79. $options['levels'] defines structure and style for particular menu levels.
  80. It needs at least one element, defining the root/top-level, and
  81. any number of additional elements, for sublevel 1, sublevel 2...sublevel n. Any sublevel
  82. property not defined inherits from the above, i.e. sublevel 1 inherits from
  83. $options['levels'][0] if $options['levels'][1], or a part of it, is not defined.
  84.  
  85. $options['levels'][0] needs arrays for "mouseout_style", "mouseover_style", "border_style",
  86. and "properties", the first three of which are used to build CSS definitions like so:
  87. mouseout array('position' => 'absolute','padding' => '2px') becomes
  88. ".mouseout_style0{position:absolute; padding:2px;}" and so on.
  89. The "properties" array defines a menu level's geometry. You can also add arrays
  90. ($options['levels'][0]['highlight_mouseout_style'] and
  91. $options['levels'][0]['highlight_mouseout_style'])in the top level for highlighting if
  92. you want the current page's menu tab highlighted.
  93.  
  94. $options['menu'] defines menu level structure and style.
  95.  
  96. Every element is a string. Note that some of these strings must include double quotes
  97. (see http://www.dhtmlcentral.com/projects/coolmenus/).
  98.  
  99. Every parameter below (except for the style parameters, which are simply any valid CSS
  100. key-value pairs) is defined in the CoolMenu reference at
  101. http://www.dhtmlcentral.com/projects/coolmenus/, which you are stronly encouraged to read.
  102. */
  103.  
  104. $options = array(
  105.     'levels' => array(//required
  106.         0 => array(//required
  107.             'mouseout_style' => array(//required; set whatever CSS elements you wish
  108.                 'position' => 'absolute',
  109.                 'padding' => '2px',
  110.                 'font-family' => 'tahoma,arial,helvetica',
  111.                 'font-size' => '11px',
  112.                 'font-weight' => 'bold',
  113.                 'background-color' => '#9DCDFE',
  114.                 'layer-background-color' => '#9DCDFE',
  115.                 'color' => 'white',
  116.                 'text-align'=>'center',
  117.                 'text-transform' => 'uppercase',
  118.                 'white-space' => 'nowrap',
  119.                 'border-top' => '1px solid #006699',
  120.                 'border-left' => '1px solid #006699',
  121.                 'border-right' => '1px solid #006699',
  122.                 'border-bottom' => '1px solid #006699'
  123.             ),
  124.             'mouseover_style' => array(//required; set whatever CSS elements you wish
  125.                 'position' => 'absolute',
  126.                 'padding' => '2px',
  127.                 'font-family' => 'tahoma,arial,helvetica',
  128.                 'font-size' => '11px',
  129.                 'font-weight' => 'bold',
  130.                 'background-color' => '#9DCDFE',
  131.                 'layer-background-color' => '#9DCDFE',
  132.                 'color' => '#006699',
  133.                 'cursor' => 'pointer',
  134.                 'cursor' => 'hand',
  135.                 'text-align'=>'center',
  136.                 'text-transform' => 'uppercase',
  137.                 'white-space' => 'nowrap',
  138.                 'border-top' => '1px solid #006699',
  139.                 'border-left' => '1px solid #006699',
  140.                 'border-right' => '1px solid #006699',
  141.                 'border-bottom' => '1px solid #006699'
  142.             ),
  143.             'border_style' => array(//optional; set whatever CSS elements you wish
  144.                 'position' => 'absolute',
  145.                 'visibility' => 'hidden',
  146.                 'width' => '0'
  147.             ),
  148.             'properties' => array(//required; each parameter here is required for level 0 at least
  149.                 'width' => '90',
  150.                 'height' => '20',
  151.                 'borderX' => '1',
  152.                 'borderY' => '1',
  153.                 'offsetX' => '0',
  154.                 'offsetY' => '0',
  155.                 'rows' => '0',
  156.                 'arrow' => '0',
  157.                 'arrowWidth' => '0',
  158.                 'arrowHeight' => '0',
  159.                 'align' => '"bottom"'
  160.             ),
  161.             /*
  162.             The next two elements are optional, and only work when the linkField values
  163.             represent local, current pages--i.e. these styles will apply when
  164.             $node[$params['linkField']] == basename($_SERVER['PHP_SELF']). When that is true,
  165.             these styles will override the toplevel mouseout and mouseover styles above. Useful
  166.             if you want the current page highlighted in the menu.
  167.             */
  168.             'highlight_mouseout_style' => array(//optional; set whatever CSS elements you wish
  169.                 'position' => 'absolute',
  170.                 'padding' => '2px',
  171.                 'font-family' => 'tahoma,arial,helvetica',
  172.                 'font-size' => '11px',
  173.                 'font-weight' => 'bold',
  174.                 'background-color' => '#E5F1FF',
  175.                 'layer-background-color' => '#E5F1FF',
  176.                 'color' => '#006699',
  177.                 'text-align'=>'center',
  178.                 'text-transform' => 'uppercase',
  179.                 'white-space' => 'nowrap',
  180.                 'border-top' => '1px solid #006699',
  181.                 'border-left' => '1px solid #006699',
  182.                 'border-right' => '1px solid #006699',
  183.             ),
  184.             'highlight_mouseover_style' => array(//optional; set whatever CSS elements you wish
  185.                 'position' => 'absolute',
  186.                 'padding' => '2px',
  187.                 'font-family' => 'tahoma,arial,helvetica',
  188.                 'font-size' => '11px',
  189.                 'font-weight' => 'bold',
  190.                 'background-color' => '#E5F1FF',
  191.                 'layer-background-color' => '#E5F1FF',
  192.                 'color' => '#006699',
  193.                 'cursor' => 'pointer',
  194.                 'cursor' => 'hand',
  195.                 'text-align'=>'center',
  196.                 'text-transform' => 'uppercase',
  197.                 'white-space' => 'nowrap',
  198.                 'border-top' => '1px solid #006699',
  199.                 'border-left' => '1px solid #006699',
  200.                 'border-right' => '1px solid #006699',
  201.             )//end highlight styles
  202.         ),
  203.         1 => array(//optional; define whatever should not be inherited from above
  204.             'mouseout_style' => array(//optional; set whatever CSS elements you wish
  205.                 'position' => 'absolute',
  206.                 'padding' => '2px',
  207.                 'font-family' => 'tahoma,arial,helvetica',
  208.                 'font-size' => '10px',
  209.                 'font-weight' => 'bold',
  210.                 'background-color' => '#9DCDFE',
  211.                 'layer-background-color' => '#9DCDFE',
  212.                 'color' => 'white',
  213.                 'text-align'=>'center',
  214.                 'text-transform' => 'uppercase',
  215.                 'white-space' => 'nowrap'
  216.             ),
  217.             'mouseover_style' => array(//optional; set whatever CSS elements you wish
  218.                 'position' => 'absolute',
  219.                 'padding' => '2px',
  220.                 'font-family' => 'tahoma,arial,helvetica',
  221.                 'font-size' => '10px',
  222.                 'font-weight' => 'bold',
  223.                 'background-color' => '#9DCDFE',
  224.                 'layer-background-color' => '#9DCDFE',
  225.                 'color' => '#006699',
  226.                 'cursor' => 'pointer',
  227.                 'cursor' => 'hand',
  228.                 'text-align'=>'center',
  229.                 'text-transform' => 'uppercase',
  230.                 'white-space' => 'nowrap'
  231.             ),
  232.             'border_style' => array(//optional; set whatever CSS elements you wish
  233.                 'position' => 'absolute',
  234.                 'visibility' => 'hidden',
  235.                 'background-color' => '#006699',
  236.                 'layer-background-color' => '#006699'
  237.             ),
  238.             'properties' => array(//optional; set whatever elements you wish
  239.                 'width' => '100',
  240.                 'offsetX' => '-10',
  241.                 'offsetY' => '10',
  242.                 'align' => '"right"',
  243.                 'arrow' => '"menu_arrow.gif"',
  244.                 'arrowWidth' => '10',
  245.                 'arrowHeight' => '9',
  246.             )
  247.         )
  248.     ),
  249.     'menu' => array(//required
  250.         'background_style' => array(//optional; set whatever CSS elements you wish
  251.             'position' => 'absolute',
  252.             'width' => '10',
  253.             'height' => '10',
  254.             'background-color' => '#99CC00',
  255.             'layer-background-color' => '#99CC00',
  256.             'visibility' => 'hidden',
  257.             'border-bottom' => '1px solid #006699'
  258.         ),
  259.         'properties' => array(//required; all parameters are required
  260.             'frames ' => '0',
  261.             //Menu properties
  262.             'pxBetween' => '5',
  263.             'fromLeft' => '0',
  264.             'fromTop' => '30',
  265.             'rows' => '1',
  266.             'menuPlacement' => '"center"',
  267.             'resizeCheck' => '1',
  268.             'wait' => '300',
  269.             'fillImg' => '"cm_fill.gif"',
  270.             'zIndex' => '0',
  271.             'offlineRoot' => '"file:///' $_SERVER['DOCUMENT_ROOT''"',
  272.             'onlineRoot' => '"/www/javascript/coolmenus/"',//path from web root to CM directory
  273.             //Background bar properties
  274.             'useBar' => '1',
  275.             'barWidth' => '"100%"',
  276.             'barHeight' => '51',
  277.             'barX' => '0',
  278.             'barY' => '0',
  279.             'barBorderX' => '0',
  280.             'barBorderY' => '0',
  281.             'barBorderClass' => '""'
  282.         )
  283.     )
  284. );
  285.  
  286.  
  287. // Now create the menu object, set the options and do the output
  288. $menu =DB_NestedSet_Output::factory($params'CoolMenu');
  289. $menu->setOptions('printTree'$options);
  290. ?>
  291.  
  292.  
  293. <html>
  294. <head>
  295. <title>DB_NestedSet_CoolMenu usage example</title>
  296. </head>
  297. <body>
  298.  
  299. <script language="JavaScript1.2" src="/www/javascript/coolmenus/coolmenus4.js">
  300. </script>
  301.  
  302. <?php
  303. $menu->printTree();
  304. ?>
  305.  
  306. </body>
  307. </html>

Documentation generated on Mon, 11 Mar 2019 15:37:09 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.