Source for file ScMenus.php
Documentation is available at ScMenus.php
* An open source SmartClient library for PHP
* @author Fernando Marcelo Morgenstern <fernando@consultorpc.com>
* @copyright Copyright (c) 2009, ConsultorPC
* @license http://www.gnu.org/licenses/lgpl-3.0-standalone.html
* @link http://smartclientphp.com/
* Smart Client Menus Helper
* @param mixed $data If string, it must be the title of the item. If array, them we will loop on it
* @param string $click Click action
* @param string $subMenu Submenu, if applicable
* @param array $options Additional options
public function addItem( $data , $click = '' , $subMenu = '' , $options = '' )
// Check if it is an array
// Add name and click to the new item
$newItem['title'] = $data;
$newItem['click'] = $click;
// Check if there is a submenu and addQuotesStr
if ( !empty( $subMenu ) )
$newItem['subMenu'] = $subMenu;
// Check if options is array and do the loop
foreach ( $options as $name => $value )
$newItem[$name] = $value;
* Get an array and do a loop using the addItem function
* @param array $data Array containing multiple items
foreach ( $data as $row )
* @param mixed $data If string, it must be the id of the field. If array, them we will loop on it
* @param string $title Title of the field
* @param array $options Additional options
// Check if it is an array
$newSeparator = $options;
// Add this as an separator
$newSeparator['isSeparator'] = true;
// Check if options is array and do the loop
foreach ( $options as $name => $value )
$newSeparator[$name] = $value;
// Add separator to the array
$this->_items[] = $newSeparator;
* @param mixed $data If string, it must be the ID of the menu. If array, them we will loop through it
* @param boolean $createButton Set true if a button must also be created
* @param string $buttonTitle Title of the button
* @param array $options Additional options
* @param array $buttonOptions Additional options to button
public function create( $data , $createButton = true , $buttonTitle = '' , $options = '' , $buttonOptions = '' )
// Check if it is an array
// Add vars to the new button
$newMenu['data'] = $this->_items;
// Check if options is array and do the loop
foreach ( $options as $name => $value )
$newMenu[$name] = $value;
$dataEncoded = Zend_Json::encode( $newMenu );
// Remove vars that shouldn't be quoted
<script type="text/javascript">
// Check if we need to create a button
$newMenuButton['title'] = $buttonTitle;
$newMenuButton['menu'] = $this->addQuotesStr( $newMenu['ID'] );
// Check if options is array and do the loop
foreach ( $buttonOptions as $name => $value )
$newMenuButton[$name] = $value;
// Remove vars that shouldn't be quoted
|