diff --git a/src/Umbrella/SimpleReport/Api/FieldDefinition.php b/src/Umbrella/SimpleReport/Api/FieldDefinition.php index 3278cc5..94c204d 100755 --- a/src/Umbrella/SimpleReport/Api/FieldDefinition.php +++ b/src/Umbrella/SimpleReport/Api/FieldDefinition.php @@ -36,7 +36,7 @@ class FieldDefinition private $fieldCaption; private $callback; - function __construct($fieldName, $fieldCaption, $fieldType = FieldType::STRING, $callback = null, $fieldSize = null, $fieldWidth = null) + function __construct($fieldName, $fieldCaption, $fieldType = FieldType::STRING, $fieldSize = null, $fieldWidth = null, $callback = null) { $this->fieldName = $fieldName; $this->fieldType = $fieldType; @@ -130,9 +130,10 @@ public function executeCallback($value) { $callback = $this->callback; - if (!is_callable($callback)) { + if (!$callback instanceof \Closure) { throw new \InvalidArgumentException('The callback must be a callable'); } + return $callback($value); } diff --git a/src/Umbrella/SimpleReport/Api/FieldSet.php b/src/Umbrella/SimpleReport/Api/FieldSet.php index 6a0e92a..b5f094b 100755 --- a/src/Umbrella/SimpleReport/Api/FieldSet.php +++ b/src/Umbrella/SimpleReport/Api/FieldSet.php @@ -32,9 +32,9 @@ function __construct() parent::__construct(array()); } - public function addField($fieldName, $fieldCaption, $fieldType, $callback = null, $fieldSize = null, $fieldWidth = null) + public function addField($fieldName, $fieldCaption, $fieldType, $fieldSize = null, $fieldWidth = null, $callback = null) { - $fieldDefinition = new FieldDefinition($fieldName, $fieldCaption, $fieldType, $callback, $fieldSize, $fieldWidth); + $fieldDefinition = new FieldDefinition($fieldName, $fieldCaption, $fieldType, $fieldSize, $fieldWidth, $callback); $fieldDefinition->setFieldOrder($this->count()); parent::append($fieldDefinition); return $this; diff --git a/src/Umbrella/SimpleReport/BaseRenderer.php b/src/Umbrella/SimpleReport/BaseRenderer.php index 40b716b..dace7c9 100755 --- a/src/Umbrella/SimpleReport/BaseRenderer.php +++ b/src/Umbrella/SimpleReport/BaseRenderer.php @@ -63,7 +63,7 @@ protected function getValue(IDatasource $datasource, FieldDefinition $fieldDescr $fieldTypeInstance = $this->configuration->getFieldTypeInstance($fieldTypeName, $rendererPrefix); $unformattedFieldValue = $datasource->getFieldValue($fieldDescription); $formattedFieldValue = $fieldTypeInstance->render($unformattedFieldValue); - if ($fieldDescription->getCallback()) { + if (null !== $fieldDescription->getCallback()) { $formattedFieldValue = $fieldDescription->executeCallBack($formattedFieldValue); } return $formattedFieldValue; diff --git a/src/Umbrella/SimpleReport/Renderer/WkPdfRenderer.php b/src/Umbrella/SimpleReport/Renderer/WkPdfRenderer.php index 247ea08..7e21670 100755 --- a/src/Umbrella/SimpleReport/Renderer/WkPdfRenderer.php +++ b/src/Umbrella/SimpleReport/Renderer/WkPdfRenderer.php @@ -292,10 +292,10 @@ protected function createAndFormatDate($format = 'd/m/Y') } /** - * Converte um HTML em PDF + * Converte um HTML em PDF. Esse método deve ser publico pois quando é feito o streaming ele precisa ser acessível. * @param string $htmlFile O conteúdo HTML para ser convertido */ - protected function createPdf($htmlFile) + public function createPdf($htmlFile) { \wkhtmltox_convert('pdf', array( 'out' => $this->output, diff --git a/test/simpletablereport/SimpleWkPdfTest.php b/test/simpletablereport/SimpleWkPdfTest.php index 40ea206..08f80c6 100755 --- a/test/simpletablereport/SimpleWkPdfTest.php +++ b/test/simpletablereport/SimpleWkPdfTest.php @@ -40,12 +40,12 @@ public function getData() { return array ( - array('id' => 1, 'nome' => 'Kelson'), - array('id' => 2, 'nome' => 'KelsonCM'), - array('id' => 3, 'nome' => ''), - array('id' => 4, 'nome' => null), - array('id' => 5, 'nome' => 'null', 'nome2' => '#error'), - array('id' => 6, 'nome2' => '#error') + array('id' => 1, 'nome' => 'Kelson', 'data' => '2014-03-26'), + array('id' => 2, 'nome' => 'KelsonCM', 'data' => '2014-03-26'), + array('id' => 3, 'nome' => '', 'data' => '2014-03-26'), + array('id' => 4, 'nome' => null, 'data' => '2014-03-26'), + array('id' => 5, 'nome' => 'null', 'nome2' => '#error', 'data' => '2014-03-26'), + array('id' => 6, 'nome2' => '#error', 'data' => '2014-03-26') ); } @@ -55,11 +55,10 @@ public function getFieldset() return $fieldSet ->addField('id', '#', FieldType::INTEGER) ->addField('nome', 'Nome', FieldType::STRING) - ->addField('razao', 'Razao', FieldType::FLOAT) - ->addField('salario', 'Salario', FieldType::DECIMAL) - ->addField('nascimento', 'Nascimento', FieldType::DATE) - ->addField('almoco', 'Almoco', FieldType::TIME) - ->addField('casamento', 'Casamento', FieldType::TIMESTAMP); + ->addField('almoco', 'Almoco', FieldType::TIME, null, null, function($value) { + $date = new DateTime($value); + return $date->format('d-m-Y'); + }); } /** @@ -95,7 +94,7 @@ public function testFooter() $html = new \Umbrella\SimpleReport\Renderer\HtmlRenderer($datasource, $template); $renderer = new WkPdfRenderer($datasource, $template, $html); $renderer->setOutput('/tmp/teste-footer.pdf'); - + $renderer->setUseFooter(true) ->setFooterPathTemplate('/var/www/simpletablereport/test/footer.html') ->setFooterPath('/tmp/teste-footer')