Ejemplo n.º 1
0
 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());
 }
Ejemplo n.º 2
0
 /**
  * {@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;
     }
 }
Ejemplo n.º 3
0
 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());
 }
Ejemplo n.º 4
0
 /**
  * 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());
 }
Ejemplo n.º 5
0
 /**
  * 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);
 }