Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 44
TTableArray
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 8
380
0.00% covered (danger)
0.00%
0 / 44
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 5
 addRow
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 4
 addColumn
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 setData
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 7
 getData
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 addRowThead
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 10
 addRowTBody
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 11
 show
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
1<?php
2/*
3 * Formdin Framework
4 * Copyright (C) 2012 Ministério do Planejamento
5 * Criado por Luís Eugênio Barbosa
6 * Essa versão é um Fork https://github.com/bjverde/formDin
7 *
8 * ----------------------------------------------------------------------------
9 * This file is part of Formdin Framework.
10 *
11 * Formdin Framework is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License version 3
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License version 3
21 * along with this program; if not,  see <http://www.gnu.org/licenses/>
22 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
23 * Fifth Floor, Boston, MA  02110-1301, USA.
24 * ----------------------------------------------------------------------------
25 * Este arquivo é parte do Framework Formdin.
26 *
27 * O Framework Formdin é um software livre; você pode redistribuí-lo e/ou
28 * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
29 * do Software Livre (FSF).
30 *
31 * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
32 * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
33 * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
34 * para maiores detalhes.
35 *
36 * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
37 * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
38 * ou escreva para a Fundação do Software Livre (FSF) Inc.,
39 * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
40 */
41
42class TTableArray Extends TElement
43{
44    private $keyMap = array();
45    private $data = null;
46    public $thead = null;
47    public $tbody = null;
48
49    /**
50     * Cria uma tabela HTML
51     *
52     * @param string $idTableHtml id da tabela
53     */
54    public function __construct($idTableHtml=null)
55    {
56        parent::__construct('table');
57        $this->setId($idTableHtml);
58        $this->thead = new TTablethead();
59        parent::add($this->thead);
60    }
61    //------------------------------------------------------------------
62    public function addRow($strId=null)
63    {
64        $row = new TTableRow();
65        $row->setId($strId);
66        parent::add($row);
67        return $row;
68    }
69    //------------------------------------------------------------------------------------
70    /**
71     * Coluna normal para o grid
72     * @param string $strFieldName 1: ID da coluna = Nome da coluna da tabela
73     * @param string $strValue     2: Nome do Label que irá aparecer 
74     */
75    public function addColumn( $strFieldName, $strValue = null)
76    {
77        $strValue =  empty($strValue)?$strFieldName:$strValue;
78        $this->keyMap[$strFieldName]=$strValue;
79    }
80    //------------------------------------------------------------------------------------
81    public function setData( $mixValue = null ){
82        if ( !is_array( $mixValue ) ) {
83            ValidateHelper::isArray($mixValue,__METHOD__,__LINE__);
84        }else{
85            $keys = array_keys($mixValue);
86            if ( empty($keys) ) {
87                $mixValue = null;
88            }
89        }
90        $this->data = $mixValue;
91    }    
92    //---------------------------------------------------------------------------------------
93    /**
94     * Retorna o array de dados do gride
95     */
96    public function getData() {
97        return $this->data;
98    }
99    //---------------------------------------------------------------------------------------
100    private function addRowThead() {
101        $listKeysMap = array_keys($this->keyMap);
102        $listKeys = array_keys($this->data);
103        $row = $this->thead->addRow();
104        if( empty($listKeysMap) ){
105            foreach( $listKeys as $keyName ) {                
106                $row->addCell($keyName);
107            }
108        } else {
109            foreach( $listKeys as $keyName ) {                
110                if(in_array($keyName,$listKeysMap)) {
111                    $row->addCell($this->keyMap[$keyName]);
112                }
113            }
114        }//Fim IF
115    }
116    //---------------------------------------------------------------------------------------
117    private function addRowTBody() {
118        $listKeys = array_keys($this->data);
119        $firstKey = $listKeys[0];
120        foreach( $this->data[$firstKey] as $keyNumber => $value ) {
121            $row = $this->addRow();
122            foreach( $listKeys as $keyName ) {
123                $listKeysMap = array_keys($this->keyMap);
124                if( empty($listKeysMap) ){
125                    $row->addCell($this->data[$keyName][$keyNumber]);
126                } else {
127                    if(in_array($keyName,$listKeysMap)) {
128                        $row->addCell($this->data[$keyName][$keyNumber]);
129                    }
130                }
131            }
132        }
133    }
134    //---------------------------------------------------------------------------------------
135    public function show( $boolPrint = true ) {
136        $this->addRowThead();
137        $this->addRowTBody();
138        return parent::show( $boolPrint );
139    }
140}