-
Notifications
You must be signed in to change notification settings - Fork 0
/
Table.php
52 lines (34 loc) · 1.22 KB
/
Table.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace Onimla\HTML;
#require_once 'Element.class.php';
class Table extends Element {
public function __construct($children = FALSE, $attr = FALSE) {
parent::__construct('table', $attr, $children);
}
public static function fromArray($array, $headings = FALSE) {
$table = FALSE;
if (count($array) > 0) {
$table = new Table();
$thead = new Element('thead');
$tbody = new Element('tbody');
$tr = new Element('tr');
foreach (array_keys(current($array)) as $key) {
$th = new Element('th');
$th->text((is_array($headings) AND key_exists($key, $headings)) ? $attr[$key] : $key);
$tr->append($th);
}
$thead->append($tr);
$table->append($thead, $tbody);
foreach ($array as $row) {
$tr = new Element('tr');
foreach ($row as $cel) {
$td = new Element('td');
$td->text($cel);
$tr->append($td);
}
$tbody->append($tr);
}
}
return $table;
}
}