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

Source for file ScTrees.php

Documentation is available at ScTrees.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 Trees 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 ScTrees()
  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.      * 
  141.      * Create
  142.      * 
  143.      * Creates a new tree
  144.      *
  145.      * @param mixed $data If string, it must be the ID of the Tree. If array, them we will loop through it
  146.      * @param string $dataSource Datasource
  147.      * @param string $width Width of the button
  148.      * @param string $height Height of the button
  149.      * @param array $options Additional options
  150.      * @return string 
  151.      * 
  152.      */
  153.     public function create$data $dataSource '' $width '' $height '' $options '' )
  154.     {
  155.         $newTree array();
  156.         
  157.         // Check if it is an array
  158.         if is_array$data ) )
  159.         {
  160.             $newTree $data;
  161.         }
  162.         else
  163.         {
  164.             // Add vars to the new button
  165.             $newTree['ID'$data;
  166.             $newTree['dataSource'$this->addQuotesStr$dataSource );
  167.             $newTree['width'$width;
  168.             $newTree['height'$height;
  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.             // Set fields
  177.             $newTree['fields'$this->_fields;
  178.             
  179.             // Check if options is array and do the loop
  180.             if is_array$options ) )
  181.             {
  182.                 foreach $options as $name => $value )
  183.                 {
  184.                     $newTree[$name$value;
  185.                 }
  186.             }
  187.         }
  188.         
  189.         // Encode all data
  190.         $dataEncoded Zend_Json::encode$newTree );
  191.         
  192.         // Remove vars that shouldn't be quoted
  193.         $dataEncoded $this->removeQuotes$dataEncoded );
  194.         
  195.         // Generate js code
  196.         $js '
  197.         <script type="text/javascript">
  198.             isc.TreeGrid.create(
  199.                 '$dataEncoded .'
  200.             );
  201.         </script>
  202.         ';
  203.         
  204.         return $js;
  205.     }
  206. }

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