'Admin Data Table', 'summary' => 'Generates XHTML markup for data tables used by ProcessWire admin', 'version' => 102, 'permanent' => true, ); } public function init() { parent::init(); $this->modules->get("JqueryTableSorter"); } public function headerRow(array $a) { $this->headerRow = $a; return $this; } public function footerRow(array $a) { $this->footerRow = $this->setupRow($a); return $this; } public function row(array $a) { $this->rows[] = $this->setupRow($a); return $this; } protected function setupRow(array $a) { $row = array(); foreach($a as $k => $v) { if(is_string($k)) { // Associative arrays get converted to: // Anchor Text => URL $v = "" . $this->encode($k) . ""; } else { $v = $this->encode($v); } $row[] = $v; } return $row; } public function action(array $action) { foreach($action as $label => $url) { $this->actions[$label] = $url; } return $this; } public function ___render() { $tableClass = trim("AdminDataTable AdminDataList {$this->class}"); if($this->sortable) $tableClass .= " AdminDataTableSortable"; $out = ''; $maxCols = 0; if(count($this->rows)) { $out = "\n"; if($this->caption) $out .= "\n\t"; if(count($this->headerRow)) { $out .= "\n\t\n\t"; foreach($this->headerRow as $th) { $th = $this->encode($th); $out .= "\n\t\t"; $maxCols++; } $out .= "\n\t\n\t"; } if(count($this->footerRow)) { $out .= "\n\t\n\t"; foreach($this->footerRow as $td) { $out .= "\n\t\t\t"; } $out .= "\n\t\n\t"; } $out .= "\n\t"; foreach($this->rows as $row) { $cols = count($row); if($cols > $maxCols) $maxCols = $cols; if($cols < $maxCols) for(; $cols < $maxCols; $cols++) $row[] = ' '; $out .= "\n\t\t"; foreach($row as $td) { $out .= "\n\t\t\t"; } $out .= "\n\t\t"; } $out .= "\n\t"; $out .= "\n
{$this->caption}
$th
$td
$td
"; } if(count($this->actions)) { $out .= "\n

"; foreach($this->actions as $label => $url) { $button = $this->modules->get("InputfieldButton"); $button->href = $url; $button->value = $label; $out .= $button->render(); } $out .= "\n

"; } return $out; } protected function encode($str) { if(!$this->encodeEntities) return $str; return htmlspecialchars($str, ENT_QUOTES); } public function setEncodeEntities($encodeEntities = true) { $this->encodeEntities = $encodeEntities ? true : false; } public function setClass($class) { $this->class = $this->encode($class); } public function setSortable($sortable) { $this->sortable = $sortable ? true : false; } public function setCaption($caption) { $this->caption = $this->encode($caption); } /** the following are specific to the Module interface **/ public function isSingular() { return false; } public function isAutoload() { return false; } }