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

Source for file ScButtons.php

Documentation is available at ScButtons.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 Buttons Helper
  19.  *
  20.  * @uses viewHelper SmartClient
  21.  */
  22. {
  23.  
  24.     /**
  25.      * @var Zend_View_Interface 
  26.      */
  27.     public $view;
  28.  
  29.     /**
  30.      * 
  31.      * Return instance
  32.      * 
  33.      */
  34.     public function ScButtons()
  35.     {
  36.         return $this;
  37.     }
  38.  
  39.     /**
  40.      * 
  41.      * Sets the view field
  42.      * @param $view Zend_View_Interface
  43.      * 
  44.      */
  45.     public function setViewZend_View_Interface $view )
  46.     {
  47.         $this->view = $view;
  48.     }
  49.  
  50.     /**
  51.      * 
  52.      * Button
  53.      * 
  54.      * Creates a new button
  55.      *
  56.      * @param mixed $data If string, it must be the title of the button. If array, them we will loop through it
  57.      * @param string $click Onclick function
  58.      * @param string $buttonType Type of the button
  59.      * @param array $options Additional options
  60.      * @return string 
  61.      * 
  62.      */
  63.     public function create$data $click '' $buttonType '' $options '' )
  64.     {
  65.         $newButton array();
  66.         
  67.         // Set the valid buttons
  68.         $validButtons array'Button' 'IButton' 'ImgButton' );
  69.         
  70.         // Check if it is an array
  71.         if is_array$data ) )
  72.         {
  73.             // Get button type off the array
  74.             $buttonType $data['buttonType'];
  75.             unset$data['buttonType');
  76.             
  77.             $newButton $data;
  78.         }
  79.         else
  80.         {
  81.             // Add vars to the new button
  82.             $newButton['title'$data;
  83.             $newButton['click'$this->addQuotesStr$click );
  84.             
  85.             // Check if options is array and do the loop
  86.             if is_array$options ) )
  87.             {
  88.                 foreach $options as $name => $value )
  89.                 {
  90.                     $newButton[$name$value;
  91.                 }
  92.             }
  93.         }
  94.         
  95.         // Check if buttonType is valid
  96.         if !in_array$buttonType $validButtons ) )
  97.         {
  98.             // Set buttonType to a default value
  99.             $buttonType 'IButton';
  100.         }
  101.         
  102.         // Encode all data
  103.         $dataEncoded Zend_Json::encode$newButton );
  104.         
  105.         // Remove vars that shouldn't be quoted
  106.         $dataEncoded $this->removeQuotes$dataEncoded );
  107.         
  108.         // Generate js code
  109.         $js '
  110.         <script type="text/javascript">
  111.             isc.'$buttonType .'.create(
  112.                 '$dataEncoded .'
  113.             );
  114.         </script>
  115.         ';
  116.         
  117.         return $js;
  118.     }
  119. }

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