Библиотека для cis, online, cms1
This commit is contained in:
commit
3c2e614d87
269 changed files with 39854 additions and 0 deletions
94
core/tools/tableview.php
Normal file
94
core/tools/tableview.php
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
class TableExcelView {
|
||||
private $list = array();
|
||||
private $data = array();
|
||||
|
||||
function setColumns(array $list) {
|
||||
$this->list = $list;
|
||||
}
|
||||
|
||||
function makeTable() {
|
||||
$xls = new ExcelTable();
|
||||
$xls->setRow(1, 1, array_keys($this->list));
|
||||
|
||||
foreach($this->data as $n => $item) {
|
||||
$result = array();
|
||||
foreach($this->list as $key => $c) {
|
||||
if (is_callable($c)) {
|
||||
$result [] = call_user_func($c, $item, $n);
|
||||
} else {
|
||||
if (is_numeric($item[$c])) {
|
||||
$result [] = new Excel_Number($item[$c]);
|
||||
} else {
|
||||
$result [] = $item[$c];
|
||||
}
|
||||
}
|
||||
}
|
||||
$xls->addRow(1, $result);
|
||||
}
|
||||
|
||||
return $xls;
|
||||
}
|
||||
|
||||
function writeTable($data, $file) {
|
||||
$this->data = $data;
|
||||
|
||||
$xls = new ExcelDocument();
|
||||
$xls->addTable(array($this, 'makeTable'));
|
||||
$xls->save($file);
|
||||
}
|
||||
}
|
||||
|
||||
class TableHTMLView {
|
||||
private $list = array();
|
||||
private $stack = array();
|
||||
private $result = array();
|
||||
|
||||
function writeElement($name, $content) {
|
||||
echo "<".$name.">";
|
||||
echo $content;
|
||||
echo "</".$name.">";
|
||||
}
|
||||
|
||||
function startElement($name) {
|
||||
array_push($this->stack, $name);
|
||||
echo "<".$name.">";
|
||||
}
|
||||
|
||||
function endElement() {
|
||||
$name = array_pop($this->stack);
|
||||
echo "</".$name.">";
|
||||
}
|
||||
|
||||
function setColumns(array $list) {
|
||||
$this->list = $list;
|
||||
}
|
||||
|
||||
function writeTable($data) {
|
||||
$this->startElement('table');
|
||||
$this->startElement('thead');
|
||||
$this->startElement('tr');
|
||||
foreach($this->list as $key => $c) {
|
||||
$this->writeElement('th', $key);
|
||||
}
|
||||
$this->endElement();
|
||||
$this->endElement();
|
||||
|
||||
$this->startElement('tbody');
|
||||
foreach($data as $n => $item) {
|
||||
$this->startElement('tr');
|
||||
foreach($this->list as $key => $c) {
|
||||
if (is_callable($c)) {
|
||||
$this->writeElement('td', call_user_func($c, $item, $n));
|
||||
} else {
|
||||
$this->writeElement('td', $item[$c]);
|
||||
}
|
||||
}
|
||||
$this->endElement();
|
||||
}
|
||||
$this->endElement();
|
||||
$this->endElement();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue