renderTable($this->table); } protected function renderTable($table) { if($table instanceof Piwik_DataTable_Array) { $columnPrefixToAdd = $table->getNameKey(); $out = ""; foreach($table->getArray() as $date => $subtable ) { $out .= ""; } $out .= "

$columnPrefixToAdd = $date

"; $out .= $this->renderDataTable($subtable); $out .= "
"; } else { $out = $this->renderDataTable($table); } return $out; } protected function renderDataTable($table) { if($table->getRowsCount() == 0) { return "Empty table
\n"; } if($table instanceof Piwik_DataTable_Simple && $table->getRowsCount() ==1) { $table->deleteColumn('label'); } static $depth=0; $i = 1; $someDetails = false; $someIdSubTable = false; $tableStructure = array(); /* * table = array * ROW1 = col1 | col2 | col3 | details | idSubTable * ROW2 = col1 | col2 (no value but appears) | col3 | details | idSubTable * subtable here */ $allColumns = array(); // echo $table; foreach($table->getRows() as $row) { foreach($row->getColumns() as $column => $value) { $allColumns[$column] = true; $tableStructure[$i][$column] = $value; } $details=array(); foreach($row->getDetails() as $detail => $value) { if(is_string($value)) $value = "'$value'"; $details[] = "'$detail' => $value"; } if(count($details) != 0) { $someDetails = true; $details = implode("
", $details); $tableStructure[$i]['_details'] = $details; } $idSubtable = $row->getIdSubDataTable(); if(!is_null($idSubtable)) { $someIdSubTable = true; $tableStructure[$i]['_idSubtable'] = $idSubtable; } if($row->getIdSubDataTable() !== null) { $depth++; try{ $tableStructure[$i]['_subtable']['html'] = $this->renderTable( Piwik_DataTable_Manager::getInstance()->getTable($row->getIdSubDataTable())); } catch(Exception $e) { $tableStructure[$i]['_subtable']['html'] = "-- Sub DataTable not loaded"; } $tableStructure[$i]['_subtable']['depth'] = $depth; $depth--; } $i++; } /* // to keep the same columns order as the columns labelled with strings ksort($allColumns); //replace the label first if(isset($allColumns['label'])) { $allColumns = array_merge(array('label'=>true),$allColumns); } */ $allColumns['_details'] = $someDetails; $allColumns['_idSubtable'] = $someIdSubTable; $html = "\n"; $html .= ""; $html .= "\n"; foreach($allColumns as $name => $toDisplay) { if($toDisplay !== false) { $html .= "\n\t"; } } $colspan = count($allColumns); foreach($tableStructure as $row) { $html .= "\n\n"; foreach($allColumns as $name => $toDisplay) { if($toDisplay !== false) { $value = "-"; if(isset($row[$name])) { $value = $row[$name]; } $html .= "\n\t"; } } $html .= ""; if(isset($row['_subtable'])) { // echo ".".$row['_subtable'];exit; $html .= ""; } } $html .= "\n\n
$name
$value
{$row['_subtable']['html']}
"; // display styles if there is a subtable displayed if($someIdSubTable) { $styles="\n\n\n\n"; if($depth == 0) { $html = $styles . $html; } } return $html; } }