public function testRemoveColumn() { $statsTable = new StatsTable(array(array('a' => 'a', 'b' => 'b'), array('a' => 'A', 'b' => 'B')), array('a' => 'Alpha', 'b' => 'Bravo')); $statsTable->removeColumn('b'); $this->assertEquals(array('a' => 'Alpha'), $statsTable->getHeaders()); $this->assertEquals(array(array('a' => 'a'), array('a' => 'A')), $statsTable->getData()); }
/** * Dump Data * @param StatsTable $statsTable * @return string */ public function dump(StatsTable $statsTable) { $result = array('data' => $statsTable->getData()); if ($this->enableHeaders) { $result['headers'] = $statsTable->getHeaders(); } if ($this->enableAggregation) { $result['aggregations'] = $statsTable->getAggregations(); $result['aggregationsFormats'] = $statsTable->getAggregationsFormats(); } $result['formats'] = $statsTable->getDataFormats(); // Format value for each line of dataset foreach ($result['data'] as &$line) { foreach ($line as $id => &$val) { if (array_key_exists($id, $result['formats'])) { $val = $this->formatValue($result['formats'][$id], $val); } } } // Format value for each value of aggregations foreach ($result['aggregations'] as $id => &$val) { if (array_key_exists($id, $result['aggregationsFormats'])) { $val = $this->formatValue($result['aggregationsFormats'][$id], $val); } } return json_encode($result); }
public function dump(StatsTable $statsTable) { $data = $statsTable->getData(); $format = $statsTable->getDataFormats(); $aggregations = $statsTable->getAggregations(); $aggregationsFormats = $statsTable->getAggregationsFormats(); $metaData = $statsTable->getMetaData(); $data = $this->formatData($data, $format); $aggregations = $this->formatLine($aggregations, $aggregationsFormats); $params = array('headers' => $statsTable->getHeaders(), 'data' => $data, 'aggregations' => $aggregations, 'metaData' => $metaData); $params = array_merge($params, $this->templateOptions); return $this->twig->render($this->template, $params); }
public function dump(StatsTable $statsTable) { $fileHandler = fopen('php://temp', 'w'); if ($this->enableHeaders) { $this->writeLine($fileHandler, $statsTable->getHeaders()); } foreach ($statsTable->getData() as $line) { $this->writeLine($fileHandler, $line, $statsTable->getDataFormats()); } if ($this->enableAggregation) { $this->writeLine($fileHandler, $statsTable->getAggregations(), $statsTable->getAggregationsFormats()); } $len = ftell($fileHandler); fseek($fileHandler, 0, SEEK_SET); return fread($fileHandler, $len); }
/** * Dumps the stats table * @param StatsTable $statsTable * @return string */ public function dump(StatsTable $statsTable) { $excel = new \PHPExcel(); $excel->getDefaultStyle()->applyFromArray($this->getDefaultStyleArray()); $sheet = $excel->getSheet(); $row = 1; $data = $statsTable->getData(); $width = count(reset($data)); // HEADERS // if ($this->enableHeaders) { $headerStyle = new \PHPExcel_Style(); $headerStyle->applyFromArray($this->getHeadersStyleArray()); $col = 0; foreach ($statsTable->getHeaders() as $header) { $sheet->setCellValueByColumnAndRow($col, $row, $header); $col++; } $sheet->duplicateStyle($headerStyle, 'A1:' . \PHPExcel_Cell::stringFromColumnIndex($width - 1) . '1'); $row++; } // DATA // foreach ($statsTable->getData() as $data) { $this->applyValues($sheet, $row, $data, $statsTable->getDataFormats()); $row++; } // AGGREGATIONS // if ($this->enableAggregation) { $this->applyValues($sheet, $row, $statsTable->getAggregations(), $statsTable->getAggregationsFormats(), $this->getAggregationsStyleArray()); } // FINAL FORMATTING // for ($col = 0; $col < $width; $col++) { $sheet->getColumnDimension(\PHPExcel_Cell::stringFromColumnIndex($col))->setAutoSize(true); } $xlsDumper = new \PHPExcel_Writer_Excel2007($excel); $pFilename = @tempnam(\PHPExcel_Shared_File::sys_get_temp_dir(), 'phpxltmp'); $xlsDumper->save($pFilename); $contents = file_get_contents($pFilename); @unlink($pFilename); unset($excel); unset($xlsDumper); return $contents; }