Axiom (v1.2.0)

A lightweight PHP framework
H:/Workspace/php-axiom/www/php-axiom/libraries/axiom/axTableHelper.class.php
Go to the documentation of this file.
00001 <?php
00016 class axTableHelper extends axBaseHelper {
00017     
00022     public $head = null;
00023     
00028     public $foot = null;
00029     
00034     public $body = null;
00035     
00040     public function __construct ($caption = false) {
00041         parent::__construct('table');
00042         if ($caption)
00043             $this->appendChild(axCaptionHelper::export($caption));
00044             
00045         $this->head = &$this->_children['head'];
00046         $this->foot = &$this->_children['foot'];
00047         $this->body = &$this->_children['body'];
00048             
00049         $this->setHead();
00050         $this->setFoot();
00051         $this->setBody();
00052     }
00053     
00061     public function setColumnNames (array $columns, $filter = true) {
00062         if ($filter)
00063             $this->body->setFilter(array_keys($columns));
00064         return $this->setHead(array($columns));
00065     }
00066     
00075     public function setHead ($rows = null) {
00076         $this->_children['head'] = axTableRowGroupHelper::export('head');
00077         if (!empty($rows))
00078             $this->head->addRows($rows);
00079         return $this;
00080     }
00081     
00090     public function setFoot ($rows = null) {
00091         $this->_children['foot'] = axTableRowGroupHelper::export('foot');
00092         if (!empty($rows))
00093             $this->foot->addRows($rows);
00094         return $this;
00095     }
00096     
00105     public function setBody ($rows = null) {
00106         $this->_children['body'] = axTableRowGroupHelper::export('body');
00107         if (!empty($rows))
00108             $this->body->addRows($rows);
00109         return $this;
00110     }
00111     
00125     public function addRow ($row, $to = false) {
00126         switch (strtolower($to)) {
00127             case 'head': case 'thead': $rowgroup = 'head'; break;
00128             case 'foot': case 'tfoot': $rowgroup = 'foot'; break;
00129             case 'body': case 'tbody': default: $rowgroup = 'body';
00130         }
00131         $this->$rowgroup->addRow($row);
00132         return $this;
00133     }
00134     
00142     public function addRows ($rows, $to = false) {
00143         foreach ($rows as $row)
00144             $this->addRow($row, $to);
00145         
00146         return $this;
00147     }
00148     
00153     public function addColGroup () {
00154         return $this->appendChild(axColGroupHelper::export());
00155     }
00156     
00160     public function __toString () {
00161         // Order the children elements according to xhtml DTD
00162         $children = array(
00163             'caption' => array(),
00164             'colgroup' => array(),
00165             'col' => array(),
00166             'thead' => array(),
00167             'tfoot' => array(),
00168             'tbody' => array(),
00169         );
00170         foreach ($this->_children as $node) {
00171             switch ($node) {
00172                 case $node instanceof axCaptionHelper: $children['caption'][] = $node; break;
00173                 case $node instanceof axColGroupHelper: $children['colgroup'][] = $node; break;
00174                 case $node instanceof axColHelper: $children['col'][] = $node; break;
00175                 case $node instanceof axTableRowGroupHelper:
00176                     switch($node->getType()) {
00177                         case 'head': $children['thead'][] = $node; break;
00178                         case 'foot': $children['tfoot'][] = $node; break;
00179                         case 'body': $children['tbody'][] = $node; break;
00180                     }
00181                     break;
00182             }
00183         }
00184         $this->_children = call_user_func_array('array_merge', $children);
00185         return parent::__toString();
00186     }
00187     
00194     public static function export ($caption = false) {
00195         return new self ($caption);
00196     }
00197 }
 All Data Structures Files Functions Variables