From cd60c2b8c151b6d675722bfad6e2a73090f5e554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dtalo=20Lelis=20de=20Vietro?= Date: Wed, 21 Jan 2015 12:20:22 -0300 Subject: [PATCH] Adding twig support for templating --- composer.json | 61 +++++++------ sample.excel.zip | Bin 6558 -> 0 bytes src/BaseRenderer.php | 23 +++-- src/ConfigurationLoader.php | 8 +- src/Parser/TemplateParser.php | 86 ------------------ src/Renderer/GroupHtmlRenderer.php | 74 --------------- src/Renderer/GroupedHtmlRenderer.php | 38 ++++---- src/Renderer/HtmlRenderer.php | 18 +--- config.ini => src/Resources/config/config.ini | 3 - src/SimpleReport.php | 76 ++++++++++++++++ 10 files changed, 150 insertions(+), 237 deletions(-) delete mode 100644 sample.excel.zip delete mode 100644 src/Parser/TemplateParser.php delete mode 100644 src/Renderer/GroupHtmlRenderer.php rename config.ini => src/Resources/config/config.ini (95%) create mode 100644 src/SimpleReport.php diff --git a/composer.json b/composer.json index 5d54546..bf6dd99 100644 --- a/composer.json +++ b/composer.json @@ -1,35 +1,36 @@ { - "name": "umbrella/simpletablereport", - "description": "PHP Simple Table Report. Export data as tables to PDF, CSV, Excel, etc...", - "license": "MIT", - "authors": [ - { - "name": "kelsoncm", - "email": "kelsoncm@gmail.com" - }, - { - "name": "Ítalo Lelis", - "email": "italolelis@gmail.com" - }, - { - "name": "Ayrton Ricardo", - "email": "ayrton_jampa15@hotmail.com" - } - ], - "require": { - "easyframework/collections": "~3.1" + "name": "umbrella/simpletablereport", + "description": "PHP Simple Table Report. Export data as tables to PDF, CSV, Excel, etc...", + "license": "MIT", + "authors": [ + { + "name": "kelsoncm", + "email": "kelsoncm@gmail.com" }, - "require-dev": { - "phpunit/phpunit": "~4.2" + { + "name": "Ítalo Lelis", + "email": "italolelis@gmail.com" }, - "autoload": { - "psr-4": { - "Umbrella\\SimpleReport\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "Umbrella\\Tests\\SimpleReport\\": "tests/" - } + { + "name": "Ayrton Ricardo", + "email": "ayrton_jampa15@hotmail.com" + } + ], + "require": { + "twig/twig": "~1.17", + "easyframework/collections": "~3.1" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "autoload": { + "psr-4": { + "Umbrella\\SimpleReport\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Umbrella\\Tests\\SimpleReport\\": "tests/" } + } } diff --git a/sample.excel.zip b/sample.excel.zip deleted file mode 100644 index da4e51e1bf57d0ecd3f88222958ad3c863998a75..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6558 zcmeHM^;=YH*B%&<8ejyJuAz|z0|cd|JEU{y9A;=F1qmeu6cj-^q!a<^?(UeOQBXos zhj_>H9p7V|_xlIVd4AaYnrrQQ&GoE(-_MGzp$x>K09*jz0{{SK!2FfyyRKLO02mhl zAP3-M8_Br3z@aX1GaVl{sD}xkx3d#d77jM&3jj9e`G40xI0D5wy)G>R;5z+{+p-OM zk(m*Nh4^$|Z&WGdFq$tBN4h!nzSB5HyY$KMX36678MGsxQI~p&Qk)a3!PyGjM^;MQiMBnJylACukB@``{^h!2vr%D6@YnO3XO zrnEY;0ZfMX#<@fLnhOuTJB7l;dxo}7)XPfH3lm|6GD3R6NZnSUm7XqF$~EovwQ2h} z7H$)R30ymU9-1x5@LNG6cd<0ADyS;u$364VIDsni)H3Hi(ldK<3ncVyN5n$+_*1|Z zV)*eB7j}B`=7T&1^|^!2vYQ5~YlBcz^kNFCH9(>8UcWQ1Gst_cd(UUx-592uu?8CN zKa-o?7!wBL6k52BShY6TS|4SodoNtGLs1fc#eW;KJ-vem0Gyu#0UAH)^o_0n%K?Ub zDi|3OVRUK+gF1Qe^L@MitIvP1D1X>`Ov0dAs{p8DTcJ*71-;>-fS;N3PDSAzvkpTO z>lWjihc8(rj}F6tAxc)W!-wmGw~dfnYxX*fbe8;Tt+kv|<-(SJlMdb`8G58IEFre` z6rD7W=q&W-kxpjb*-2@Zlj!`4=xCbSq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6S z{ulc_T~dv35Y>3)_soQ*J^%~i9B6yHa>IQd=Kz#nvlg8@kk9#QUeJNRth6t$BI(|V zwa2;#mr-UXUn+u?DPNiKIuvxw@y~rgCEv_UQ~6}76MXMkp}D#wo3UT&qZf<|S!#Z> zb+9xKJ^1RTU})uLYR<)hnG(L?x&+=ik!)$aJsmAlr=qcWDzAImD&1yrT&p5y8Bel~ z$g3mn62Wo&tNAWdeNg(~ZJhr=hEj=TgA_-FG}lYAstL+p7oHuW?6}v+g!eVj$Rjy| z%khR;%m*r z6N`zd=5|j!GAapaB7D2JCeuc{qv|Ionots7rYtYKoV(?8;pyD@{it^DvMF8Odgj3+ zWCiorcFR786pQVAc{!()as2?QJJC=+5F+Q>THP~ z`;rxG;1o8%_T}V7(F%FG{shGX8yq(Cu*W@4MEiB7xxz`uO%GQdU)6ZQ;w{2oS_;z? zwxAamGYTal^e0p75Z0u$qm=F!IJCrjislhhp}0O_&#*M??B3sg6NSxiQK+2;J4M`W z4lr8FkwvZ*#b6LvU5Kj?oQX}$?yVvm)mV>}e%MIzx~Hi?_r^r|DA!gTuN=qWR;Yfx zdn3vg?M}kuPx%M*yx2r0|r=m<#U5`mhbkjpz;3`o` zHEB^b`XRQD--*@M2rbHS6A>GtVrf1xe)9_da{Ih*WY5LS#H695zKO7k;js9$x9mN! zUveeAGS!36)YFB;7{G%;LYF&6;? zGD>W#Jp&l+)og}%HNlk8^Y79*uNwP{ih<+@rE`JVK*0xGu2#oJBWIvN{bu6 z97jK|H8BJ(i`HyrPFKa1CzlO=g_<+4y{5a67;$-tVRLW5$ijPl{e$rA>U`FTMi2Rb zjl5Yy$tm#rp^1gf3;18N_wTRh`~7bw@fylMJNS7h_#OD|o{#yg{ diff --git a/src/BaseRenderer.php b/src/BaseRenderer.php index 44e8acb..1f35384 100644 --- a/src/BaseRenderer.php +++ b/src/BaseRenderer.php @@ -17,10 +17,11 @@ */ namespace Umbrella\SimpleReport; +use Easy\Collections\Dictionary; use Umbrella\SimpleReport\Api\FieldDefinition; use Umbrella\SimpleReport\Api\DatasourceInterface; +use Umbrella\SimpleReport\Api\FieldSet; use Umbrella\SimpleReport\Api\RendererInterface; -use Umbrella\SimpleReport\Api\TemplateInterface; /** * Description of BaseRenderer @@ -33,19 +34,29 @@ abstract class BaseRenderer implements RendererInterface protected $configuration; /** - * @var DatasourceInterface + * @var DatasourceInterface */ protected $datasource; /** - * @var TemplateInterface + * @var FieldSet */ - protected $template; + protected $fieldset; - public function __construct(DatasourceInterface $datasource, TemplateInterface $template) + /** + * @var Dictionary + */ + protected $options; + + public function __construct(DatasourceInterface $datasource, FieldSet $fieldset, Dictionary $options = null) { $this->datasource = $datasource; - $this->template = $template; + $this->fieldset = $fieldset; + $this->options = new Dictionary(); + if ($options) { + $this->options->concat($options); + } + $configurationLoader = ConfigurationLoader::getInstance(); $this->configuration = $configurationLoader->getConfiguration(); } diff --git a/src/ConfigurationLoader.php b/src/ConfigurationLoader.php index 91ea9e3..6a2efae 100644 --- a/src/ConfigurationLoader.php +++ b/src/ConfigurationLoader.php @@ -30,7 +30,7 @@ class ConfigurationLoader private $configuration; /** - * + * * @return ConfigurationLoader */ public static function getInstance() @@ -43,7 +43,7 @@ public static function getInstance() } /** - * + * * @return ConfigurationInterface */ public function getConfiguration() @@ -53,12 +53,12 @@ public function getConfiguration() public function getRootDir() { - return filter_input(INPUT_SERVER, 'DOCUMENT_ROOT') ? : getcwd(); + return filter_input(INPUT_SERVER, 'DOCUMENT_ROOT') ?: getcwd(); } protected function load() { - $configFile = __DIR__ . "/../config.ini"; + $configFile = __DIR__ . "/Resources/config/config.ini"; $ini_array = parse_ini_file($configFile); $configurationClassName = $ini_array['simpletablereport.configurationClassName']; $this->configuration = new $configurationClassName($ini_array); diff --git a/src/Parser/TemplateParser.php b/src/Parser/TemplateParser.php deleted file mode 100644 index 66150c4..0000000 --- a/src/Parser/TemplateParser.php +++ /dev/null @@ -1,86 +0,0 @@ - - * @author Valter - */ -class TemplateParser -{ - protected $tags = array(); - protected $template = null; - - public function __construct(TemplateInterface $template) - { - $this->template = $template; - } - - public function setTemplate(TemplateInterface $template) - { - $this->template = $template; - return $this; - } - - public function getTemplate() - { - return $this->template; - } - - public function getTags() - { - return $this->tags; - } - - public function setTags($values) - { - foreach ($values as $key => $value) { - $this->addTag($key, $value); - } - return $this; - } - - public function addTag($key, $value) - { - $this->tags[$key] = $value; - return $this; - } - - public function removeTag($key) - { - if (!isset($key)) { - return null; - } - unset($this->tags[$key]); - } - - protected function findTemplate() - { - $file = $this->template->getPath(); - if (!file_exists($file)) { - throw new Exception('Arquivo de template não encontrado'); - } - return file_get_contents($file); - } - - public function parse() - { - $html = $this->findTemplate(); - - foreach ($this->tags as $tag => $value) { - $html = str_replace("{{" . $tag . "}}", $value, $html); - } - - return $html; - } -} diff --git a/src/Renderer/GroupHtmlRenderer.php b/src/Renderer/GroupHtmlRenderer.php deleted file mode 100644 index 2fdd344..0000000 --- a/src/Renderer/GroupHtmlRenderer.php +++ /dev/null @@ -1,74 +0,0 @@ -. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -namespace Umbrella\SimpleReport\Renderer; - -/** - * @author Ítalo Lelis de Vietro - */ -class GroupHtmlRenderer extends HtmlRenderer -{ - - protected function renderTableBodyRows() - { - for ($this->datasource->rewind(); $this->datasource->valid(); $this->datasource->next()) { - $this->doWriteTableBodyRowStart(); - $this->renderTableBodyFields(); - $this->doWriteTableBodyRowEnd(); - } - } - - protected function renderTableBodyFields() - { - foreach ($this->template->getFields() as $fieldDescription) { - $this->doWriteTableBodyDataStart(); - - echo $this->getValue($this->datasource, $fieldDescription, ''); - - $this->doWriteTableBodyDataEnd(); - } - } - - protected function renderTableBodyGroupedFields() - { - foreach ($this->template->getFields() as $fieldDescription) { - $this->doWriteTableBodyDataStart(); - echo $this->getValue($this->datasource, $fieldDescription, ''); - $this->doWriteTableBodyDataEnd(); - } - } - - protected function doWriteTableBodyRowStart() - { - echo $this->getOption('table.body.row.start'); - } - - protected function doWriteTableBodyDataStart() - { - echo $this->getOption('table.body.data.start'); - } - - protected function doWriteTableBodyDataEnd() - { - echo $this->getOption('table.body.data.end'); - } - - protected function doWriteTableBodyRowEnd() - { - echo $this->getOption('table.body.row.end'); - } -} diff --git a/src/Renderer/GroupedHtmlRenderer.php b/src/Renderer/GroupedHtmlRenderer.php index 378d468..631fc18 100644 --- a/src/Renderer/GroupedHtmlRenderer.php +++ b/src/Renderer/GroupedHtmlRenderer.php @@ -20,7 +20,6 @@ /** * Description of HTMLRenderer * - * @author kelsoncm */ class GroupedHtmlRenderer extends HtmlRenderer { @@ -34,7 +33,7 @@ class GroupedHtmlRenderer extends HtmlRenderer protected function renderTableHeader() { - $depth = $this->template->getParam('grouped'); + $depth = $this->options->get('grouped'); $show = null; if (is_array($depth)) { $show = isset($depth['showHeader']) ? $depth['showHeader'] : false; @@ -43,19 +42,20 @@ protected function renderTableHeader() $this->doWriteTableHeaderStart(); $this->doWriteTableHeaderRowStart(); - $fields = $this->template->getFields(); + $fields = $this->fieldset; $count = count($fields); for ($i = 0; $i < $count; $i++) { $this->doWriteTableHeaderDataStart(); if (($i == 0) || ($i > $depth) || ($show)) { - echo $fields[$i]->getFieldCaption(); + $this->write($fields[$i]->getFieldCaption()); } $this->doWriteTableHeaderDataEnd(); } $this->doWriteTableHeaderRowEnd(); $this->doWriteTableHeaderEnd(); } + /* * Mudança: Deve incluir um head na primeira coluna para cada inicio de grupo */ @@ -63,9 +63,8 @@ protected function renderTableHeader() protected function renderTableBodyRows() { $this->setSumGroupedValue(); - $fields = $this->template->getFields(); - - $depth = $this->template->getParam('grouped'); + $fields = $this->fieldset; + $depth = $this->options->get('grouped'); if (is_array($depth)) { $depth = isset($depth['depth']) ? $depth['depth'] : null; @@ -96,47 +95,48 @@ public function renderGroupHeadRow() protected function renderGroupHeadFields() { - $depth = $this->template->getParam('grouped'); + $depth = $this->options->get('grouped'); if (is_array($depth)) { $depth = isset($depth['depth']) ? $depth['depth'] : null; } - $fields = $this->template->getFields(); + $fields = $this->fieldset; $value = $this->getValue($this->datasource, $fields[$depth - 1], ''); $count = count($fields); for ($i = 0; $i < $count - 1; $i++) { $this->doWriteTableBodyDataStart(); if ($i == $depth - 1) { - echo $value; + $this->write($value); } $this->doWriteTableBodyDataEnd(); } //Coluna Somatoria $this->doWriteTableBodyDataStart(); - echo $this->groupedSums[$value]; + $this->write($this->groupedSums[$value]); $this->doWriteTableBodyDataEnd(); } + /* * Mudança: só deve iterar os valores a partir da coluna que não servir de head */ protected function renderTableBodyFields() { - $depth = $this->template->getParam('grouped'); + $depth = $this->options->get('grouped'); if (is_array($depth)) { $depth = isset($depth['depth']) ? $depth['depth'] : null; } - $fields = $this->template->getFields(); + $fields = $this->fieldset; $count = count($fields); for ($i = 0; $i < $count; $i++) { $this->doWriteTableBodyDataStart(); if ($i >= $depth) { - echo $this->getValue($this->datasource, $fields[$i], ''); + $this->write($this->getValue($this->datasource, $fields[$i], '')); } $this->doWriteTableBodyDataEnd(); } @@ -147,7 +147,7 @@ protected function renderTableFooter() $this->doWriteTableFooterStart(); $this->doWriteTableFooterRowStart(); $columnCountEnabled = $this->datasource->getEnabledColumnCount(); - $countColumn = ($columnCountEnabled) ? $this->datasource->getColumnFieldCounts() : $this->template->getFields(); + $countColumn = ($columnCountEnabled) ? $this->datasource->getColumnFieldCounts() : $this->fieldset; $columnPrint = ''; $count = count($countColumn); @@ -158,7 +158,7 @@ protected function renderTableFooter() } else { $columnPrint = ' '; } - echo $columnPrint; + $this->write($columnPrint); $this->doWriteTableFooterDataEnd(); } $this->doWriteTableFooterRowEnd(); @@ -167,7 +167,7 @@ protected function renderTableFooter() protected function setSumGroupedValue() { - $fields = $this->template->getFields(); + $fields = $this->fieldset; $value = null; for ($this->datasource->rewind(); $this->datasource->valid(); $this->datasource->next()) { $value = $this->getValue($this->datasource, $fields[0], ''); @@ -180,11 +180,11 @@ protected function setSumGroupedValue() protected function doWriteTableBodyGroupedDataStart() { - echo $this->getOption('table.body.grouped.data.start'); + $this->write($this->getOption('table.body.grouped.data.start')); } protected function doWriteTableBodyGroupedRowStart() { - echo $this->getOption('table.body.grouped.row.start'); + $this->write($this->getOption('table.body.grouped.row.start')); } } diff --git a/src/Renderer/HtmlRenderer.php b/src/Renderer/HtmlRenderer.php index 48e12f5..6a3a524 100644 --- a/src/Renderer/HtmlRenderer.php +++ b/src/Renderer/HtmlRenderer.php @@ -31,9 +31,7 @@ protected function write($string) public function render() { $this->stringBuffer = ''; - $this->doWriteDocumentStart(); $this->renderTable(); - $this->doWriteDocumentEnd(); } protected function renderTable() @@ -48,7 +46,7 @@ protected function renderTableHeader() { $this->doWriteTableHeaderStart(); $this->doWriteTableHeaderRowStart(); - foreach ($this->template->getFields() as $value) { + foreach ($this->fieldset as $value) { $this->doWriteTableHeaderDataStart(); $this->write($value->getFieldCaption()); $this->doWriteTableHeaderDataEnd(); @@ -75,7 +73,7 @@ protected function renderTableBodyRows() protected function renderTableBodyFields() { - foreach ($this->template->getFields() as $fieldDescription) { + foreach ($this->fieldset as $fieldDescription) { $this->doWriteTableBodyDataStart(); $this->write($this->getValue($this->datasource, $fieldDescription)); $this->doWriteTableBodyDataEnd(); @@ -86,8 +84,7 @@ protected function renderTableFooter() { $this->doWriteTableFooterStart(); $this->doWriteTableFooterRowStart(); - $countColumn = $this->template->getFields(); - $count = count($countColumn); + $count = count(fieldset); for ($i = 0; $i < $count; $i++) { $this->doWriteTableFooterDataStart(); @@ -98,11 +95,6 @@ protected function renderTableFooter() $this->doWriteTableFooterEnd(); } - protected function doWriteDocumentStart() - { - $this->write($this->getOption('documentbody.start')); - } - protected function doWriteTableStart() { $this->write($this->getOption('table.start')); @@ -203,8 +195,4 @@ protected function doWriteTableEnd() $this->write($this->getOption('table.end')); } - protected function doWriteDocumentEnd() - { - $this->write($this->getOption('documentbody.end')); - } } diff --git a/config.ini b/src/Resources/config/config.ini similarity index 95% rename from config.ini rename to src/Resources/config/config.ini index 93c6382..e08a534 100644 --- a/config.ini +++ b/src/Resources/config/config.ini @@ -26,9 +26,6 @@ simpletablereport.timestamptype.toformat = d/m/Y H:i:s simpletablereport.xlsxrenderer.sample = sample.excel.zip -simpletablereport.htmlrenderer.documentbody.start = '' -simpletablereport.htmlrenderer.documentbody.end = '' - simpletablereport.htmlrenderer.table.start = '' simpletablereport.htmlrenderer.table.end = '
' diff --git a/src/SimpleReport.php b/src/SimpleReport.php new file mode 100644 index 0000000..d665a72 --- /dev/null +++ b/src/SimpleReport.php @@ -0,0 +1,76 @@ +tableRenderer = $tableRenderer; + $loader = new Twig_Loader_Filesystem($options->get('paths')->toArray()); + $this->renderer = $twig = new Twig_Environment($loader, $options->toArray()); + } + + /** + * @return Twig_Environment + */ + public function getRenderer() + { + return $this->renderer; + } + + /** + * @param Twig_Environment $renderer + */ + public function setRenderer($renderer) + { + $this->renderer = $renderer; + } + + + public function addGlobal($name, $value) + { + $this->renderer->addGlobal($name, $value); + return $this; + } + + public function addGlobals($vars) + { + foreach ($vars as $name => $value) { + $this->addGlobal($name, $value); + } + return $this; + } + + public function render($view, array $context = array()) + { + $this->tableRenderer->render(); + $table = $this->tableRenderer->getStringBuffer(); + + return $this->renderer->render($view, array_merge(array( + 'table' => $table + ), $context)); + } + +} \ No newline at end of file