MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
tablecontrols.class
Ir para a documentação deste ficheiro.
1<?php
2
3#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4# Table
5# Class for html tables
6# - Rows, Cols and Content are 0-based
7#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8
9class MTable extends MControl
10{
11 var $table;
14
15 function __construct($table, $tableAttr, $rowAttr, $cellAttr)
16 {
17 parent::__construct();
18 $this->table = $table;
19 $this->SetAttributes($tableAttr);
20 $this->rowAttr = $rowAttr;
21 $this->cellAttr = $cellAttr;
22 }
23}
24
25class MSimpleTable extends MTable
26{
27 var $cell;
29
30 function __construct($name='', $attrs='', $row=1, $cell=1)
31 {
32 mcontrol::__construct($name);
33
34 if ($attrs == '')
35 {
36 $attrs = "cellspacing=0 cellpadding=0 border=0 width=100%";
37 }
38 else
39 {
40 $attrs = str_replace("\"", '', $attrs);
41 }
42
43 $this->setAttributes($attrs);
44 $this->setClass( $this->attrs->items['class'] );
45
46 for($i=0; $i < $row; $i++)
47 {
48 $this->attributes['row'][$i] = '';
49
50 for($j=0; $j < $cell; $j++)
51 {
52 $this->attributes['cell'][$i][$j] = '';
53 }
54 }
55 }
56
57 function setRowAttribute($i, $name, $attr)
58 {
59 $this->attributes['row'][$i] .= " $name=\"$attr\" ";
60 }
61
62 function setCellAttribute($i, $j, $name, $attr)
63 {
64 $this->attributes['cell'][$i][$j] .= " $name=\"$attr\" ";
65 }
66
67 function setRowClass($i,$class)
68 {
69 $this->attributes['row'][$i] .= " class=\"$class\" ";
70 }
71
72 function setCellClass($i,$j,$class)
73 {
74 $this->attributes['cell'][$i][$j] .= " class=\"$class\" ";
75 }
76
77 function setCell($i,$j,$content,$attrs='')
78 {
79 $this->cell[$i][$j] = $content;
80 $this->attributes['cell'][$i][$j] .= $attrs;
81 }
82
83 function generate()
84 {
85 $n = count($this->cell);
86
87 for($i=0; $i<$n; $i++)
88 {
89 $k = count($this->cell[$i]);
90
91 for($j=0; $j<$k; $j++)
92 {
93 $table[$i][$j] = $this->painter->generateToString($this->cell[$i][$j]);
94 }
95 }
96 //$t = new MTable($table, $this->Attributes(),$this->attributes['row'],$this->attributes['cell']);
97 $this->table = $table;
98 //$this->SetAttributes( $tableAttr );
99 $this->rowAttr = $this->attributes['row']; //$rowAttr;
100 $this->cellAttr = $this->attributes['cell']; //$cellAttr;
101
102 return $this->getRender('table');
103 }
104
105}
106
108{
112 var $zebra = false;
114 var $setBorder = false;
116
117 function __construct($title='', $array, $colTitle=null)
118 {
119 parent::__construct('');
120 $this->title = $title;
121 $this->array = &$array;
122 $this->colTitle = $colTitle;
123
124 // JS's referente ao cabeçalho fixo conforme rolagem
126 $this->page->addScript("../themes/{$MIOLO->getTheme()->getName()}/scripts/fixed_table_header.js");
127 }
128
129 function SetAlternate($zebra=false)
130 {
131 $this->zebra = $zebra;
132 }
133
134 function Generate()
135 {
139
140 $tbodyId = 'tbody' . $this->id;
141 $bodyId = 'body' . $this->id;
142
143 $t = new SimpleTable($tbodyId);
144
145 if ( $this->fixedColumnHeader )
146 {
147 $this->page->onLoad(
148 "if (typeof $('#{$tbodyId}').stickyTableHeaders == 'function' ) $('#{$tbodyId}').stickyTableHeaders();".
149 "$('#{$bodyId}').on('scroll', function(){\$('#{$tbodyId}').stickyTableHeaders();});"
150 );
151
152 if ( !$this->title )
153 {
154 $t->attributes['row'][0] = "class=\"m-grid-row-heading\"";
155 }
156 else
157 {
158 $t->attributes['row'][1] = "class=\"m-grid-row-heading\"";
159 }
160 }
161
162 $t->SetClass("m-tableraw");
163 $t->SetAttributes('cellspacing=1 cellpadding=3 class="table"');
164 if ( $this->setBorder )
165 {
166 $t->SetAttributes('border=1');
167 }
168 $k = 0;
169 if ($title)
170 {
171 $ncols = count($colTitle);
172 $t->SetCell($k++,0,$title," class=\"m-tableraw-title\" colspan=$ncols ");
173 }
174 if (is_array($colTitle))
175 {
176 $n = count($colTitle);
177 for($i=0;$i<$n;$i++)
178 $t->SetCell($k,$i,$colTitle[$i]," class=\"m-tableraw-column-title\" ");
179 $k++;
180 }
181 if (is_array($array))
182 {
183 $nrows = count($array);
184 for($i=0; $i<$nrows; $i++)
185 {
186 $rowClass = "m-tableraw-row" . ($this->zebra ? '-'.($i%2) : '');
187 $t->SetRowClass($k, $rowClass);
188 if (is_array($array[$i]))
189 {
190 $ncols = count($array[$i]);
191 for($j=0; $j<$ncols; $j++)
192 {
193 $attr = $this->attributes['cell'][$i][$j];
194 if ($attr == '') $attr = "width=0 align=\"left\" valign=\"top\"";
195 $t->SetCell($k,$j,$array[$i][$j],$attr);
196
197 }
198 }
199 else
200 {
201 $attr = $this->attributes['cell'][$i][0];
202 if ($attr == '') $attr = "width=0 align=\"left\" valign=\"top\"";
203 $t->SetCell($k,0,$array[$i], $attr);
204 }
205 $k++;
206 }
207 }
208
209 if ( strpos(MIOLO::getInstance()->getTheme()->id, "sbootstrap") !== false )
210 {
211 $divTable = new MDiv('divTable' . $this->id, $t, 'm-grid-body');
212 $divTable->addBoxStyle('overflow', 'auto');
213
214 //barra de rolagem flutuante
215 $this->page->onload("$('.m-grid-body').floatingScroll();");
216 $this->page->onload("$('.fl-scrolls').css('margin-bottom', '2.6%');");
217
218 return $divTable->generate();
219 }
220
221 return $t->Generate();
222 }
223
224}
225
226class MTableXml extends MTableRaw
227{
228 function __construct($title='', $file, $colTitle=null)
229 {
230 $xmlTree = new XMLTree($file);
231 $array = $xmlTree->getXMLTreeAsArray();
232 parent::__construct($title, $array, $colTitle);
233 }
234}
235
236class TableCell extends MControl
237{
242
243 function __construct()
244 {
245 parent::__construct();
246 $this->attributes = array();
247 $this->content = array();
248 $this->contentCount = 0;
249 $this->cssclass = 'ThemeTableCell';
250 $this->separator = '<br/>';
251 }
252
253 function SetAttributes($attr)
254 {
255 foreach($attr as $a=>$v) $this->attributes[$a] = $v;
256 }
257
258 function SetAttribute($attr,$value)
259 {
260 $this->attributes[$attr] = $value;
261 }
262
264 {
265 $this->content = array($content);
266 $this->contentCount = 1;
267 }
268
269 function GetContent($pos=0)
270 {
271 if ($pos < $this->contentCount) {
272 return $this->content[$pos];
273 }
274 return null;
275 }
276
277 function ClearContent()
278 {
279 $this->content = array();
280 $this->contentCount = 0;
281 }
282
284 {
285 $this->content[] = $content;
286 $this->contentCount++;
287 }
288}
289
290class TableRow extends MControl
291{
292 var $cell; // array of Cell object
295
296 function __construct()
297 {
298 parent::__construct();
299 $this->cell = array();
300 $this->attributes = array (
301 'align'=>'',
302 'valign'=>''
303 );
304 $this->cssclass = 'ThemeTableRow';
305 $this->cellCount = 0;
306 }
307
308 function SetAttributes($attr)
309 {
310 foreach($attr as $a=>$v) $this->attributes[$a] = $v;
311 }
312
313 function SetAttribute($attr,$value)
314 {
315 $this->attributes[$attr] = $value;
316 }
317
318 function AddCell()
319 {
320 $this->cell[$c = $this->cellCount++] = new TableCell();
321 return $c;
322 }
323
325 {
326 if (($this->cellCount > 0) && ($this->cellCount > $cell))
327 {
328 array_splice($this->cell,$cell, 1);
329 $this->cellCount--;
330 }
331 }
332
333 function GetCell($cell)
334 {
335 if ($this->ncells > $cell)
336 {
337 return $this->cell[$cell];
338 }
339 return null;
340 }
341}
342
343?>
setAttributes($attr)
Definição mcontrol.class:462
attributes( $mergeDuplicates=false)
Definição mcontrol.class:486
setClass( $cssClass, $add=true)
Definição mcontrol.class:398
getRender( $method)
Definição mcontrol.class:833
static getInstance()
Definição miolo.class:134
setCell($i, $j, $content, $attrs='')
setRowClass($i, $class)
setCellAttribute($i, $j, $name, $attr)
setRowAttribute($i, $name, $attr)
__construct($name='', $attrs='', $row=1, $cell=1)
setCellClass($i, $j, $class)
SetAlternate($zebra=false)
__construct($title='', $array, $colTitle=null)
__construct($title='', $file, $colTitle=null)
__construct($table, $tableAttr, $rowAttr, $cellAttr)
SetAttribute($attr, $value)
SetContent($content)
SetAttributes($attr)
AddContent($content)
GetContent($pos=0)
SetAttribute($attr, $value)
SetAttributes($attr)
GetCell($cell)
RemoveCell($cell)