Back to index

awl  0.53
Public Member Functions | Public Attributes
MenuSet Class Reference

List of all members.

Public Member Functions

 MenuSet ($div_id, $main_class= '', $active_class= 'active')
 

@-


AddOption ($label, $target, $title="", $active=false, $sortkey=null, $external=false)
 Add an option, which is a link.
AddSubMenu (&$submenu_set, $label, $target, $title="", $active=false, $sortkey=2000)
 Add an option, which is a submenu.
 _HasActive ()
 Does the menu have any options that are active.
 Size ()
 Find out how many options the menu has.
 _OptionExists ($newlabel)
 See if a menu already has this option.
 LinkActiveSubMenus ()
 Mark each MenuOption as active that has an active sub-menu entry.
 MakeSomethingActive ($test_pattern)
 Mark each MenuOption as active that has an active sub-menu entry.
 _CompareSequence ($a, $b)
 _CompareSequence is used in sorting the menu options into the sequence order
 Render ($submenus_inline=false)
 Render the menu tree to an HTML fragment.
 RenderAsCSS ($depth=0, $skip_empty=true)
 Render the menu tree to an HTML fragment.

Public Attributes

 $div_id
 $main_class
 $active_class
 $options
 $parent
 $last_sortkey
 $has_active_options

Detailed Description

Definition at line 222 of file MenuSet.php.


Member Function Documentation

MenuSet::_CompareSequence ( a,
b 
)

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

Parameters:
objectref$aThe first menu option
objectref$bThe second menu option
Returns:
int ( $a == b ? 0 ( $a > b ? 1 : -1 ))

Definition at line 448 of file MenuSet.php.

                                      {
    dbg_error_log("MenuSet",":_CompareSequence: Comparing %d with %d", $a->sortkey, $b->sortkey);
    return ($a->sortkey - $b->sortkey);
  }

Does the menu have any options that are active.

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

Parameters:
string$labelA Label for the new menu option
Returns:
boolean Whether the menu has options that are active.

Definition at line 354 of file MenuSet.php.

                         {
    if ( isset($this->has_active_options) ) {
      return $this->has_active_options;
    }
    foreach( $this->options AS $k => $v ) {
      if ( $v->IsActive() ) {
        $rc = true;
        return $rc;
      }
    }
    $rc = false;
    return $rc;
  }
MenuSet::_OptionExists ( newlabel)

See if a menu already has this option.

Returns:
boolean Whether the option already exists in the menu.

Definition at line 380 of file MenuSet.php.

                                      {
    $rc = false;
    foreach( $this->options AS $k => $v ) {
      if ( $newlabel == $v->label ) return $k;
    }
    return $rc;
  }

Here is the caller graph for this function:

