Finish export forms

modifié:         core/lib/Thelia/Config/Resources/config.xml
	modifié:         core/lib/Thelia/Config/Resources/form.xml
	modifié:         core/lib/Thelia/Controller/Admin/ExportController.php
	modifié:         core/lib/Thelia/Controller/Admin/ImportExportController.php
	modifié:         core/lib/Thelia/Core/Template/Loop/Formatter.php
	modifié:         core/lib/Thelia/Core/Template/Loop/ImportExportType.php
	modifié:         core/lib/Thelia/Form/ExportForm.php
	modifié:         core/lib/Thelia/ImportExport/Both/NewsletterImportExport.php
	modifié:         core/lib/Thelia/ImportExport/Export/MailingExport.php
	renommé:         core/lib/Thelia/ImportExport/ExportHandlerInterface.php -> core/lib/Thelia/ImportExport/ExportHandler.php
	modifié:         core/lib/Thelia/Model/Export.php
	modifié:         core/lib/Thelia/Model/Import.php
	nouveau fichier: core/lib/Thelia/Tests/ImportExport/Export/MailingExportTest.php
	nouveau fichier: templates/backOffice/default/ajax/export-modal.html
	modifié:         templates/backOffice/default/export-page.html
	modifié:         templates/backOffice/default/export.html
This commit is contained in:
Benjamin Perche
2014-07-11 16:06:15 +02:00
parent 33695a7886
commit b6937ab421
16 changed files with 453 additions and 127 deletions

View File

@@ -146,7 +146,7 @@
<!-- zip -->
<service id="thelia.archive_builder.zip" class="Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveBuilder">
<tag name="thelia.manager.archive_builder" />
<tag name="thelia.archive_builder" />
</service>
<!-- tar -->

View File

@@ -133,7 +133,7 @@
<form name="thelia.assets.flush" class="Thelia\Form\Cache\AssetsFlushForm"/>
<form name="thelia.images-and-documents-cache.flush" class="Thelia\Form\Cache\ImagesAndDocumentsCacheFlushForm"/>
<form name="thelia.admin.export" class="Thelia\Form\ExportForm" />
<form name="thelia.export" class="Thelia\Form\ExportForm" />
</forms>

View File

@@ -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()

View File

@@ -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)

View File

@@ -42,6 +42,7 @@ class Formatter extends BaseLoop implements ArraySearchLoopInterface
$exportId = $this->getExport();
$formatters = [];
if ($exportId !== null) {
$export = ExportQuery::create()->findPk($exportId);

View File

@@ -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 <bperche@openstudio.fr>
*/
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);
}

View File

@@ -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"],

View File

@@ -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 <bperche@openstudio.fr>
*/
class NewsletterImportExport implements ExportHandlerInterface, ImportHandlerInterface
class NewsletterImportExport implements ExportHandler, ImportHandlerInterface
{
protected $container;

View File

@@ -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 <bperche@openstudio.fr>
*/
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);
}
/**

View File

@@ -14,25 +14,29 @@ namespace Thelia\ImportExport;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Interface ExportHandlerInterface
* Interface ExportHandler
* @package Thelia\ImportExport
* @author Benjamin Perche <bperche@openstudio.fr>
*/
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();
}

View File

@@ -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",
]
)
);

View File

@@ -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",
]
);
}

View File

@@ -0,0 +1,52 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Tests\ImportExport\Export;
use Symfony\Component\DependencyInjection\Container;
use Thelia\Core\Translation\Translator;
use Thelia\ImportExport\Export\ExportType;
use Thelia\ImportExport\Export\MailingExport;
/**
* Class MailingExportTest
* @package Thelia\Tests\ImportExport\Export
* @author Benjamin Perche <bperche@openstudio.fr>
*/
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()
);
}
}