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

Source for file ScGrids.php

Documentation is available at ScGrids.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 Grids Helper
  19.  *
  20.  * @uses viewHelper SmartClient
  21.  */
  22. {
  23.  
  24.     /**
  25.      * @var Zend_View_Interface 
  26.      */
  27.     public $view;
  28.  
  29.     /**
  30.      * @var Array 
  31.      */
  32.     protected $_fields;
  33.  
  34.     /**
  35.      * 
  36.      * Return instance
  37.      * 
  38.      */
  39.     public function ScGrids()
  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 Field
  58.      *
  59.      * @param mixed $data If string, it must be the id of the field. If array, them we will loop on it
  60.      * @param string $title Title of the field
  61.      * @param array $options Additional options
  62.      * @return string 
  63.      * 
  64.      */
  65.     public function addField$data $title '' $options '' )
  66.     {
  67.         $newField array();
  68.         
  69.         // Check if it is an array
  70.         if is_array$data ) )
  71.         {
  72.             $newField $data;
  73.         }
  74.         else
  75.         {
  76.             // Add name and title to the new field
  77.             $newField['name'$data;
  78.             $newField['title'$title;
  79.             
  80.             // Check if options is array and do the loop
  81.             if is_array$options ) )
  82.             {
  83.                 foreach $options as $name => $value )
  84.                 {
  85.                     $newField[$name$value;
  86.                 }
  87.             }
  88.         }
  89.         
  90.         // TODO: Check if at least name and title are set on the new field
  91.         // Add field to the array
  92.         $this->_fields[$newField;
  93.     }
  94.  
  95.     /**
  96.      * Add Fields
  97.      *
  98.      * Get an array and do a loop using the addField function
  99.      * 
  100.      * @param array $data Array containing multiple fields
  101.      *  
  102.      */
  103.     public function addFields$data )
  104.     {
  105.         if is_array$data ) )
  106.         {
  107.             foreach $data as $row )
  108.             {
  109.                 $this->addField$row );
  110.             }
  111.         }
  112.     }
  113.     
  114.     /**
  115.      * Get Fields
  116.      *
  117.      * Return the current fields array
  118.      * 
  119.      * @return array 
  120.      *  
  121.      */
  122.     public function getFields()
  123.     {
  124.         return $this->_fields;
  125.     }
  126.     
  127.     /**
  128.      * 
  129.      * Clear fields
  130.      *
  131.      * Clear Fields array
  132.      *  
  133.      */
  134.     public function clearFields()
  135.     {
  136.         unset$this->_fields );
  137.     }
  138.  
  139.     /**
  140.      * Create
  141.      *
  142.      * Create the Smart Client grid
  143.      * 
  144.      * @param mixed $data If string, it must be the id of the field. If array, them we will loop on it
  145.      * @return string 
  146.      *  
  147.      */
  148.     public function create$data $dataSource '' $width '' $height '' $options '' )
  149.     {
  150.         $newGrid array();
  151.         
  152.         // Check if we have an array
  153.         if is_array$data ) )
  154.         {
  155.             $newGrid $data;
  156.         }
  157.         else
  158.         {
  159.             // Add vars to the new grid
  160.             $newGrid['ID'$data;
  161.             $newGrid['width'$width;
  162.             $newGrid['height'$height;
  163.             
  164.             // Set fields
  165.             $newGrid['fields'$this->_fields;
  166.             
  167.             // Add remove quotes str, to avoid datasource being quoted
  168.             $newGrid['dataSource'$this->addQuotesStr$dataSource );
  169.             
  170.             // Set default value for autoFetchData if it is not set
  171.             if empty$options['autoFetchData') )
  172.             {
  173.                 $options['autoFetchData'true;
  174.             }
  175.             
  176.             // Check if options is array and do the loop
  177.             if is_array$options ) )
  178.             {
  179.                 foreach $options as $name => $value )
  180.                 {
  181.                     $newGrid[$name$value;
  182.                 }
  183.             }
  184.         }
  185.         
  186.         // Encode all data
  187.         $dataEncoded Zend_Json::encode$newGrid );
  188.         
  189.         // Remove vars that shouldn't be quoted
  190.         $dataEncoded $this->removeQuotes$dataEncoded );
  191.         
  192.         // Generate js code
  193.         $js '
  194.         <script type="text/javascript">
  195.             isc.ListGrid.create(
  196.                 '$dataEncoded .'
  197.             );
  198.         </script>
  199.         ';
  200.         
  201.         return $js;
  202.     }
  203. }

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