From b6937ab421b883aa31a88f68c7da1390c8bdb8c5 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 11 Jul 2014 16:06:15 +0200 Subject: [PATCH] =?UTF-8?q?Finish=20export=20forms=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20core/lib/Thelia/Config/Resources/config?= =?UTF-8?q?.xml=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thel?= =?UTF-8?q?ia/Config/Resources/form.xml=20=09modifi=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Controller/Admin/ExportController.p?= =?UTF-8?q?hp=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia?= =?UTF-8?q?/Controller/Admin/ImportExportController.php=20=09modifi=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Core/Template/Loop/F?= =?UTF-8?q?ormatter.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/?= =?UTF-8?q?lib/Thelia/Core/Template/Loop/ImportExportType.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Form/ExportFo?= =?UTF-8?q?rm.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Th?= =?UTF-8?q?elia/ImportExport/Both/NewsletterImportExport.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/ImportExport/?= =?UTF-8?q?Export/MailingExport.php=20=09renomm=C3=A9:=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20core/lib/Thelia/ImportExport/ExportHandlerInterface.ph?= =?UTF-8?q?p=20->=20core/lib/Thelia/ImportExport/ExportHandler.php=20=09mo?= =?UTF-8?q?difi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Model/Exp?= =?UTF-8?q?ort.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/T?= =?UTF-8?q?helia/Model/Import.php=20=09nouveau=20fichier:=20core/lib/Theli?= =?UTF-8?q?a/Tests/ImportExport/Export/MailingExportTest.php=20=09nouveau?= =?UTF-8?q?=20fichier:=20templates/backOffice/default/ajax/export-modal.ht?= =?UTF-8?q?ml=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20templates/backO?= =?UTF-8?q?ffice/default/export-page.html=20=09modifi=C3=A9:=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20templates/backOffice/default/export.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Config/Resources/config.xml | 2 +- core/lib/Thelia/Config/Resources/form.xml | 2 +- .../Controller/Admin/ExportController.php | 4 +- .../Admin/ImportExportController.php | 71 ++++++++- .../Thelia/Core/Template/Loop/Formatter.php | 1 + .../Core/Template/Loop/ImportExportType.php | 12 +- core/lib/Thelia/Form/ExportForm.php | 5 + .../Both/NewsletterImportExport.php | 4 +- .../ImportExport/Export/MailingExport.php | 65 ++++++-- ...HandlerInterface.php => ExportHandler.php} | 16 +- core/lib/Thelia/Model/Export.php | 8 +- core/lib/Thelia/Model/Import.php | 6 +- .../ImportExport/Export/MailingExportTest.php | 52 +++++++ .../backOffice/default/ajax/export-modal.html | 93 +++++++++++ templates/backOffice/default/export-page.html | 147 +++++++++--------- templates/backOffice/default/export.html | 92 +++++++++-- 16 files changed, 453 insertions(+), 127 deletions(-) rename core/lib/Thelia/ImportExport/{ExportHandlerInterface.php => ExportHandler.php} (83%) create mode 100644 core/lib/Thelia/Tests/ImportExport/Export/MailingExportTest.php create mode 100644 templates/backOffice/default/ajax/export-modal.html diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 9b9d7df13..25c59abd2 100644 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -146,7 +146,7 @@ - + diff --git a/core/lib/Thelia/Config/Resources/form.xml b/core/lib/Thelia/Config/Resources/form.xml index 9dbb59253..ebb1a03e8 100644 --- a/core/lib/Thelia/Config/Resources/form.xml +++ b/core/lib/Thelia/Config/Resources/form.xml @@ -133,7 +133,7 @@
- + diff --git a/core/lib/Thelia/Controller/Admin/ExportController.php b/core/lib/Thelia/Controller/Admin/ExportController.php index 8f20d61a7..a1ea06c2e 100644 --- a/core/lib/Thelia/Controller/Admin/ExportController.php +++ b/core/lib/Thelia/Controller/Admin/ExportController.php @@ -108,11 +108,11 @@ class ExportController extends BaseAdminController protected function setOrders($category = null, $export = null) { if ($category === null) { - $category = $this->getRequest()->query->get("category_order"); + $category = $this->getRequest()->query->get("category_order", "manual"); } if ($export === null) { - $export = $this->getRequest()->query->get("export_order"); + $export = $this->getRequest()->query->get("export_order", "manual"); } $this->getParserContext() diff --git a/core/lib/Thelia/Controller/Admin/ImportExportController.php b/core/lib/Thelia/Controller/Admin/ImportExportController.php index 6b3f8e269..de39423b3 100644 --- a/core/lib/Thelia/Controller/Admin/ImportExportController.php +++ b/core/lib/Thelia/Controller/Admin/ImportExportController.php @@ -11,7 +11,9 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; -use Thelia\Core\HttpFoundation\Response; +use Thelia\Core\Template\Element\LoopResult; +use Thelia\Core\Template\Loop\Export as ExportLoop; +use Thelia\Core\Template\Loop\Import as ImportLoop; use Thelia\Model\ExportQuery; /** @@ -37,7 +39,37 @@ class ImportExportController extends BaseAdminController return $this->render("404"); } - return $this->render("import-page"); + /** + * Use the loop to inject the same vars in Smarty + */ + $loop = new ImportLoop($this->container); + + $loop->initializeArgs([ + "export" => $export->getId() + ]); + + $query = $loop->buildModelCriteria(); + $result= $query->find(); + + $results = $loop->parseResults( + new LoopResult($result) + ); + + $parserContext = $this->getParserContext(); + + /** @var \Thelia\Core\Template\Element\LoopResultRow $row */ + foreach ($results as $row) { + foreach ($row->getVarVal() as $name=>$value) { + $parserContext->set($name, $value); + } + } + + /** Then render the form */ + if ($this->getRequest()->isXmlHttpRequest()) { + return $this->render("ajax/import-modal"); + } else { + return $this->render("import-page"); + } } public function exportView($id) @@ -46,12 +78,37 @@ class ImportExportController extends BaseAdminController return $this->render("404"); } - $this->getParserContext() - ->set("ID", $export->getId()) - ->set("TITLE", $export->getTitle()) - ; + /** + * Use the loop to inject the same vars in Smarty + */ + $loop = new ExportLoop($this->container); - return $this->render("export-page"); + $loop->initializeArgs([ + "export" => $export->getId() + ]); + + $query = $loop->buildModelCriteria(); + $result= $query->find(); + + $results = $loop->parseResults( + new LoopResult($result) + ); + + $parserContext = $this->getParserContext(); + + /** @var \Thelia\Core\Template\Element\LoopResultRow $row */ + foreach ($results as $row) { + foreach ($row->getVarVal() as $name=>$value) { + $parserContext->set($name, $value); + } + } + + /** Then render the form */ + if ($this->getRequest()->isXmlHttpRequest()) { + return $this->render("ajax/export-modal"); + } else { + return $this->render("export-page"); + } } protected function getExport($id) diff --git a/core/lib/Thelia/Core/Template/Loop/Formatter.php b/core/lib/Thelia/Core/Template/Loop/Formatter.php index 71a81ad1e..4fd127154 100644 --- a/core/lib/Thelia/Core/Template/Loop/Formatter.php +++ b/core/lib/Thelia/Core/Template/Loop/Formatter.php @@ -42,6 +42,7 @@ class Formatter extends BaseLoop implements ArraySearchLoopInterface $exportId = $this->getExport(); $formatters = []; + if ($exportId !== null) { $export = ExportQuery::create()->findPk($exportId); diff --git a/core/lib/Thelia/Core/Template/Loop/ImportExportType.php b/core/lib/Thelia/Core/Template/Loop/ImportExportType.php index 13ecf422d..1dee9a74c 100644 --- a/core/lib/Thelia/Core/Template/Loop/ImportExportType.php +++ b/core/lib/Thelia/Core/Template/Loop/ImportExportType.php @@ -12,6 +12,8 @@ namespace Thelia\Core\Template\Loop; use Propel\Runtime\ActiveQuery\Criteria; +use Propel\Runtime\ActiveQuery\ModelCriteria; +use Thelia\Core\Template\Element\BaseI18nLoop; use Thelia\Core\Template\Element\BaseLoop; use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResultRow; @@ -27,7 +29,7 @@ use Thelia\Type\TypeCollection; * @package Thelia\Core\Template\Loop * @author Benjamin Perche */ -abstract class ImportExportType extends BaseLoop implements PropelSearchLoopInterface +abstract class ImportExportType extends BaseI18nLoop implements PropelSearchLoopInterface { const DEFAULT_ORDER = "manual"; @@ -49,8 +51,8 @@ abstract class ImportExportType extends BaseLoop implements PropelSearchLoopInte $loopResultRow ->set("ID", $type->getId()) - ->set("TITLE", $type->getTitle()) - ->set("DESCRIPTION", $type->getDescription()) + ->set("TITLE", $type->getVirtualColumn("i18n_TITLE")) + ->set("DESCRIPTION", $type->getVirtualColumn("i18n_DESCRIPTION")) ->set("URL", $url) ->set("POSITION", $type->getPosition()) ->set("CATEGORY_ID", $type->getByName($this->getCategoryName())) @@ -69,8 +71,12 @@ abstract class ImportExportType extends BaseLoop implements PropelSearchLoopInte */ public function buildModelCriteria() { + /** @var ModelCriteria $query */ $query = $this->getQueryModel(); + $this->configureI18nProcessing($query, array('TITLE', 'DESCRIPTION')); + + if (null !== $ids = $this->getId()) { $query->filterById($ids); } diff --git a/core/lib/Thelia/Form/ExportForm.php b/core/lib/Thelia/Form/ExportForm.php index 33fb8e029..c791d357e 100644 --- a/core/lib/Thelia/Form/ExportForm.php +++ b/core/lib/Thelia/Form/ExportForm.php @@ -47,6 +47,11 @@ class ExportForm extends BaseForm "multiple" => false, "choices" => $this->formattersNames, )) + ->add("do_compress", "checkbox", array( + "label" => $this->translator->trans("Do compress"), + "label_attr" => ["for" => "do_compress"], + "required" => false, + )) ->add("archive_builder", "choice", array( "label" => $this->translator->trans("Archive Format"), "label_attr" => ["for" => "archive_builder"], diff --git a/core/lib/Thelia/ImportExport/Both/NewsletterImportExport.php b/core/lib/Thelia/ImportExport/Both/NewsletterImportExport.php index ffa220e38..4f093077f 100644 --- a/core/lib/Thelia/ImportExport/Both/NewsletterImportExport.php +++ b/core/lib/Thelia/ImportExport/Both/NewsletterImportExport.php @@ -13,7 +13,7 @@ namespace Thelia\ImportExport\Both; use Symfony\Component\DependencyInjection\ContainerInterface; use Thelia\Core\FileFormat\Formatting\FormatterData; -use Thelia\ImportExport\ExportHandlerInterface; +use Thelia\ImportExport\ExportHandler; use Thelia\ImportExport\ImportHandlerInterface; /** @@ -21,7 +21,7 @@ use Thelia\ImportExport\ImportHandlerInterface; * @package Thelia\ImportExport\Both * @author Benjamin Perche */ -class NewsletterImportExport implements ExportHandlerInterface, ImportHandlerInterface +class NewsletterImportExport implements ExportHandler, ImportHandlerInterface { protected $container; diff --git a/core/lib/Thelia/ImportExport/Export/MailingExport.php b/core/lib/Thelia/ImportExport/Export/MailingExport.php index 8e572e1a8..982e45f56 100644 --- a/core/lib/Thelia/ImportExport/Export/MailingExport.php +++ b/core/lib/Thelia/ImportExport/Export/MailingExport.php @@ -13,27 +13,20 @@ namespace Thelia\ImportExport\Export; use Symfony\Component\DependencyInjection\ContainerInterface; use Thelia\Core\FileFormat\Formatting\FormatterData; -use Thelia\ImportExport\ExportHandlerInterface; +use Thelia\Core\Translation\Translator; +use Thelia\ImportExport\ExportHandler; +use Thelia\Model\CustomerQuery; +use Thelia\Model\Map\CustomerTableMap; +use Thelia\Model\Map\NewsletterTableMap; +use Thelia\Model\NewsletterQuery; /** * Class MailingExport * @package Thelia\ImportExport\Export * @author Benjamin Perche */ -class MailingExport implements ExportHandlerInterface +class MailingExport extends ExportHandler { - protected $container; - - /** - * @param ContainerInterface $container - * - * Dependency injection: load the container to be able to get parameters and services - */ - public function __construct(ContainerInterface $container) - { - $this->container = $container; - } - /** * @return \Thelia\Core\FileFormat\Formatting\FormatterData * @@ -41,7 +34,49 @@ class MailingExport implements ExportHandlerInterface */ public function buildFormatterData() { - $data = new FormatterData(); + $translator = Translator::getInstance(); + + $email = $translator->trans("email"); + $lastName = $translator->trans("last name"); + $firstName = $translator->trans("first name"); + + + $aliases = [ + NewsletterTableMap::EMAIL => $email, + CustomerTableMap::EMAIL => $email, + + NewsletterTableMap::LASTNAME => $lastName, + CustomerTableMap::LASTNAME => $lastName, + + NewsletterTableMap::FIRSTNAME => $firstName, + CustomerTableMap::FIRSTNAME => $firstName, + ]; + + $data = new FormatterData($aliases); + + $newsletter = NewsletterQuery::create() + ->select([ + NewsletterTableMap::EMAIL, + NewsletterTableMap::LASTNAME, + NewsletterTableMap::FIRSTNAME, + ]) + ->find() + ->toArray() + ; + + $customers = CustomerQuery::create() + ->select([ + CustomerTableMap::EMAIL, + CustomerTableMap::LASTNAME, + CustomerTableMap::FIRSTNAME, + ]) + ->find() + ->toArray() + ; + + $both = $newsletter + $customers; + + return $data->setData($both); } /** diff --git a/core/lib/Thelia/ImportExport/ExportHandlerInterface.php b/core/lib/Thelia/ImportExport/ExportHandler.php similarity index 83% rename from core/lib/Thelia/ImportExport/ExportHandlerInterface.php rename to core/lib/Thelia/ImportExport/ExportHandler.php index 64348ff3b..ec67ad096 100644 --- a/core/lib/Thelia/ImportExport/ExportHandlerInterface.php +++ b/core/lib/Thelia/ImportExport/ExportHandler.php @@ -14,25 +14,29 @@ namespace Thelia\ImportExport; use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Interface ExportHandlerInterface + * Interface ExportHandler * @package Thelia\ImportExport * @author Benjamin Perche */ -interface ExportHandlerInterface +abstract class ExportHandler { + protected $container; + /** * @param ContainerInterface $container * * Dependency injection: load the container to be able to get parameters and services */ - public function __construct(ContainerInterface $container); + public function __construct(ContainerInterface $container) { + $this->container = $container; + } /** * @return \Thelia\Core\FileFormat\Formatting\FormatterData * - * The method builds + * The method builds the FormatterData for the formatter */ - public function buildFormatterData(); + abstract public function buildFormatterData(); /** * @return string|array @@ -49,5 +53,5 @@ interface ExportHandlerInterface * ExportType::EXPORT_UNBOUNDED, * ); */ - public function getHandledType(); + abstract public function getHandledType(); } \ No newline at end of file diff --git a/core/lib/Thelia/Model/Export.php b/core/lib/Thelia/Model/Export.php index 7df3107c5..f71dad85d 100644 --- a/core/lib/Thelia/Model/Export.php +++ b/core/lib/Thelia/Model/Export.php @@ -5,7 +5,7 @@ namespace Thelia\Model; use Propel\Runtime\ActiveQuery\Criteria; use Symfony\Component\DependencyInjection\ContainerInterface; use Thelia\Core\Translation\Translator; -use Thelia\ImportExport\ExportHandlerInterface; +use Thelia\ImportExport\ExportHandler; use Thelia\Model\Base\Export as BaseExport; use Thelia\Model\Map\ExportTableMap; @@ -77,7 +77,7 @@ class Export extends BaseExport /** * @param ContainerInterface $container - * @return ExportHandlerInterface + * @return ExportHandler * @throws \ErrorException */ public function getHandleClassInstance(ContainerInterface $container) @@ -101,13 +101,13 @@ class Export extends BaseExport $instance = new $class($container); - if (!$instance instanceof ExportHandlerInterface) { + if (!$instance instanceof ExportHandler) { throw new \ErrorException( Translator::getInstance()->trans( "The class \"%class\" must implement %interface", [ "%class" => $class, - "%interface" => "\\Thelia\\ImportExport\\ExportHandlerInterface", + "%interface" => "\\Thelia\\ImportExport\\ExportHandler", ] ) ); diff --git a/core/lib/Thelia/Model/Import.php b/core/lib/Thelia/Model/Import.php index b54829fb0..cf05188ad 100644 --- a/core/lib/Thelia/Model/Import.php +++ b/core/lib/Thelia/Model/Import.php @@ -4,7 +4,7 @@ namespace Thelia\Model; use Propel\Runtime\ActiveQuery\Criteria; use Symfony\Component\DependencyInjection\ContainerInterface; -use Thelia\ImportExport\ExportHandlerInterface; +use Thelia\ImportExport\ExportHandler; use Thelia\Model\Base\Import as BaseImport; use Thelia\Model\Map\ImportTableMap; @@ -89,12 +89,12 @@ class Import extends BaseImport $instance = new $class($container); - if (!$class instanceof ExportHandlerInterface) { + if (!$class instanceof ExportHandler) { throw new \ErrorException( "The class \"%class\" must implement %interface", [ "%class" => $class, - "%interface" => "\\Thelia\\ImportExport\\ExportHandlerInterface", + "%interface" => "\\Thelia\\ImportExport\\ExportHandler", ] ); } diff --git a/core/lib/Thelia/Tests/ImportExport/Export/MailingExportTest.php b/core/lib/Thelia/Tests/ImportExport/Export/MailingExportTest.php new file mode 100644 index 000000000..fd45426c5 --- /dev/null +++ b/core/lib/Thelia/Tests/ImportExport/Export/MailingExportTest.php @@ -0,0 +1,52 @@ + + */ +class MailingExportTest extends \PHPUnit_Framework_TestCase +{ + /** @var MailingExport $handler */ + protected $handler; + + public function setUp() + { + $container = new Container(); + + new Translator($container); + + $this->handler = new MailingExport($container); + } + + public function testExport() + { + $data = $this->handler->buildFormatterData(); + + + } + + public function testType() + { + $this->assertEquals( + [ExportType::EXPORT_TABLE, ExportType::EXPORT_UNBOUNDED], + $this->handler->getHandledType() + ); + } +} \ No newline at end of file diff --git a/templates/backOffice/default/ajax/export-modal.html b/templates/backOffice/default/ajax/export-modal.html new file mode 100644 index 000000000..b32a08bd4 --- /dev/null +++ b/templates/backOffice/default/ajax/export-modal.html @@ -0,0 +1,93 @@ +{form name="thelia.export"} + + + +{/form} \ No newline at end of file diff --git a/templates/backOffice/default/export-page.html b/templates/backOffice/default/export-page.html index d5fd65e21..0d0b93e8d 100644 --- a/templates/backOffice/default/export-page.html +++ b/templates/backOffice/default/export-page.html @@ -1,41 +1,41 @@ {extends file="admin-layout.tpl"} {block name="no-return-functions"} - {$admin_current_location = 'tools'} + {$admin_current_location = 'modules'} {/block} -{block name="page-title"}{intl l='Export: %title' title=$TITLE}{/block} +{block name="page-title"}{intl l='Export'}: {$TITLE}{/block} {block name="check-resource"}admin.export{/block} {block name="check-access"}view{/block} {block name="main-content"} - {form name="thelia.admin.export"} -
-
-
+
- + -
-
-
-
- {intl l="Export"} -
-
+
+
+
+ +
+ {intl l='Export: '}{$TITLE} +
+ + {form name="thelia.export"} + +
+
{ifloop rel="export-formatters"} -
- -
-
+
+
{custom_render_form_field form=$form field="formatter"} {/custom_render_form_field}
- -
-
-
- -
- -
+
+ {form_field form=$form field="do_compress"} + +
+
-
-
-
- {custom_render_form_field form=$form field="archive_builder"} - - {/custom_render_form_field} -
-
+ {/form_field}
- -
+
+
+
+ {custom_render_form_field form=$form field="archive_builder"} + + {/custom_render_form_field} +
+
{form_field form=$form field="images"} -
- +
+
{/form_field}
-
+
{form_field form=$form field="documents"} -
- +
+
{/form_field}
-
-
- {/ifloop} - {elseloop rel="export-formatters"} -
-
-
- {intl l="You can't do exports, you don't have any formatter that handles this."} + {/ifloop} + {elseloop rel="export-formatters"} +
+
+
+ {intl l="You can't do exports, you don't have any formatter that handles this."} +
-
- {/elseloop} + {/elseloop} +
-
+ + + + {/form}
- - {/form} +
{/block} {block name="javascript-initialization"} @@ -124,19 +121,19 @@ {/block} {block name="javascript-last-call"} - {module_include location='configuration-js'} diff --git a/templates/backOffice/default/export.html b/templates/backOffice/default/export.html index beccb4987..5d41464ec 100644 --- a/templates/backOffice/default/export.html +++ b/templates/backOffice/default/export.html @@ -17,6 +17,7 @@ {assign url_export "export_order="|cat:$export_order} {/if} +
@@ -33,17 +34,18 @@ {module_include location='tools_top'} {loop name="export-category" type="export-category" order=$category_order} + {assign category_title $TITLE}
-
+
@@ -77,20 +94,20 @@ {$ID}
- + {$POSITION} - + {$TITLE} @@ -51,17 +53,32 @@
- + {if $export_order == "id"} + + {elseif $export_order == "id_reverse"} + + {/if} + {intl l="ID"} - + {if $export_order == "alpha"} + + {elseif $export_order == "alpha_reverse"} + + {/if} + {intl l="Name"} - + {if $export_order == "manual"} + + {elseif $export_order == "manual_reverse"} + + {/if} + {intl l="Position"} - {$TITLE} + {$TITLE} - + {$POSITION} - + @@ -115,4 +132,59 @@ {module_include location='configuration_bottom'} +{/block} + +{block name="javascript-initialization"} + {javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'} + + {/javascripts} +{/block} + +{block name="javascript-last-call"} + + {module_include location='configuration-js'} {/block} \ No newline at end of file