* @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 Tree Helper * * @uses viewHelper SmartClient */ class SmartClient_Helper_ScTree extends SmartClient_Helper_ScGeneral { /** * @var Zend_View_Interface */ public $view; /** * @var Array */ protected $_data = array(); /** * * Return instance * */ public function ScTree() { return $this; } /** * * Sets the view field * @param $view Zend_View_Interface * */ public function setView( Zend_View_Interface $view ) { $this->view = $view; } /** * * Add Data * * @param mixed $data Array containing the data for the tree */ public function addData( $data ) { // Check if it is an array if ( is_array( $data ) ) { $this->_data[] = $data; } } /** * Get Data * * Return the current data array * * @return array * */ public function getData() { return $this->_data; } /** * * Clear data * * Clear Data array * */ public function clearData() { unset( $this->_data ); } /** * * Create * * Creates a new tree * * @param mixed $data If string, it must be the ID of the Tree Grid. If array, them we will loop through it * @param string $dataSource Datasource * @param string $width Width of the button * @param string $height Height of the button * @param array $options Additional options * @return string * */ public function create( $data , $nameProperty = '' , $relationshipField = '' , $options = '' ) { $newTree = array(); // Check if it is an array if ( is_array( $data ) ) { $newTree = $data; } else { // Add vars to the new button $newTree['modelType'] = $data; $newTree['nameProperty'] = $nameProperty; // Check the current modelType and set relationship field according to each of them if ( $data == 'parent' ) { $newTree['parentIdField'] = $relationshipField; } else { $newTree['childrenProperty'] = $relationshipField; } // Set data $newTree['data'] = $this->_data; // Check if options is array and do the loop if ( is_array( $options ) ) { foreach ( $options as $name => $value ) { $newTree[$name] = $value; } } } // Encode data $dataEncoded = $this->encode( $newTree ); // Generate js code $js = 'isc.Tree.create( '. $dataEncoded .' )'; // Add script tag $js = $this->addScriptTags( $js ); return $js; } }