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

Source for file ScLayouts.php

Documentation is available at ScLayouts.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 Layouts Helper
  19.  *
  20.  */
  21. class ScLayouts extends ScGeneral 
  22. {
  23.  
  24.     /**
  25.      * @var Array All members
  26.      */
  27.     protected $_members;
  28.     
  29.     /**
  30.      * 
  31.      * Add Member
  32.      *
  33.      * @param string $data Content of the member. Can be the ID of an element
  34.      * 
  35.      */
  36.     public function addMember$data )
  37.     {
  38.         $newMember $data;
  39.         
  40.         // Add member to the array
  41.         $this->_members[$newMember;
  42.     }
  43.  
  44.     /**
  45.      * Add Multiple Members
  46.      * 
  47.      * @param array $data Array containing multiple members
  48.      *  
  49.      */
  50.     public function addMembers$data )
  51.     {
  52.         if is_array$data ) )
  53.         {
  54.             foreach $data as $row )
  55.             {
  56.                 $this->addMember$row );
  57.             }
  58.         }
  59.     }
  60.     
  61.     /**
  62.      * Get Members
  63.      *
  64.      * Return the current members array
  65.      * 
  66.      * @return array 
  67.      *  
  68.      */
  69.     public function getMembers()
  70.     {
  71.         return $this->_members;
  72.     }
  73.     
  74.     /**
  75.      * 
  76.      * Clear Members array
  77.      *  
  78.      */
  79.     public function clearMembers()
  80.     {
  81.         unset$this->_members );
  82.     }
  83.  
  84.     /**
  85.      * 
  86.      * Creates a Layout
  87.      *
  88.      * @param mixed $data If string, it must be the element ID. If array, them we will loop through it
  89.      * @param integer $width Width of the tab set
  90.      * @param integer $height Height of the tab set
  91.      * @param string $type Type of the layout
  92.      * @param array $options Additional options
  93.      * @return string 
  94.      * 
  95.      */
  96.     public function create$data $width '' $height '' $layoutType 'HLayout' $options '' )
  97.     {
  98.         $newLayout array();
  99.         
  100.         // Set the valid type of layouts
  101.         $validTypes array'HLayout' 'VLayout' );
  102.         
  103.         // Check if it is an array
  104.         if is_array$data ) )
  105.         {
  106.             // Get layout type off the array
  107.             $layoutType $data['layoutType'];
  108.             unset$data['layoutType');
  109.             
  110.             $newLayout $data;
  111.         }
  112.         else
  113.         {
  114.             // Add vars to the new button
  115.             $newLayout['ID'$data;
  116.             $newLayout['width'$width;
  117.             $newLayout['height'$height;
  118.             
  119.             // Set members
  120.             $newLayout['members'$this->_members;
  121.             
  122.             // Check if options is array and do the loop
  123.             if is_array$options ) )
  124.             {
  125.                 foreach $options as $name => $value )
  126.                 {
  127.                     $newLayout[$name$value;
  128.                 }
  129.             }
  130.         }
  131.         
  132.         // Check if layoutType is valid
  133.         if !in_array$layoutType $validTypes ) )
  134.         {
  135.             // Set layoutType to a default value
  136.             $layoutType 'HLayout';
  137.         }
  138.         
  139.         // Encode all data
  140.         $dataEncoded json_encode$newLayout );
  141.         
  142.         // Remove vars that shouldn't be quoted
  143.         $dataEncoded $this->removeQuotes$dataEncoded );
  144.         
  145.         // Generate js code
  146.         $js '
  147.         <script type="text/javascript">
  148.             isc.'$layoutType .'.create(
  149.                 '$dataEncoded .'
  150.             );
  151.         </script>
  152.         ';
  153.         
  154.         return $js;
  155.     }
  156. }

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