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

Source for file ScTabs.php

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

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