* @copyright Copyright (c) 2009, ConsultorPC * @license http://www.gnu.org/licenses/lgpl-3.0-standalone.html * @link http://smartclientphp.com/ * @since Version 0.1 * @filesource */ /** * Smart Client DetailViewer Helper * */ class ScDetailViewer extends ScGeneral { /** * @var Array */ protected $_fields; /** * * Add Field * * @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 * @return string * */ public function addField( $data , $title = '' , $options = '' ) { $newField = array(); // Check if it is an array if ( is_array( $data ) ) { $newField = $data; } else { // Add name and title to the new field $newField['name'] = $data; $newField['title'] = $title; // Check if options is array and do the loop if ( is_array( $options ) ) { foreach ( $options as $name => $value ) { $newField[$name] = $value; } } } // Add field to the array $this->_fields[] = $newField; } /** * Add Fields * * Get an array and do a loop using the addField function * * @param array $data Array containing multiple fields * */ public function addFields( $data ) { if ( is_array( $data ) ) { foreach ( $data as $row ) { $this->addField( $row ); } } } /** * Get Fields * * Return the current fields array * * @return array * */ public function getFields() { return $this->_fields; } /** * * Clear fields * * Clear Fields array * */ public function clearFields() { unset( $this->_fields ); } /** * Create * * Create the Smart Client DetailViewer * * @param mixed $data If string, it must be the id of the field. If array, them we will loop on it * @return string * */ public function create( $data , $dataSource = '' , $width = '' , $height = '' , $options = '' ) { $newDetailViewer = array(); // Check if we have an array if ( is_array( $data ) ) { $newDetailViewer = $data; } else { // Add vars to the new grid $newDetailViewer['ID'] = $data; $newDetailViewer['width'] = $width; if ( !is_null( $newDetailViewer['height'] ) ) { $newDetailViewer['height'] = $height; } // Set fields $newDetailViewer['fields'] = $this->_fields; if ( !is_null( $newDetailViewer['dataSource'] ) ) { // Add remove quotes str, to avoid datasource being quoted $newDetailViewer['dataSource'] = $this->addQuotesStr( $dataSource ); } // Check if options is array and do the loop if ( is_array( $options ) ) { foreach ( $options as $name => $value ) { $newDetailViewer[$name] = $value; } } } // Encode all data $dataEncoded = json_encode( $newDetailViewer ); // Remove vars that shouldn't be quoted $dataEncoded = $this->removeQuotes( $dataEncoded ); // Generate js code $js = 'isc.DetailViewer.create( '. $dataEncoded .' );'; // Add script tag $js = $this->addScriptTags( $js ); return $js; } }