SCZF
[ class tree: SCZF ] [ index: SCZF ] [ all elements ]

Source for file ScLayouts.php

Documentation is available at ScLayouts.php

  1. <?php
  2. /**
  3.  * SCZF
  4.  *
  5.  * An open source SmartClient View Helper for Zend Framework
  6.  *
  7.  * @package        SCZF
  8.  * @author        Fernando Marcelo Morgenstern <fernando@consultorpc.com>
  9.  * @copyright    Copyright (c) 2009, ConsultorPC
  10.  * @license        http://www.gnu.org/licenses/lgpl-3.0-standalone.html
  11.  * @link        http://smartclientphp.com/
  12.  * @since        Version 0.1b
  13.  * @filesource
  14.  */
  15.  
  16.  
  17. /**
  18.  * Smart Client Layouts Helper
  19.  *
  20.  * @uses viewHelper SmartClient
  21.  */
  22. {
  23.  
  24.     /**
  25.      * @var Zend_View_Interface 
  26.      */
  27.     public $view;
  28.     
  29.     /**
  30.      * @var Array All members
  31.      */
  32.     protected $_members;
  33.  
  34.     /**
  35.      * 
  36.      * Return instance
  37.      * 
  38.      */
  39.     public function ScLayouts()
  40.     {
  41.         return $this;
  42.     }
  43.  
  44.     /**
  45.      * 
  46.      * Sets the view field
  47.      * @param $view Zend_View_Interface
  48.      * 
  49.      */
  50.     public function setViewZend_View_Interface $view )
  51.     {
  52.         $this->view = $view;
  53.     }
  54.     
  55.     /**
  56.      * 
  57.      * Add Member
  58.      *
  59.      * @param string $data Content of the member. Can be the ID of an element
  60.      * 
  61.      */
  62.     public function addMember$data )
  63.     {
  64.         $newMember $data;
  65.         
  66.         // Add member to the array
  67.         $this->_members[$newMember;
  68.     }
  69.  
  70.     /**
  71.      * Add Multiple Members
  72.      * 
  73.      * @param array $data Array containing multiple members
  74.      *  
  75.      */
  76.     public function addMembers$data )
  77.     {
  78.         if is_array$data ) )
  79.         {
  80.             foreach $data as $row )
  81.             {
  82.                 $this->addMember$row );
  83.             }
  84.         }
  85.     }
  86.     
  87.     /**
  88.      * Get Members
  89.      *
  90.      * Return the current members array
  91.      * 
  92.      * @return array 
  93.      *  
  94.      */
  95.     public function getMembers()
  96.     {
  97.         return $this->_members;
  98.     }
  99.     
  100.     /**
  101.      * 
  102.      * Clear Members array
  103.      *  
  104.      */
  105.     public function clearMembers()
  106.     {
  107.         unset$this->_members );
  108.     }
  109.  
  110.     /**
  111.      * 
  112.      * Creates a Layout
  113.      *
  114.      * @param mixed $data If string, it must be the element ID. If array, them we will loop through it
  115.      * @param integer $width Width of the tab set
  116.      * @param integer $height Height of the tab set
  117.      * @param string $type Type of the layout
  118.      * @param array $options Additional options
  119.      * @return string 
  120.      * 
  121.      */
  122.     public function create$data $width '' $height '' $layoutType 'HLayout' $options '' )
  123.     {
  124.         $newLayout array();
  125.         
  126.         // Set the valid type of layouts
  127.         $validTypes array'HLayout' 'VLayout' );
  128.         
  129.         // Check if it is an array
  130.         if is_array$data ) )
  131.         {
  132.             // Get layout type off the array
  133.             $layoutType $data['layoutType'];
  134.             unset$data['layoutType');
  135.             
  136.             $newLayout $data;
  137.         }
  138.         else
  139.         {
  140.             // Add vars to the new button
  141.             $newLayout['ID'$data;
  142.             $newLayout['width'$width;
  143.             $newLayout['height'$height;
  144.             
  145.             // Set members
  146.             $newLayout['members'$this->_members;
  147.             
  148.             // Check if options is array and do the loop
  149.             if is_array$options ) )
  150.             {
  151.                 foreach $options as $name => $value )
  152.                 {
  153.                     $newLayout[$name$value;
  154.                 }
  155.             }
  156.         }
  157.         
  158.         // Check if layoutType is valid
  159.         if !in_array$layoutType $validTypes ) )
  160.         {
  161.             // Set layoutType to a default value
  162.             $layoutType 'HLayout';
  163.         }
  164.         
  165.         // Encode all data
  166.         $dataEncoded Zend_Json::encode$newLayout );
  167.         
  168.         // Remove vars that shouldn't be quoted
  169.         $dataEncoded $this->removeQuotes$dataEncoded );
  170.         
  171.         // Generate js code
  172.         $js '
  173.         <script type="text/javascript">
  174.             isc.'$layoutType .'.create(
  175.                 '$dataEncoded .'
  176.             );
  177.         </script>
  178.         ';
  179.         
  180.         return $js;
  181.     }
  182. }

Documentation generated on Mon, 20 Jul 2009 16:51:57 -0300 by phpDocumentor 1.4.1