& MenuSet::AddOption ( label,
target,
title = "",
active = false,
sortkey = null,
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.

Parameters:
string$labelA Label for the new menu option
string$targetThe URL to target for this option.
string$titleSome tooltip help for the title tag.
string$activeWhether this option should be marked as Active.
int$sortkeyAn (optional) value to allow option ordering.
externalopen this link in a new window/tab.
Returns:
mixed A reference to the MenuOption that was added, or false if none were added.

Definition at line 295 of file MenuSet.php.

                                                                                                   {
    if ( !isset($sortkey) ) {
      $sortkey = (isset($this->last_sortkey) ? $this->last_sortkey + 100 : 1000);
    }
    $this->last_sortkey = $sortkey;
    if ( version_compare(phpversion(), '5.0') < 0) {
      $new_option = new MenuOption( $label, $target, $title, $this->main_class, $sortkey );
    }
    else {
      $new_option = new MenuOption( $label, $target, $title, $this->main_class, $sortkey );
    }
    if ( ($old_option = $this->_OptionExists( $label )) === false ) {
      $this->options[] = &$new_option ;
    }
    else {
      dbg_error_log("MenuSet",":AddOption: Replacing existing option # $old_option ($label)");
      $this->options[$old_option] = &$new_option;  // Overwrite the existing option
    }
    if ( is_bool($active) && $active == false && $_SERVER['REQUEST_URI'] == $target ) {
      // If $active is not set, then we look for an exact match to the current URL
      $new_option->Active( $this->active_class );
    }
    else if ( is_bool($active) && $active ) {
      // When active is specified as a boolean, the recognition has been done externally
      $new_option->Active( $this->active_class );
    }
    else if ( is_string($active) && preg_match($active,$_SERVER['REQUEST_URI']) ) {
      // If $active is a string, then we match the current URL to that as a Perl regex
      $new_option->Active( $this->active_class );
    }

    if ( $external == true ) $new_option->Set('target', '_blank');

    return $new_option ;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

& MenuSet::AddSubMenu ( &$  submenu_set,
label,
target,
title = "",
active = false,
sortkey = 2000 
)

Add an option, which is a submenu.

Parameters:
object&$submenu_setA reference to a menu tree
string$labelA Label for the new menu option
string$targetThe URL to target for this option.
string$titleSome tooltip help for the title tag.
string$activeWhether this option should be marked as Active.
int$sortkeyAn (optional) value to allow option ordering.
Returns:
mixed A reference to the MenuOption that was added, or false if none were added.

Definition at line 341 of file MenuSet.php.

                                                                                                  {
    $new_option =& $this->AddOption( $label, $target, $title, $active, $sortkey );
    $submenu_set->parent = &$new_option ;
    $new_option->AddSubmenu( $submenu_set );
    return $new_option ;
  }

Here is the call graph for this function:

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.

Definition at line 395 of file MenuSet.php.

                                 {
    $this->has_active_options = false;
    foreach( $this->options AS $k => $v ) {
      if ( isset($v->submenu_set) && $v->submenu_set->_HasActive() ) {
        // Note that we need to do it this way, since $v is a copy, not a reference
        $this->options[$k]->Active( $this->active_class );
        $this->has_active_options = true;
      }
    }
  }

Here is the caller graph for this function:

MenuSet::MakeSomethingActive ( test_pattern)

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.

Definition at line 413 of file MenuSet.php.

                                                {
    if ( $this->has_active_options ) return;  // Already true.
    foreach( $this->options AS $k => $v ) {
      if ( isset($v->submenu_set) && $v->submenu_set->_HasActive() ) {
        // Note that we need to do it this way, since $v is a copy, not a reference
        $this->options[$k]->Active( $this->active_class );
        $this->has_active_options = true;
        return $this->has_active_options;
      }
    }

    foreach( $this->options AS $k => $v ) {
      if ( isset($v->submenu_set) && $v->submenu_set->MakeSomethingActive($test_pattern) ) {
        // Note that we need to do it this way, since $v is a copy, not a reference
        $this->options[$k]->Active( $this->active_class );
        $this->has_active_options = true;
        return $this->has_active_options;
      }
      else {
        if ( $this->options[$k]->MaybeActive( $test_pattern, $this->active_class ) ) {
          $this->has_active_options = true;
          return $this->has_active_options;
        }
      }
    }
    return false;
  }
MenuSet::MenuSet ( div_id,
main_class = '',
active_class = 'active' 
)

@-

Start a new MenuSet with no options.

Parameters:
string$div_idAn ID for the HTML div that the menu will be presented in.
string$main_classA CSS class for most menu options.
string$active_classA CSS class for active menu options.

Definition at line 276 of file MenuSet.php.

                                                                          {
    $this->options = array();
    $this->main_class = $main_class;
    $this->active_class = $active_class;
    $this->div_id = $div_id;
  }
MenuSet::Render ( submenus_inline = false)

Render the menu tree to an HTML fragment.

Parameters:
boolean$submenus_inlineIndicate 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.

Definition at line 462 of file MenuSet.php.

                                              {
    if ( !isset($this->has_active_options) ) {
      $this->LinkActiveSubMenus();
    }
    $options = $this->options;
    usort($options,"_CompareMenuSequence");
    $render_sub_menus = false;
    $r = "<div id=\"$this->div_id\">\n";
    foreach( $options AS $k => $v ) {
      $r .= $v->Render();
      if ( $v->IsActive() && isset($v->submenu_set) && $v->submenu_set->Size() > 0 ) {
        $render_sub_menus = $v->submenu_set;
        if ( $submenus_inline )
          $r .= $render_sub_menus->Render();
      }
    }
    $r .="</div>\n";
    if ( !$submenus_inline && $render_sub_menus != false ) {
      $r .= $render_sub_menus->Render();
    }
    return $r;
  }

Here is the call graph for this function:

MenuSet::RenderAsCSS ( depth = 0,
skip_empty = true 
)

Render the menu tree to an HTML fragment.

Parameters:
boolean$submenus_inlineIndicate 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.

Definition at line 494 of file MenuSet.php.

                                                         {
    $this->LinkActiveSubMenus();

    if ( $depth > 0 )
      $class = "submenu" . $depth;
    else
      $class = "menu";

    $options = $this->options;
    usort($options,"_CompareMenuSequence");

    $r = "<div id=\"$this->div_id\" class=\"$class\">\n<ul>\n";
    foreach( $options AS $k => $v ) {
      if ( $skip_empty && isset($v->submenu_set) && $v->submenu_set->Size() < 1 ) continue;
      $r .= "<li>".$v->Render();
      if ( isset($v->submenu_set) && $v->submenu_set->Size() > 0 ) {
        $r .= $v->submenu_set->RenderAsCSS($depth+1);
      }
      $r .= "</li>\n";
    }
    $r .="</ul></div>\n";
    return $r;
  }

Here is the call graph for this function:

Find out how many options the menu has.

Returns:
int The number of options in the menu.

Definition at line 372 of file MenuSet.php.

                   {
    return count($this->options);
  }

Member Data Documentation

Definition at line 242 of file MenuSet.php.

Definition at line 230 of file MenuSet.php.

Definition at line 267 of file MenuSet.php.

Definition at line 260 of file MenuSet.php.

Definition at line 236 of file MenuSet.php.

Definition at line 248 of file MenuSet.php.

Definition at line 254 of file MenuSet.php.


The documentation for this class was generated from the following file: