Source for file TMenu.php
Documentation is available at TMenu.php
namespace
Adianti \
Widget \
Menu ;
* @author Pablo Dall'Oglio
* @copyright Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
* @license http://www.adianti.com.br/framework-license
private $item_transformer ;
private $menu_transformer ;
* @param $xml SimpleXMLElement parsed from XML Menu
public function __construct ( $xml , $permission_callback =
NULL , $menu_level =
1 , $menu_class =
'dropdown-menu' , $item_class =
'' , $link_class =
'dropdown-toggle' , $item_transformer =
null , $menu_transformer =
null )
$this -> { 'class' } =
$menu_class .
" level-{
$menu_level } " ;
$this -> menu_class = $menu_class ;
$this -> menu_level = $menu_level ;
$this -> item_class = $item_class ;
$this -> link_class = $link_class ;
$this -> item_transformer = $item_transformer ;
$this -> menu_transformer = $menu_transformer ;
if ( $xml instanceof SimpleXMLElement )
$this -> parse ( $xml , $permission_callback ) ;
* @param $menuitem A TMenuItem Object
public function addMenuItem ( TMenuItem $menuitem )
if ( ! empty ( $this -> item_transformer ))
call_user_func ( $this -> item_transformer , $menuitem ) ;
$this -> items [ ] = $menuitem ;
public function getMenuItems ( )
* Parse a XMLElement reading menu entries
* @param $xml A SimpleXMLElement Object
* @param $permission_callback check permission callback
public function parse ( $xml , $permission_callback = NULL )
foreach ( $xml as $xmlElement )
$atts = $xmlElement -> attributes ( ) ;
$label = (string) $atts [ 'label' ] ;
$action = (string) $xmlElement -> action ;
$icon = (string) $xmlElement -> icon ;
$menuItem = new <a href="widget/menu/TMenuItem.html">TMenuItem</a> ( $label , $action , $icon , $this -> menu_level , $this -> menu_transformer ) ;
$menuItem -> setLinkClass ( $this -> link_class ) ;
$menu_atts = $xmlElement -> menu -> attributes ( ) ;
$menu_class = ! empty ( $menu_atts [ 'class' ] ) ? $menu_atts [ 'class' ] : $this -> menu_class ;
$menu = new <a href="widget/menu/TMenu.html">TMenu</a> ( $xmlElement -> menu -> menuitem , $permission_callback , $this -> menu_level +1 , $menu_class , $this -> item_class , $this -> link_class , $this -> item_transformer , $this -> menu_transformer ) ;
$menuItem -> setMenu ( $menu ) ;
$menuItem -> { 'class' } = $this -> item_class ;
// just child nodes have actions
if ( ! empty ( $action ) AND $permission_callback AND ( substr ( $action , 0 , 7 ) !== 'http://' ) AND ( substr ( $action , 0 , 8 ) !== 'https://' ))
// menus without permission check
// parent nodes are shown just when they have valid children (with permission)
* Shows the widget at the screen
foreach ( $this -> items as $item )