Class MenuSet

Description

A MenuSet is a hierarchy of MenuOptions, some of which might be MenuSet objects themselves.

The menu options are presented in HTML span tags, and the menus themselves are presented inside HTML div tags. All layout and styling is expected to be provide by CSS.

A non-trivial example would look something like this:

  1. require("MenuSet.php");
  2. $main_menu new MenuSet('menu''menu''menu_active');
  3.   ...
  4. $other_menu new MenuSet('submenu''submenu''submenu_active');
  5. $other_menu->AddOption("Extra Other","/extraother.php","Submenu option to do extra things.");
  6. $other_menu->AddOption("Super Other","/superother.php","Submenu option to do super things.");
  7. $other_menu->AddOption("Meta Other","/metaother.php","Submenu option to do meta things.");
  8.   ...
  9. $main_menu->AddOption("Do This","/dothis.php","Option to do this thing.");
  10. $main_menu->AddOption("Do That","/dothat.php","Option to do all of that.");
  11. $main_menu->AddSubMenu$other_menu"Do The Other","/dotheother.php","Submenu to do all of the other things."true);
  12.   ...
  13. if isset($main_menu&& is_object($main_menu) ) {
  14.   $main_menu->AddOption("Home","/","Go back to the home page");
  15.   echo $main_menu->Render();
  16. }
In a hierarchical menu tree, like the example above, only one sub-menu will be shown, which will be the first one that is found to have active menu options.

The menu display will generally recognise the current URL and mark as active the menu option that matches it, but in some cases it might be desirable to force one or another option to be marked as active using the appropriate parameter to the AddOption or AddSubMenu call.

Located in /MenuSet.php (line 222)


	
			
Method Summary
 MenuSet MenuSet (string $div_id, [string $main_class = ''], [string $active_class = 'active'])
 mixed &AddOption (string $label, string $target, [string $title = ""], [string $active = false], [int $sortkey = null], [external $external = false])
 mixed &AddSubMenu (object &$submenu_set, string $label, string $target, [string $title = ""], [string $active = false], [int $sortkey = 2000])
 void MakeSomethingActive ( $test_pattern)
 string Render ([boolean $submenus_inline = false])
 string RenderAsCSS ([ $depth = 0], [ $skip_empty = true], boolean $submenus_inline)
 int Size ()
 int _CompareSequence (objectref $a, objectref $b)
 boolean _HasActive (string $label)
 boolean _OptionExists ( $newlabel)
Methods
Constructor MenuSet (line 276)

Start a new MenuSet with no options.

MenuSet MenuSet (string $div_id, [string $main_class = ''], [string $active_class = 'active'])
  • string $div_id: An ID for the HTML div that the menu will be presented in.
  • string $main_class: A CSS class for most menu options.
  • string $active_class: A CSS class for active menu options.
AddOption (line 295)

Add an option, which is a link.

The call will attempt to work out whether the option should be marked as active, and will sometimes get it wrong.

  • return: A reference to the MenuOption that was added, or false if none were added.
mixed &AddOption (string $label, string $target, [string $title = ""], [string $active = false], [int $sortkey = null], [external $external = false])
  • string $label: A Label for the new menu option
  • string $target: The URL to target for this option.
  • string $title: Some tooltip help for the title tag.
  • string $active: Whether this option should be marked as Active.
  • int $sortkey: An (optional) value to allow option ordering.
  • external $external: open this link in a new window/tab.
AddSubMenu (line 341)

Add an option, which is a submenu

  • return: A reference to the MenuOption that was added, or false if none were added.
mixed &AddSubMenu (object &$submenu_set, string $label, string $target, [string $title = ""], [string $active = false], [int $sortkey = 2000])
  • object &$submenu_set: A reference to a menu tree
  • string $label: A Label for the new menu option
  • string $target: The URL to target for this option.
  • string $title: Some tooltip help for the title tag.
  • string $active: Whether this option should be marked as Active.
  • int $sortkey: An (optional) value to allow option ordering.
LinkActiveSubMenus (line 395)

Mark each MenuOption as active that has an active sub-menu entry.

Currently needs to be called manually before rendering but really should probably be called as part of the render now, and then this could be a private routine.

void LinkActiveSubMenus ()
MakeSomethingActive (line 413)

Mark each MenuOption as active that has an active sub-menu entry.

Currently needs to be called manually before rendering but really should probably be called as part of the render now, and then this could be a private routine.

void MakeSomethingActive ( $test_pattern)
  • $test_pattern
Render (line 462)

Render the menu tree to an HTML fragment.

  • return: The HTML fragment.
string Render ([boolean $submenus_inline = false])
  • boolean $submenus_inline: Indicate whether to render the sub-menus within the menus, or render them entirely separately after we finish rendering the top level ones.
RenderAsCSS (line 494)

Render the menu tree to an HTML fragment.

  • return: The HTML fragment.
string RenderAsCSS ([ $depth = 0], [ $skip_empty = true], boolean $submenus_inline)
  • boolean $submenus_inline: Indicate whether to render the sub-menus within the menus, or render them entirely separately after we finish rendering the top level ones.
  • $depth
  • $skip_empty
Size (line 372)

Find out how many options the menu has.

  • return: The number of options in the menu.
int Size ()
_CompareSequence (line 448)

_CompareSequence is used in sorting the menu options into the sequence order

  • return: ( $a == b ? 0 ( $a > b ? 1 : -1 ))
int _CompareSequence (objectref $a, objectref $b)
  • objectref $a: The first menu option
  • objectref $b: The second menu option
_HasActive (line 354)

Does the menu have any options that are active.

Most likely used so that we can then set the parent menu as active.

  • return: Whether the menu has options that are active.
boolean _HasActive (string $label)
  • string $label: A Label for the new menu option
_OptionExists (line 380)

See if a menu already has this option

  • return: Whether the option already exists in the menu.
boolean _OptionExists ( $newlabel)
  • $newlabel

Documentation generated on Thu, 15 Apr 2010 20:23:05 +1200 by phpDocumentor 1.3.2