Overview

Packages

  • awl
    • AuthPlugin
    • AwlDatabase
    • Browser
    • classEditor
    • DataEntry
    • DataUpdate
    • EMail
    • iCalendar
    • MenuSet
    • PgQuery
    • Session
    • Translation
    • User
    • Utilities
    • Validation
    • vCalendar
    • vComponent
    • XMLDocument
    • XMLElement
  • None

Classes

  • MenuOption
  • MenuSet

Functions

  • _CompareMenuSequence
  • Overview
  • Package
  • Class

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.

Package: awl\MenuSet
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
Methods summary
public
# MenuSet( string $div_id, string $main_class = '', string $active_class = 'active' )

Start a new MenuSet with no options.

Start a new MenuSet with no options.

Parameters

$div_id
An ID for the HTML div that the menu will be presented in.
$main_class
A CSS class for most menu options.
$active_class
A CSS class for active menu options.
public mixed &
# AddOption( string $label, string $target, string $title = "", string $active = false, integer $sortkey = null, external $external = false )

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.

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.

Parameters

$label
A Label for the new menu option
$target
The URL to target for this option.
$title
Some tooltip help for the title tag.
$active
Whether this option should be marked as Active.
$sortkey
An (optional) value to allow option ordering.
$external
this link in a new window/tab.

Returns

mixed
A reference to the MenuOption that was added, or false if none were added.
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

Add an option, which is a submenu

Parameters

$submenu_set
$submenu_set A reference to a menu tree
$label
A Label for the new menu option
$target
The URL to target for this option.
$title
Some tooltip help for the title tag.
$active
Whether this option should be marked as Active.
$sortkey
An (optional) value to allow option ordering.

Returns

mixed
A reference to the MenuOption that was added, or false if none were added.
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.

Does the menu have any options that are active. Most likely used so that we can then set the parent menu as active.

Parameters

$label,…
A Label for the new menu option

Returns

boolean
Whether the menu has options that are active.
public integer
# Size( )

Find out how many options the menu has.

Find out how many options the menu has.

Returns

integer
The number of options in the menu.
public boolean
# _OptionExists( $newlabel )

See if a menu already has this option

See if a menu already has this option

Returns

boolean
Whether the option already exists in the menu.
public
# LinkActiveSubMenus( )

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

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.

public
# MakeSomethingActive( $test_pattern )

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

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.

public integer
# _CompareSequence( objectref $a, objectref $b )

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

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

Parameters

$a
The first menu option
$b
The second menu option

Returns

integer
( $a == b ? 0 ( $a > b ? 1 : -1 ))
public string
# Render( boolean $submenus_inline = false )

Render the menu tree to an HTML fragment.

Render the menu tree to an HTML fragment.

Parameters

$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.

Returns

string
The HTML fragment.
public string
# RenderAsCSS( boolean $depth = 0, $skip_empty = true )

Render the menu tree to an HTML fragment.

Render the menu tree to an HTML fragment.

Parameters

$depth

$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.

$skip_empty

Returns

string
The HTML fragment.
Properties summary
public string $div_id

CSS style to use for the div around the options

CSS style to use for the div around the options

#
public string $main_class

CSS style to use for normal menu option

CSS style to use for normal menu option

#
public string $active_class

CSS style to use for active menu option

CSS style to use for active menu option

#
public array $options

An array of MenuOption objects

An array of MenuOption objects

#
public reference $parent

Any menu option that happens to parent this set

Any menu option that happens to parent this set

#
public MenuSet::$last_sortkey $last_sortkey

The sortkey used by any previous option

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.

Will be set to true or false when we link active sub-menus, but will be unset until we do that.

#
API documentation generated by ApiGen