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

Source for file ScWindows.php

Documentation is available at ScWindows.php

  1. <?php
  2. /**
  3.  * SCPHP
  4.  *
  5.  * An open source SmartClient library for PHP
  6.  *
  7.  * @package        SCPHP
  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.  */
  21. class ScWindows extends ScGeneral 
  22. {
  23.     
  24.     /**
  25.      * @var Array Items for this window
  26.      */
  27.     protected $_items;
  28.     
  29.     /**
  30.      * 
  31.      * Add Item
  32.      *
  33.      * @param mixed $itemID ID of the item
  34.      * @return string 
  35.      * 
  36.      */
  37.     public function addItem$itemID )
  38.     {
  39.         $this->_items[$itemID;
  40.     }
  41.  
  42.     /**
  43.      * Add Multiple Items
  44.      * 
  45.      * @param array $data Array containing multiple items
  46.      *  
  47.      */
  48.     public function addItems$data )
  49.     {
  50.         if is_array$data ) )
  51.         {
  52.             foreach $data as $row )
  53.             {
  54.                 $this->addItem$row );
  55.             }
  56.         }
  57.     }
  58.     
  59.     /**
  60.      * Get Items
  61.      *
  62.      * Return the current items array
  63.      * 
  64.      * @return array 
  65.      *  
  66.      */
  67.     public function getItems()
  68.     {
  69.         return $this->_items;
  70.     }
  71.     
  72.     /**
  73.      * 
  74.      * Clear Items array
  75.      *  
  76.      */
  77.     public function clearItems()
  78.     {
  79.         unset$this->_items );
  80.     }
  81.  
  82.     /**
  83.      * 
  84.      * Creates a Window
  85.      *
  86.      * @param mixed $data If string, it must be the element ID. If array, them we will loop through it
  87.      * @param string $title Title of the window
  88.      * @param integer $width Width of the window
  89.      * @param integer $height Height of the window
  90.      * @param string $content Content of the window ( can be override by items )
  91.      * @param array $options Additional options
  92.      * @return string 
  93.      * 
  94.      */
  95.     public function create$data $title '' $width '' $height '' $content '' $options '' )
  96.     {
  97.         $newWindow array();
  98.         
  99.         // Check if it is an array
  100.         if is_array$data ) )
  101.         {
  102.             $newWindow $data;
  103.         }
  104.         else
  105.         {
  106.             // Add vars to the new button
  107.             $newWindow['ID'$data;
  108.             $newWindow['title'$title;
  109.             $newWindow['width'$width;
  110.             $newWindow['height'$height;
  111.             $newWindow['content'$content;
  112.             
  113.             // Generate the items string
  114.             $itemsStr implode',' $this->_items );
  115.             
  116.             // Set items
  117.             $newWindow['items'$this->addQuotesStr$itemsStr );
  118.             
  119.             // Set default value for autoSize if it is not set
  120.             if !isset$options['autoSize') )
  121.             {
  122.                 $options['autoSize'true;
  123.             }
  124.             
  125.             // Set default value for canDragResize if it is not set
  126.             if !isset$options['canDragResize') )
  127.             {
  128.                 $options['canDragResize'true;
  129.             }
  130.             
  131.             // Check if options is array and do the loop
  132.             if is_array$options ) )
  133.             {
  134.                 foreach $options as $name => $value )
  135.                 {
  136.                     $newWindow[$name$value;
  137.                 }
  138.             }
  139.         }
  140.         
  141.         // Encode all data
  142.         $dataEncoded json_encode$newWindow );
  143.         
  144.         // Remove vars that shouldn't be quoted
  145.         $dataEncoded $this->removeQuotes$dataEncoded );
  146.         
  147.         // Generate js code
  148.         $js '
  149.         <script type="text/javascript">
  150.             isc.Window.create(
  151.                 '$dataEncoded .'
  152.             );
  153.         </script>
  154.         ';
  155.         
  156.         return $js;
  157.     }
  158. }

Documentation generated on Wed, 29 Jul 2009 22:37:15 -0300 by phpDocumentor 1.4.1