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