Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 70 |
| TTreeViewData | |
0.00% |
0 / 1 |
|
0.00% |
0 / 11 |
1260 | |
0.00% |
0 / 70 |
| __construct | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 10 |
|||
| addItem | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
| getId | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| setParent | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| clear | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 6 |
|||
| getIdParent | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 3 |
|||
| getElementById | |
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 11 |
|||
| getTag | |
0.00% |
0 / 1 |
56 | |
0.00% |
0 / 16 |
|||
| generateXml | |
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 9 |
|||
| getXml | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
| show | |
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 | class TTreeViewData |
| 43 | { |
| 44 | //static private $level = 0; |
| 45 | private $xml; |
| 46 | private $parent; |
| 47 | private $id; |
| 48 | private $child; |
| 49 | private $itens; |
| 50 | private $text; |
| 51 | private $hint; |
| 52 | private $userData; |
| 53 | private $open; |
| 54 | private $checked; |
| 55 | /** |
| 56 | * Classe TTreeView |
| 57 | * |
| 58 | * @param mixed $id |
| 59 | * @param mixed $text |
| 60 | * @param mixed $boolOpen |
| 61 | * @param mixed $hint |
| 62 | * @param mixed $arrUserData |
| 63 | * @param mixed $boolSelect |
| 64 | * @param mixed $boolChecked |
| 65 | * @return TTreeViewData |
| 66 | */ |
| 67 | public function __construct( $id, $text, $boolOpen=null, $hint=null, $arrUserData=null, $boolSelect=null, $boolChecked=null ) |
| 68 | { |
| 69 | $this->parent = null; |
| 70 | $this->child = 0; |
| 71 | $this->id = $id; |
| 72 | $this->text = $text; |
| 73 | $this->open = ($boolOpen===true) ? 'yes' :'no'; |
| 74 | $this->hint = $hint; |
| 75 | $this->select = ($boolSelect===true) ? 'yes' :'no'; |
| 76 | $this->userData = $arrUserData; |
| 77 | $this->checked = ( $boolChecked===true) ? 'yes' :'no'; |
| 78 | } |
| 79 | public function addItem( TTreeViewData $item ) |
| 80 | { |
| 81 | $item->setParent($this->getId()); |
| 82 | $item->child=1; |
| 83 | $this->itens[$item->getId()] = $item; |
| 84 | return $item; |
| 85 | } |
| 86 | public function getId() |
| 87 | { |
| 88 | return $this->id; |
| 89 | } |
| 90 | public function setParent($id) |
| 91 | { |
| 92 | $this->parent=$id; |
| 93 | } |
| 94 | public function clear() |
| 95 | { |
| 96 | if($this->itens) |
| 97 | { |
| 98 | forEach($this->itens as $k=>$item) |
| 99 | { |
| 100 | $result = $item->clear(); |
| 101 | unset($this->itens[$k]); |
| 102 | } |
| 103 | unset($this->itens); |
| 104 | } |
| 105 | } |
| 106 | function getIdParent() |
| 107 | { |
| 108 | if( (string) $this->parent != '' && (int) $this->parent != 0 ) |
| 109 | { |
| 110 | return $this->parent; |
| 111 | } |
| 112 | return null; |
| 113 | } |
| 114 | public function getElementById($id) |
| 115 | { |
| 116 | $result=null; |
| 117 | if($id == $this->id) |
| 118 | { |
| 119 | return $this; |
| 120 | } |
| 121 | if($this->itens) |
| 122 | { |
| 123 | forEach($this->itens as $k=>$item) |
| 124 | { |
| 125 | if( $k == $id) |
| 126 | { |
| 127 | $result = $this->itens[$k]; |
| 128 | } |
| 129 | else |
| 130 | { |
| 131 | $result = $item->getElementById($id); |
| 132 | } |
| 133 | if ($result) |
| 134 | break; |
| 135 | } |
| 136 | } |
| 137 | //return $result ? $result : $this; |
| 138 | return $result; |
| 139 | } |
| 140 | //---------------------------------------------------------------------------------------------- |
| 141 | /* |
| 142 | private function getTagOld($ident) |
| 143 | { |
| 144 | $tag = ""; |
| 145 | if(is_null($this->parent) ) |
| 146 | { |
| 147 | $tag .= "<tree id=\"{$this->getId()}\">"; |
| 148 | } |
| 149 | else |
| 150 | { |
| 151 | $tag .="<item id=\"{$this->getId()}\" text=\"{$this->text}\""; |
| 152 | if($this->tooltip) |
| 153 | { |
| 154 | $tag.=" tooltip=\"{$this->hint}\""; |
| 155 | } |
| 156 | if($this->select=="yes") |
| 157 | { |
| 158 | $tag.=" select=\"{$this->select}\""; |
| 159 | } |
| 160 | if($this->open=="yes") |
| 161 | { |
| 162 | $tag.=" open=\"{$this->open}\">"; |
| 163 | } |
| 164 | $tag.=">"; |
| 165 | } |
| 166 | return $ident.$tag."\n"; |
| 167 | } |
| 168 | */ |
| 169 | //---------------------------------------------------------------------------------------------- |
| 170 | private function getTag() |
| 171 | { |
| 172 | $tag = new TElement('tree'); |
| 173 | $tag->setProperty('id',$this->getId()); |
| 174 | $tag->setProperty('text',$this->text); |
| 175 | if(!is_null($this->parent) ) |
| 176 | { |
| 177 | $tag->setTagType('item'); |
| 178 | if($this->child==1) |
| 179 | { |
| 180 | $tag->setProperty('child',"1"); |
| 181 | } |
| 182 | if($this->hint) |
| 183 | { |
| 184 | $tag->setProperty('tooltip',$this->hint); |
| 185 | } |
| 186 | if($this->select=="yes") |
| 187 | { |
| 188 | $tag->setProperty('select',$this->select); |
| 189 | } |
| 190 | if($this->open=="yes") |
| 191 | { |
| 192 | $tag->setProperty('open',$this->open); |
| 193 | } |
| 194 | if($this->checked=="yes") |
| 195 | { |
| 196 | $tag->setProperty("checked",$this->checked); |
| 197 | } |
| 198 | } |
| 199 | return $tag; |
| 200 | } |
| 201 | //--------------------------------------------------------------------------------------- |
| 202 | public function generateXml($fim=true) |
| 203 | { |
| 204 | $xml = $this->getTag(); |
| 205 | |
| 206 | if( is_array( $this->userData ) ) |
| 207 | { |
| 208 | foreach($this->userData as $k=>$v) |
| 209 | { |
| 210 | /* |
| 211 | $userData = new TElement('userdata'); |
| 212 | $userData->setProperty('name',$k); |
| 213 | $userData->add($v,false); |
| 214 | $xml->add($userData); |
| 215 | */ |
| 216 | $xml->add('<userdata name="'.$k.'">'.$v.'</userdata>'); |
| 217 | } |
| 218 | } |
| 219 | if( $this->itens) |
| 220 | { |
| 221 | foreach($this->itens as $k=>$item) |
| 222 | { |
| 223 | $xml->add($item->generateXml(false)); |
| 224 | } |
| 225 | } |
| 226 | $this->xml = $xml; |
| 227 | return $xml; |
| 228 | } |
| 229 | public function getXml() |
| 230 | { |
| 231 | $this->generateXml(); |
| 232 | if( $this->xml) |
| 233 | { |
| 234 | return $this->xml->show(false); |
| 235 | } |
| 236 | } |
| 237 | public function show() |
| 238 | { |
| 239 | $this->generateXml(); |
| 240 | if( $this->xml) |
| 241 | { |
| 242 | $this->xml->show(); |
| 243 | } |
| 244 | } |
| 245 | //---------------------------------------------------------------------------------- |
| 246 | /*public function getXml() |
| 247 | { |
| 248 | self::$level++; |
| 249 | $ident = str_repeat(chr(9),(self::$level-1)); |
| 250 | $xml = $this->getTag($ident); |
| 251 | if( $this->itens) |
| 252 | { |
| 253 | foreach($this->itens as $k=>$item) |
| 254 | { |
| 255 | $xml.=$item->getXml(); |
| 256 | } |
| 257 | } |
| 258 | if($this->userData) |
| 259 | { |
| 260 | foreach($this->userData as $k=>$v) |
| 261 | { |
| 262 | $xml .= $ident.chr(9)."<userdata name=\"{$k}\">{$v}</userdata>\n"; |
| 263 | } |
| 264 | } |
| 265 | if(is_null($this->parent) ) |
| 266 | { |
| 267 | $xml.= $ident."</tree>\n"; |
| 268 | } |
| 269 | else |
| 270 | { |
| 271 | $xml.= $ident."</item>\n"; |
| 272 | } |
| 273 | self::$level--; |
| 274 | return $xml; |
| 275 | } |
| 276 | */ |
| 277 | } |
| 278 | /* |
| 279 | $item = new TTreeViewItem('0','root'); |
| 280 | $item->getElementById(0)->addItem( new TTreeViewItem(1,'Cadastro') ); |
| 281 | $item->getElementById(1)->addItem( new TTreeViewItem(11,'Livros') ); |
| 282 | $item->getElementById(1)->addItem( new TTreeViewItem(12,'Bicicletas') ); |
| 283 | $item->getElementById(1)->addItem( new TTreeViewItem(13,'Móveis') ); |
| 284 | $item->getElementById(11)->addItem( new TTreeViewItem(111,'Usados') ); |
| 285 | $item->getElementById(11)->addItem( new TTreeViewItem(112,'Novos') ); |
| 286 | $item->getElementById(112)->addItem( new TTreeViewItem(1121,'Novo 1',true,"Item novo",true,array("url"=>"http://www.google.com.br")) ); |
| 287 | echo $item->getXml(); |
| 288 | */ |
| 289 | |
| 290 | /* |
| 291 | $subItem = $item->addItem(new TTreeViewItem(1,'Cadastro')); |
| 292 | $subItem->addItem(new TTreeViewItem(11,'Usuários')); |
| 293 | $subItem->addItem(new TTreeViewItem(12,'Computador')); |
| 294 | $subItem->addItem(new TTreeViewItem(13,'Livros')); |
| 295 | $item14 = $subItem->addItem(new TTreeViewItem(14,'Canetas')); |
| 296 | $item14->addItem(new TTreeViewItem(141,'Usados',false,'Livros Usados',false,array('url'=>'http://www.google.com.br'))); |
| 297 | print_r($item->getElementById(141)); |
| 298 | */ |
| 299 | //$item->Show(); |
| 300 | |
| 301 | ?> |