Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
23.08% |
3 / 13 |
CRAP | |
38.18% |
21 / 55 |
| THtml | |
0.00% |
0 / 1 |
|
23.08% |
3 / 13 |
160.07 | |
38.18% |
21 / 55 |
| __construct | |
0.00% |
0 / 1 |
2.00 | |
90.91% |
10 / 11 |
|||
| show | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| setIncludeFile | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| getIncludeFile | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 4 |
|||
| getHtmlValue | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
| parseFile | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
| setValue | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
| getValue | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 6 |
|||
| setGridFile | |
0.00% |
0 / 1 |
3.46 | |
28.57% |
2 / 7 |
|||
| getGridFile | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
| setLoadingMessage | |
100.00% |
1 / 1 |
2 | |
100.00% |
3 / 3 |
|||
| getLoadingMessage | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| setFormFields | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
| 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 | |
| 42 | /** |
| 43 | * Classe criar campos de conteúdo livre ( html ) |
| 44 | */ |
| 45 | class THtml extends TControl |
| 46 | { |
| 47 | private $includeFile; |
| 48 | private $width; |
| 49 | private $height; |
| 50 | private $gridFile; |
| 51 | private $loadingMessage; |
| 52 | public function __construct($strName,$strValue=null,$strIncludeFile=null,$strHeight=null,$strWidth=null,$strGridId=null,$strGridFile=null,$strLoadingMessage=null) |
| 53 | { |
| 54 | if( empty($strName) ){ |
| 55 | throw new DomainException(TMessage::ERROR_FIELD_ID_CANNOT_EMPTY.' '.__CLASS__); |
| 56 | } |
| 57 | parent::__construct('div',$strName,$strValue); |
| 58 | parent::setFieldType('html'); |
| 59 | $this->setClass('fwHtml'); |
| 60 | $this->setWidth($strWidth); |
| 61 | $this->setHeight($strHeight); |
| 62 | $this->setIncludeFile($strIncludeFile); |
| 63 | $this->setGridFile($strGridFile,$strGridId); |
| 64 | $this->setLoadingMessage($strLoadingMessage); |
| 65 | } |
| 66 | //------------------------------------------------------------------------------------- |
| 67 | public function show($print=true) |
| 68 | { |
| 69 | $this->add($this->getHtmlValue()); |
| 70 | return parent::show($print); |
| 71 | } |
| 72 | //------------------------------------------------------------------------------------- |
| 73 | public function setIncludeFile($strFileName=null) |
| 74 | { |
| 75 | $this->includeFile =$strFileName; |
| 76 | } |
| 77 | //------------------------------------------------------------------------------------- |
| 78 | public function getIncludeFile() |
| 79 | { |
| 80 | if( !is_null($this->includeFile) && !file_exists($this->includeFile) ) |
| 81 | { |
| 82 | $this->setValue('Arquivo '.$this->includeFile.' não encontrado'); |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | return $this->includeFile; |
| 87 | } |
| 88 | } |
| 89 | //------------------------------------------------------------------------------------- |
| 90 | public function getHtmlValue() |
| 91 | { |
| 92 | if($this->getIncludeFile() ) |
| 93 | { |
| 94 | return $this->parseFile(); |
| 95 | } |
| 96 | return null; |
| 97 | } |
| 98 | //----------------------------------------------------------------------------- |
| 99 | protected function parseFile() |
| 100 | { |
| 101 | //return implode("", file($this->getIncludeFile(),1)); |
| 102 | ob_start(); |
| 103 | eval("?>" .implode("", file($this->getIncludeFile(),1))."<?" ); |
| 104 | $c = ob_get_contents(); |
| 105 | ob_clean(); |
| 106 | return $c; |
| 107 | } |
| 108 | //------------------------------------------------------------------------------ |
| 109 | public function setValue( $strNewValue = null ) |
| 110 | { |
| 111 | $this->clearChildren(); |
| 112 | $this->add($strNewValue); |
| 113 | parent::setValue(null); |
| 114 | } |
| 115 | //------------------------------------------------------------------------------- |
| 116 | public function getValue() |
| 117 | { |
| 118 | if($this->getIncludeFile() ) |
| 119 | { |
| 120 | return $this->parseFile(); |
| 121 | } |
| 122 | // o campo html não possui um value e sim um array de values ( childrens ) |
| 123 | $value = $this->getChildren(); |
| 124 | if( is_array( $value ) && count( $value ) == 1 ) |
| 125 | { |
| 126 | return $value[0]; |
| 127 | } |
| 128 | return $this->value; |
| 129 | //return $this->getChildren(); |
| 130 | //return implode('',$this->getChildren()); |
| 131 | } |
| 132 | //----------------------------------------------------------------------------------- |
| 133 | /** |
| 134 | * Define o nome de um arquivo que cria um gride utilizando a classe TGrid |
| 135 | * Se for definido este parametro, o TForm criará o javascript para carregamento do gride via ajax |
| 136 | * |
| 137 | * @param mixed $strGridFile |
| 138 | */ |
| 139 | public function setGridFile($strGridFile,$strGridId,$mixFormFields=null) |
| 140 | { |
| 141 | if( !is_null($strGridFile) ) |
| 142 | { |
| 143 | $this->gridFile=null; |
| 144 | $this->gridFile['id'] = $strGridId; |
| 145 | $this->gridFile['file'] = $strGridFile; |
| 146 | $this->setFormFields($mixFormFields); |
| 147 | $this->setIncludeFile(null); |
| 148 | } |
| 149 | } |
| 150 | /** |
| 151 | * Retonra o array com as informações do ID e FILE do arquivo do gride |
| 152 | * se for passado null como parametro. |
| 153 | * Se for passado id, retorna o ID |
| 154 | * Se for passado file, retorna o FILE |
| 155 | */ |
| 156 | public function getGridFile($strKey=null) |
| 157 | { |
| 158 | if( is_null($strKey)) |
| 159 | { |
| 160 | return $this->gridFile; |
| 161 | } |
| 162 | else |
| 163 | { |
| 164 | return $this->gridFile[$strKey]; |
| 165 | } |
| 166 | } |
| 167 | //------------------------------------------------------------------------------------- |
| 168 | public function setLoadingMessage($strNewValue=null) |
| 169 | { |
| 170 | $strNewValue = empty($strNewValue)?'':$strNewValue; |
| 171 | $this->loadingMessage = str_replace("'",'"',$strNewValue); |
| 172 | } |
| 173 | public function getLoadingMessage() |
| 174 | { |
| 175 | return $this->loadingMessage; |
| 176 | } |
| 177 | //--------------------------------------------------------------------- |
| 178 | public function setFormFields($mixFormFields = null) |
| 179 | { |
| 180 | if( is_string($mixFormFields)) |
| 181 | { |
| 182 | $mixFormFields = explode(',',$mixFormFields); |
| 183 | } |
| 184 | $this->gridFile['formFields'] = $mixFormFields; |
| 185 | } |
| 186 | } |
| 187 | ?> |