public function buildView(TableView $view, TableInterface $table) { $data = array(); foreach ($table->getData()->getRows() as $_data) { $row = $this->resolveParams($table->getOption('rows_params'), $_data, true); $data['row_' . implode('_', $row)] = $row; } $view->setData($data); }
public function export(TableView $view, $template = null, array $options = array()) { $out = tempnam('/tmp', 'export-out-'); $data = $view->getData(); file_put_contents($out, $this->twig->render($template ?: $this->template, array('table' => $data))); $now = new \DateTime(); $filename = preg_replace(array('/\\[now\\]/', '/\\[caption\\]/'), array($now->format('Y-m-d H\\hi'), $data['caption']), 'Export'); return new Export(new \SplFileInfo($out), $this->getContentType(), $filename, $this->getFileExtension()); }
public function testExport() { $view = new TableView(); $view->setData(array('caption' => 'test')); $export = $this->extension->export($view); $this->assertInstanceOf('EMC\\TableBundle\\Table\\Export\\ExportInterface', $export); $this->assertEquals($this->extension->getContentType(), $export->getContentType()); $this->assertEquals($this->extension->getFileExtension(), $export->getFileExtension()); $this->assertEquals('application/pdf', mime_content_type($export->getFile()->getPathname())); }
public function testExport() { $view = new TableView(); $view->setData(array('caption' => 'abc', 'thead' => array(array('title' => 'a'), array('title' => 'b')), 'tbody' => array(array('data' => array(array('value' => 1), array('value' => '2'))), array('data' => array(array('value' => 7.5), array('value' => 'test')))))); $export = $this->extension->export($view); $this->assertInstanceOf('EMC\\TableBundle\\Table\\Export\\ExportInterface', $export); $this->assertEquals($this->extension->getContentType(), $export->getContentType()); $this->assertEquals($this->extension->getFileExtension(), $export->getFileExtension()); $this->assertEquals("a;b\n1;2\n7.5;test\n", file_get_contents($export->getFile()->getPathname())); }
/** * {@inheritdoc} */ public function export(TableView $view, $template = null, array $options = array()) { $input = $this->tempnam('html'); $output = $this->tempnam('pdf'); try { $data = $view->getData(); $this->buildHtml($input, $view, $template, $options); $this->buildPdf($input, $output, $data); $filename = $this->formatName($this->options['filename'], new \DateTime(), $data['caption']); $export = new Export(new \SplFileInfo($output), $this->getContentType(), $filename, $this->getFileExtension()); unlink($input); return $export; } catch (\Exception $exception) { unlink($input); throw $exception; } }
public function export(TableView $view, $template = null, array $options = array()) { $out = tempnam('/tmp', 'export-out-'); $data = $view->getData(); $file = new \SplFileObject($out, 'w'); $file->setCsvControl($this->delimiter, $this->enclosure, $this->escape); $row = array(); foreach ($data['thead'] as $th) { $row[] = $th['title']; } $file->fputcsv($row); foreach ($data['tbody'] as $tr) { $row = array(); foreach ($tr['data'] as $td) { $row[] = $td['value']; } $file->fputcsv($row); } $now = new \DateTime(); $filename = preg_replace(array('/\\[now\\]/', '/\\[caption\\]/'), array($now->format('Y-m-d H\\hi'), $data['caption']), 'Export'); return new Export($file->getFileInfo(), $this->getContentType(), $filename, $this->getFileExtension()); }
/** * Render block $block with $table view's data. * @param \Twig_Environment $twig * @param \EMC\TableBundle\Table\TableView $view * @param string $block * @return string */ public function render(\Twig_Environment $twig, TableView $view, $block) { $this->load(); return $this->template->renderBlock($block, $view->getData()); }
/** * Render block $block with $table view's data. * @param \Twig_Environment $twig * @param \EMC\TableBundle\Table\TableView $view * @return string */ public function render(\Twig_Environment $twig, TableView $view, $template = null) { $context = array_merge($twig->getGlobals(), $view->getData()); return $twig->loadTemplate($template ?: $this->template)->renderBlock('table', $context); }