From 33695a788685ecaa55c4f06a27d2618ab291846c Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 11 Jul 2014 10:46:16 +0200 Subject: [PATCH] =?UTF-8?q?Implement=20export=20types=20=09modifi=C3=A9:?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20core/lib/Thelia/Controller/Admin/Imp?= =?UTF-8?q?ortExportController.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20core/lib/Thelia/Core/FileFormat/Formatting/Formatter/Json?= =?UTF-8?q?Formatter.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core?= =?UTF-8?q?/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.p?= =?UTF-8?q?hp=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia?= =?UTF-8?q?/Core/Template/Loop/Formatter.php=20=09modifi=C3=A9:=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20core/lib/Thelia/ImportExport/Export/MailingEx?= =?UTF-8?q?port.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/?= =?UTF-8?q?Thelia/Model/Export.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20templates/backOffice/default/export-page.html=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20templates/backOffice/default/?= =?UTF-8?q?includes/export-form-definition.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/ImportExportController.php | 5 + .../Formatting/Formatter/JsonFormatter.php | 5 +- .../Formatting/Formatter/XMLFormatter.php | 5 +- .../Thelia/Core/Template/Loop/Formatter.php | 5 +- .../ImportExport/Export/MailingExport.php | 22 ++++ core/lib/Thelia/Model/Export.php | 29 +++-- templates/backOffice/default/export-page.html | 107 +++++++++++++++++- .../includes/export-form-definition.html | 96 ---------------- 8 files changed, 157 insertions(+), 117 deletions(-) diff --git a/core/lib/Thelia/Controller/Admin/ImportExportController.php b/core/lib/Thelia/Controller/Admin/ImportExportController.php index c9ab79e86..6b3f8e269 100644 --- a/core/lib/Thelia/Controller/Admin/ImportExportController.php +++ b/core/lib/Thelia/Controller/Admin/ImportExportController.php @@ -46,6 +46,11 @@ class ImportExportController extends BaseAdminController return $this->render("404"); } + $this->getParserContext() + ->set("ID", $export->getId()) + ->set("TITLE", $export->getTitle()) + ; + return $this->render("export-page"); } diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/JsonFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/JsonFormatter.php index 04612bfdb..75a4a9148 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/JsonFormatter.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/JsonFormatter.php @@ -90,9 +90,6 @@ class JsonFormatter extends AbstractFormatter public function getExportType() { - return array( - ExportType::EXPORT_TABLE, - ExportType::EXPORT_UNBOUNDED, - ); + return ExportType::EXPORT_UNBOUNDED; } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.php index 45046af96..558446bae 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.php @@ -145,9 +145,6 @@ class XMLFormatter extends AbstractFormatter public function getExportType() { - return array( - ExportType::EXPORT_TABLE, - ExportType::EXPORT_UNBOUNDED, - ); + return ExportType::EXPORT_UNBOUNDED; } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Loop/Formatter.php b/core/lib/Thelia/Core/Template/Loop/Formatter.php index 15cac4399..71a81ad1e 100644 --- a/core/lib/Thelia/Core/Template/Loop/Formatter.php +++ b/core/lib/Thelia/Core/Template/Loop/Formatter.php @@ -46,8 +46,9 @@ class Formatter extends BaseLoop implements ArraySearchLoopInterface $export = ExportQuery::create()->findPk($exportId); if (null !== $export) { - $types = $export->getHandleClassInstance($this->container) - ->getHandledType(); + $handlerInstance = $export->getHandleClassInstance($this->container); + + $types = $handlerInstance->getHandledType(); if (is_scalar($types)) { $types = [$types]; diff --git a/core/lib/Thelia/ImportExport/Export/MailingExport.php b/core/lib/Thelia/ImportExport/Export/MailingExport.php index 01e73eb8e..8e572e1a8 100644 --- a/core/lib/Thelia/ImportExport/Export/MailingExport.php +++ b/core/lib/Thelia/ImportExport/Export/MailingExport.php @@ -44,4 +44,26 @@ class MailingExport implements ExportHandlerInterface $data = new FormatterData(); } + /** + * @return string|array + * + * Define all the type of export/formatters that this can handle + * return a string if it handle a single type ( specific exports ), + * or an array if multiple. + * + * Thelia types are defined in \Thelia\ImportExport\Export\ExportType + * + * example: + * return array( + * ExportType::EXPORT_TABLE, + * ExportType::EXPORT_UNBOUNDED, + * ); + */ + public function getHandledType() + { + return array( + ExportType::EXPORT_TABLE, + ExportType::EXPORT_UNBOUNDED, + ); + } } \ No newline at end of file diff --git a/core/lib/Thelia/Model/Export.php b/core/lib/Thelia/Model/Export.php index 529aeba54..7df3107c5 100644 --- a/core/lib/Thelia/Model/Export.php +++ b/core/lib/Thelia/Model/Export.php @@ -4,6 +4,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\Model\Base\Export as BaseExport; use Thelia\Model\Map\ExportTableMap; @@ -83,24 +84,32 @@ class Export extends BaseExport { $class = $this->getHandleClass(); + if ($class[0] !== "\\") { + $class = "\\" . $class; + } + if (!class_exists($class)) { throw new \ErrorException( - "The class \"%class\" doesn't exist", - [ - "%class" => $class - ] + Translator::getInstance()->trans( + "The class \"%class\" doesn't exist", + [ + "%class" => $class + ] + ) ); } $instance = new $class($container); - if (!$class instanceof ExportHandlerInterface) { + if (!$instance instanceof ExportHandlerInterface) { throw new \ErrorException( - "The class \"%class\" must implement %interface", - [ - "%class" => $class, - "%interface" => "\\Thelia\\ImportExport\\ExportHandlerInterface", - ] + Translator::getInstance()->trans( + "The class \"%class\" must implement %interface", + [ + "%class" => $class, + "%interface" => "\\Thelia\\ImportExport\\ExportHandlerInterface", + ] + ) ); } diff --git a/templates/backOffice/default/export-page.html b/templates/backOffice/default/export-page.html index f1b49c6ef..d5fd65e21 100644 --- a/templates/backOffice/default/export-page.html +++ b/templates/backOffice/default/export-page.html @@ -4,12 +4,117 @@ {$admin_current_location = 'tools'} {/block} -{block name="page-title"}{intl l='Export: %name' name=$NAME}{/block} +{block name="page-title"}{intl l='Export: %title' title=$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"} +
+
+ {ifloop rel="export-formatters"} +
+ +
+
+ {custom_render_form_field form=$form field="formatter"} + + {/custom_render_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."} +
+
+
+ {/elseloop} +
+
+
+
+
+
+ {/form} {/block} {block name="javascript-initialization"} diff --git a/templates/backOffice/default/includes/export-form-definition.html b/templates/backOffice/default/includes/export-form-definition.html index 2ee6add0d..e69de29bb 100644 --- a/templates/backOffice/default/includes/export-form-definition.html +++ b/templates/backOffice/default/includes/export-form-definition.html @@ -1,96 +0,0 @@ -{* - - This file defines the fields used for export configuration: - - Export format - - With images ? documents ? - - archive format ? - -*} - -
-
-
-
- {intl l="Export options"} -
-
- {ifloop rel="export-formatters"} -
- -
-
- {custom_render_form_field form=$form field="formatter"} - - {/custom_render_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"} -
-
-
- {/elseloop} -
-
-
\ No newline at end of file