Lançado Adianti Framework 7.6!
Clique aqui para saber mais
menu

Adianti Solutions

API

Adianti, Framework, PHP, MVC, Active record, Front controller, IDE, RAD, Web, multiplataforma, geração de código, desenvolvimento rápido, relatórios, formulários, listagens, datagrids, gráficos, banco de dados, padrões de projeto, design patterns API do Adianti Framework.
API Docs
code
Selecione a classe

Source for file TTable.php

Documentation is available at TTable.php

  1. <?php
  2. namespace Adianti\Widget\Container;
  3.  
  4. use Adianti\Widget\Base\TElement;
  5. use Adianti\Widget\Container\TTableRow;
  6.  
  7. /**
  8.  * Creates a table layout, with rows and columns
  9.  *
  10.  * @version    7.4
  11.  * @package    widget
  12.  * @subpackage container
  13.  * @author     Pablo Dall'Oglio
  14.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  15.  * @license    http://www.adianti.com.br/framework-license
  16.  */
  17. class TTable extends TElement
  18. {
  19.     private $section;
  20.     
  21.     /**
  22.      * Class Constructor
  23.      */
  24.     public function __construct()
  25.     {
  26.         parent::__construct('table');
  27.         $this->section null;
  28.     }
  29.  
  30.     /**
  31.      * Create a table
  32.      */
  33.     public static function create($properties)
  34.     {
  35.         $table new TTable;
  36.         foreach ($properties as $property => $value)
  37.         {
  38.             $table->$property $value;
  39.         }
  40.         return $table;
  41.     }
  42.     
  43.     /**
  44.      * Add section
  45.      */
  46.     public function addSection($type)
  47.     {
  48.         if ($type == 'thead')
  49.         {
  50.             $this->section new TElement('thead');
  51.         }
  52.         else if ($type == 'tbody')
  53.         {
  54.             $this->section new TElement('tbody');
  55.         }
  56.         else if ($type == 'tfoot')
  57.         {
  58.             $this->section new TElement('tfoot');
  59.         }
  60.         parent::add($this->section);
  61.         
  62.         return $this->section;
  63.     }
  64.     
  65.     /**
  66.      * Add a new row (TTableRow object) to the table
  67.      * @return TTableRow 
  68.      */
  69.     public function addRow()
  70.     {
  71.         // creates a new Table Row
  72.         $row new TTableRow$this->section $this->section->getName('tbody');
  73.         
  74.         // add this row to the table element
  75.         if (isset($this->section))
  76.         {
  77.             $this->section->add($row);
  78.         }
  79.         else
  80.         {
  81.             parent::add($row);
  82.         }
  83.         return $row;
  84.     }
  85.     
  86.     /**
  87.      * Add a new row (TTableRow object) with many cells
  88.      * @param $cells Each argument is a row cell
  89.      * @return TTableRow 
  90.      */
  91.     public function addRowSet()
  92.     {
  93.         // creates a new Table Row
  94.         $row $this->addRow();
  95.         
  96.         $args func_get_args();
  97.         if ($args)
  98.         {
  99.             foreach ($args as $arg)
  100.             {
  101.                 if (is_array($arg))
  102.                 {
  103.                     $inst $row;
  104.                     call_user_func_array(array($inst'addMultiCell')$arg);
  105.                 }
  106.                 else
  107.                 {
  108.                     $row->addCell($arg($this->section && $this->section->getName(== 'thead''th' 'td');
  109.                 }
  110.             }
  111.         }
  112.         return $row;
  113.     }
  114.     
  115.     /**
  116.      * Create a table from data array
  117.      * @param $array_data Array with raw data
  118.      * @param $table_properties Array of CSS properties for table
  119.      * @param $header_properties Array of CSS properties for header
  120.      * @param $body_properties Array of CSS properties for body
  121.      */
  122.     public static function fromData($array_data$table_properties null$header_properties null$body_properties null)
  123.     {
  124.         $table new self;
  125.         if ($table_properties)
  126.         {
  127.             foreach ($table_properties as $prop=>$value)
  128.             {
  129.                 $table->$prop $value;
  130.             }
  131.         }
  132.         
  133.         $header array_keys(isset($array_data[0])?$array_data[0]:array());
  134.         
  135.         $thead new TElement('thead');
  136.         $table->add($thead);
  137.         
  138.         $tr new TTableRow;
  139.         $thead->add($tr);
  140.         foreach ($header as $cell)
  141.         {
  142.             $td $tr->addCell((string) $cell);
  143.             if ($header_properties)
  144.             {
  145.                 foreach ($header_properties as $prop=>$value)
  146.                 {
  147.                     $td->$prop $value;
  148.                 }
  149.             }
  150.         }
  151.         
  152.         $tbody new TElement('tbody');
  153.         $table->add($tbody);
  154.         
  155.         $i 0;
  156.         foreach ($array_data as $row)
  157.         {
  158.             $tr new TTableRow;
  159.             $tbody->add($tr);
  160.             $tr->{'class'($i %2==0'odd''even';
  161.             
  162.             foreach ($header as $key)
  163.             {
  164.                 $cell = isset($row[$key]$row[$key'';
  165.                 $td $tr->addCell((string) $cell);
  166.                 if ($body_properties)
  167.                 {
  168.                     foreach ($body_properties as $prop=>$value)
  169.                     {
  170.                         $td->$prop $value;
  171.                     }
  172.                 }
  173.             }
  174.             
  175.             $i ++;
  176.         }
  177.         
  178.         return $table;
  179.     }
  180. }