Source of file HtmlReportFormatter.php
Size: 1,908 Bytes - Last Modified: 2021-12-23T10:25:16+00:00
/var/www/docs.ssmods.com/process/src/code/formatters/HtmlReportFormatter.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 | <?php /** * * @author marcus@silverstripe.com.au * @license http://silverstripe.org/bsd-license/ */ class HtmlReportFormatter extends ReportFormatter { /** * @return string */ protected function getOutputFormat() { return 'html'; } /** * Create a header for the report * * @return string */ protected function createHeader($tableName) { $header = array(); // just join it all up $header[] = '<thead><tr>'; foreach ($this->headers as $field => $display) { $header[] = '<th class="reportHeader '.$field.'">'.$display.'</th>'; } $header[] = '</tr></thead>'; return implode("\n", $header); } /** * Create a body for the report * * @return string */ protected function createBody($tableName, $tableData) { $body = array(); $body[] = '<tbody>'; $formatting = $this->getFieldFormatters(); $rowNum = 1; foreach ($tableData as $row) { $oddEven = $rowNum % 2 == 0 ? 'even' : 'odd'; $body[] = '<tr class="reportrow '.$oddEven.'">'; foreach ($row as $field => $value) { $extraclass = ''; if ($value == '') { $extraclass = 'noReportData'; } if (isset($formatting[$field])) { $value = $formatting[$field]->format($value); } $body[] = '<td class="reportcell '.$field.' '.$extraclass.'">'.$value.'</td>'; } $body[] = '</tr>'; $rowNum++; } $body[] = '</tbody>'; return implode("\n", $body); } /** * Format the header and body into a complete report output. * * @return string */ protected function formatReport($reportPieces) { $bits = ''; foreach ($reportPieces as $tableName => $table) { if ($tableName != ReportFormatter::DEFAULT_TABLE_NAME) { $bits .= '<h2 class="reportTableName">'.$tableName."</h2>\n"; } $bits .= '<table class="reporttable" cellpadding="0" cellspacing="0">'. $table['Header'].$table['Body'].'</table>'."\n\n"; } return $bits; } } |