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

Source for file ScWindows.php

Documentation is available at ScWindows.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 Windows Helper
  19.  *
  20.  * @uses viewHelper SmartClient
  21.  */
  22. {
  23.  
  24.     /**
  25.      * @var Zend_View_Interface 
  26.      */
  27.     public $view;
  28.     
  29.     /**
  30.      * @var Array Items for this window
  31.      */
  32.     protected $_items;
  33.  
  34.     /**
  35.      * 
  36.      * Return instance
  37.      * 
  38.      */
  39.     public function ScWindows()
  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 Item
  58.      *
  59.      * @param mixed $itemID ID of the item
  60.      * @return string 
  61.      * 
  62.      */
  63.     public function addItem$itemID )
  64.     {
  65.         $this->_items[$itemID;
  66.     }
  67.  
  68.     /**
  69.      * Add Multiple Items
  70.      * 
  71.      * @param array $data Array containing multiple items
  72.      *  
  73.      */
  74.     public function addItems$data )
  75.     {
  76.         if is_array$data ) )
  77.         {
  78.             foreach $data as $row )
  79.             {
  80.                 $this->addItem$row );
  81.             }
  82.         }
  83.     }
  84.     
  85.     /**
  86.      * Get Items
  87.      *
  88.      * Return the current items array
  89.      * 
  90.      * @return array 
  91.      *  
  92.      */
  93.     public function getItems()
  94.     {
  95.         return $this->_items;
  96.     }
  97.     
  98.     /**
  99.      * 
  100.      * Clear Items array
  101.      *  
  102.      */
  103.     public function clearItems()
  104.     {
  105.         unset$this->_items );
  106.     }
  107.  
  108.     /**
  109.      * 
  110.      * Creates a Window
  111.      *
  112.      * @param mixed $data If string, it must be the element ID. If array, them we will loop through it
  113.      * @param string $title Title of the window
  114.      * @param integer $width Width of the window
  115.      * @param integer $height Height of the window
  116.      * @param string $content Content of the window ( can be override by items )
  117.      * @param array $options Additional options
  118.      * @return string 
  119.      * 
  120.      */
  121.     public function create$data $title '' $width '' $height '' $content '' $options '' )
  122.     {
  123.         $newWindow array();
  124.         
  125.         // Check if it is an array
  126.         if is_array$data ) )
  127.         {
  128.             $newWindow $data;
  129.         }
  130.         else
  131.         {
  132.             // Add vars to the new button
  133.             $newWindow['ID'$data;
  134.             $newWindow['title'$title;
  135.             $newWindow['width'$width;
  136.             $newWindow['height'$height;
  137.             $newWindow['content'$content;
  138.             
  139.             // Generate the items string
  140.             $itemsStr implode',' $this->_items );
  141.             
  142.             // Set items
  143.             $newWindow['items'$this->addQuotesStr$itemsStr );
  144.             
  145.             // Set default value for autoSize if it is not set
  146.             if !isset$options['autoSize') )
  147.             {
  148.                 $options['autoSize'true;
  149.             }
  150.             
  151.             // Set default value for canDragResize if it is not set
  152.             if !isset$options['canDragResize') )
  153.             {
  154.                 $options['canDragResize'true;
  155.             }
  156.             
  157.             // Check if options is array and do the loop
  158.             if is_array$options ) )
  159.             {
  160.                 foreach $options as $name => $value )
  161.                 {
  162.                     $newWindow[$name$value;
  163.                 }
  164.             }
  165.         }
  166.         
  167.         // Encode all data
  168.         $dataEncoded Zend_Json::encode$newWindow );
  169.         
  170.         // Remove vars that shouldn't be quoted
  171.         $dataEncoded $this->removeQuotes$dataEncoded );
  172.         
  173.         // Generate js code
  174.         $js '
  175.         <script type="text/javascript">
  176.             isc.Window.create(
  177.                 '$dataEncoded .'
  178.             );
  179.         </script>
  180.         ';
  181.         
  182.         return $js;
  183.     }
  184. }

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