Class MenuSet
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:
require("MenuSet.php"); $main_menu = new MenuSet('menu', 'menu', 'menu_active'); ... $other_menu = new MenuSet('submenu', 'submenu', 'submenu_active'); $other_menu->AddOption("Extra Other","/extraother.php","Submenu option to do extra things."); $other_menu->AddOption("Super Other","/superother.php","Submenu option to do super things."); $other_menu->AddOption("Meta Other","/metaother.php","Submenu option to do meta things."); ... $main_menu->AddOption("Do This","/dothis.php","Option to do this thing."); $main_menu->AddOption("Do That","/dothat.php","Option to do all of that."); $main_menu->AddSubMenu( $other_menu, "Do The Other","/dotheother.php","Submenu to do all of the other things.", true); ... if ( isset($main_menu) && is_object($main_menu) ) { $main_menu->AddOption("Home","/","Go back to the home page"); echo $main_menu->Render(); }
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.
Copyright: Catalyst IT Ltd, Morphoss Ltd http://www.morphoss.com/
License: GNU GPL v2 or later
Author: Andrew McMillan andrew@mcmillan.net.nz
Located at MenuSet.php
public
|
|
public
mixed
&
|
|
public
mixed
&
|
#
AddSubMenu( object & $submenu_set, string $label, string $target, string $title = "", string $active = false, integer $sortkey = 2000 )
Add an option, which is a submenu |
public
boolean
|
#
_HasActive( string $label,… )
Does the menu have any options that are active. Most likely used so that we can then set the parent menu as active. |
public
integer
|
|
public
boolean
|
|
public
|
|
public
|
#
MakeSomethingActive( $test_pattern )
Mark each MenuOption as active that has an active sub-menu entry. |
public
integer
|
#
_CompareSequence( objectref $a, objectref $b )
_CompareSequence is used in sorting the menu options into the sequence order |
public
string
|
|
public
string
|
public
string
|
$div_id
CSS style to use for the div around the options |
|
public
string
|
$main_class
CSS style to use for normal menu option |
|
public
string
|
$active_class
CSS style to use for active menu option |
|
public
array
|
$options
An array of MenuOption objects |
|
public
reference
|
$parent
Any menu option that happens to parent this set |
|
public
|
$last_sortkey
The sortkey used by any previous option |
|
public
reference
|
$has_active_options
Will be set to true or false when we link active sub-menus, but will be unset until we do that. |