git.schokokeks.org
Repositories
Help
Report an Issue
fs-draft.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
dcda8f5
Branches
Tags
master
midgard
vorlage
fs-draft.git
source
logic
server
table.php
advanced
bfadmin-master
commited
dcda8f5
at 2016-04-25 00:47:49
table.php
Blame
History
Raw
<?php class class_column { public $title; public $extract_; public $format_; public function __construct($title, $extract_, $format_ = null) { if ($format_ == null) $format_ = function ($x) {return $x;}; $this->title = $title; $this->extract_ = $extract_; $this->format_ = $format_; } public function extract($row) { return call_user_func($this->extract_, $row); // return $this->extract_($row); } public function format($value) { return call_user_func($this->format_, $value); // return $this->format_($value); } } class class_table { private $columns; private $rows; public function __construct($columns, $rows = []) { $this->columns = $columns; $this->rows = []; $this->fill($rows); } private function add($row) { array_push($this->rows, $row); } private function fill($rows) { array_map ( function ($row) {$this->add($row);}, $rows ); } public function generate() { ?> <table class="datatable"> <thead> <tr> <?php array_map ( function ($column) { ?> <th> <?php echo($column->title); ?> </th> <?php }, $this->columns ); ?> </tr> </thead> <tbody> <?php array_map ( function ($row) { ?> <tr> <?php array_map ( function ($column) use (&$row) { ?> <td> <?php echo($column->format($column->extract($row))); ?> </td> <?php }, $this->columns ); ?> </tr> <?php }, $this->rows ); ?> </tbody> </table> <?php } } ?>