Пример #1
0
 public function testOutputFromHtml()
 {
     $internal = $this->getMock('Knp\\Snappy\\GeneratorInterface');
     $internal->expects($this->once())->method('getOutputFromHtml')->with($this->equalTo('<html>foo</html>'), $this->equalTo(array('foo' => 'bar')));
     $logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
     $logger->expects($this->once())->method('debug')->with($this->equalTo('Output from HTML (<html>foo</html>).'));
     $generator = new LoggableGenerator($internal, $logger);
     $generator->getOutputFromHtml('<html>foo</html>', array('foo' => 'bar'), true);
 }
    public function testSetOption()
    {
        $internal = $this->getMock('Knp\\Snappy\\Image');
        $internal->expects($this->at(0))->method('setOption')->with($this->equalTo('foo'), $this->equalTo('bar'));
        $internal->expects($this->at(1))->method('setOption')->with($this->equalTo('foo'), $this->equalTo(array('bar' => 'baz')));
        $logger = $this->getMock('Psr\\Log\\LoggerInterface');
        $logger->expects($this->at(0))->method('debug')->with($this->equalTo('Set option foo = \'bar\'.'));
        $logger->expects($this->at(1))->method('debug')->with($this->equalTo('Set option foo = array (
  \'bar\' => \'baz\',
).'));
        $generator = new LoggableGenerator($internal, $logger);
        $generator->setOption('foo', 'bar');
        $generator->setOption('foo', array('bar' => 'baz'));
    }
Пример #3
0
 /**
  * @return string|Response
  */
 public function render()
 {
     $response = new Response();
     switch ($this->getFormat()) {
         case 'csv':
             $response->headers->set('Content-Type', 'text/csv');
             $response->setContent($this->prepareCSV());
             break;
         case 'json':
             $response->headers->set('Content-Type', 'application/json');
             //remove first row from data
             unset($this->data[0]);
             $response->setContent(json_encode($this->data));
             break;
         case 'xls':
             $response->headers->set('Content-Type', 'application/vnd.ms-excel');
             $response->setContent($this->data);
             break;
         case 'html':
             $response->headers->set('Content-Type', 'text/html');
             $response->setContent($this->data);
             break;
         case 'xml':
             $response->headers->set('Content-Type', 'application/xml');
             $response->setContent($this->data);
             break;
         case 'pdf':
             $columns = $this->data[0];
             unset($this->data[0]);
             $response->headers->set('Content-Type', 'application/pdf');
             $response->setContent($this->knpSnappyPdf->getOutputFromHtml($this->templating->render($this->getTemplate(), ['columns' => $columns, 'data' => $this->data, 'template_vars' => $this->getTemplateVars()]), $this->getPdfOptions()));
             break;
         case 'render':
             $columns = $this->data[0];
             unset($this->data[0]);
             $response->headers->set('Content-Type', 'text/plain');
             $response->setContent($this->templating->render($this->getTemplate(), ['columns' => $columns, 'data' => $this->data, 'template_vars' => $this->getTemplateVars()]));
             break;
         case 'listData':
             $columns = $this->data[0];
             unset($this->data[0]);
             return ['columns' => $columns, 'rows' => $this->data];
     }
     if ($this->getInMemory()) {
         return $response->getContent();
     }
     $response->headers->set('Cache-Control', 'public');
     $response->headers->set('Content-Disposition', 'attachment; filename="' . $this->getFileName() . '"');
     return $response;
 }
 /**
  * Genera una factura para la inscripción indicada.
  *
  * @param Registration $registration
  * @param $filename
  *
  * @return string
  */
 public function generateInvoiceDraft(Registration $registration, &$filename)
 {
     $filename = sprintf('factura-%s-%d-%s.pdf', $registration->getConvention()->getSlug(), $registration->getId(), $registration->getUser()->getUniversity()->getSlug());
     $html = $this->twig->render('themes/invoice/invoice_draft.html.twig', array('registration' => $registration, 'fecha' => new \DateTime('today')));
     return $this->loggableGenerator->getOutputFromHtml($html);
 }
Пример #5
0
 /**
  * @param $html
  * @return string
  */
 public function generateFromHtml($html)
 {
     return $this->generator->getOutputFromHtml($html, $this->options);
 }