* @copyright Copyright (c) 2010, ConsultorPC * @license http://www.gnu.org/licenses/lgpl-3.0-standalone.html * @link http://smartclientphp.com/ * @since Version 0.1b * @filesource */ /** * Smart Client Layout Helper * */ class ScLayout extends ScGeneral { /** * @var Array All members */ protected $_members; /** * * Add Member * * @param string $data Content of the member. Can be the ID of an element * */ public function addMember( $data ) { $newMember = $data; // Add member to the array $this->_members[] = $newMember; } /** * Add Multiple Members * * @param array $data Array containing multiple members * */ public function addMembers( $data ) { if ( is_array( $data ) ) { foreach ( $data as $row ) { $this->addMember( $row ); } } } /** * Get Members * * Return the current members array * * @return array * */ public function getMembers() { return $this->_members; } /** * * Clear Members array * */ public function clearMembers() { unset( $this->_members ); } /** * * Creates a Layout * * @param mixed $data If string, it must be the element ID. If array, them we will loop through it * @param integer $width Width of the tab set * @param integer $height Height of the tab set * @param string $type Type of the layout * @param array $options Additional options * @return string * */ public function create( $data , $width = '' , $height = '' , $layoutType = 'HLayout' , $options = '' ) { $newLayout = array(); // Set the valid type of layouts $validTypes = array( 'HLayout' , 'VLayout' ); // Check if it is an array if ( is_array( $data ) ) { // Get layout type off the array $layoutType = $data['layoutType']; unset( $data['layoutType'] ); $newLayout = $data; } else { // Add vars to the new button $newLayout['ID'] = $data; $newLayout['width'] = $width; $newLayout['height'] = $height; // Set members $newLayout['members'] = $this->_members; // Check if options is array and do the loop if ( is_array( $options ) ) { foreach ( $options as $name => $value ) { $newLayout[$name] = $value; } } } // Check if layoutType is valid if ( !in_array( $layoutType , $validTypes ) ) { // Set layoutType to a default value $layoutType = 'HLayout'; } // Encode data $dataEncoded = $this->encode( $newLayout ); // Generate js code $js = 'isc.'. $layoutType .'.create( '. $dataEncoded .' );'; // Add script tag $js = $this->addScriptTags( $js ); return $js; } }