Refactor and fix CS

modifié:         core/lib/Thelia/Controller/Admin/ImportExportController.php
	modifié:         core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php
	modifié:         core/lib/Thelia/Core/Event/ImportExport/Export.php
	modifié:         core/lib/Thelia/Core/FileFormat/Archive/ArchiveBuilderManager.php
	renommé:         core/lib/Thelia/ImportExport/Export/ExportType.php -> core/lib/Thelia/Core/FileFormat/FormatType.php
	modifié:         core/lib/Thelia/Core/FileFormat/Formatting/Formatter/JsonFormatter.php
	modifié:         core/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.php
	modifié:         core/lib/Thelia/Core/FileFormat/Formatting/FormatterInterface.php
	modifié:         core/lib/Thelia/Core/FileFormat/Formatting/FormatterManager.php
	modifié:         core/lib/Thelia/Core/Template/Loop/Formatter.php
	modifié:         core/lib/Thelia/Core/Template/Loop/ImportExportCategory.php
	modifié:         core/lib/Thelia/Core/Template/Loop/ProductSaleElements.php
	modifié:         core/lib/Thelia/Form/ImportForm.php
	renommé:         core/lib/Thelia/ImportExport/ExportHandler.php -> core/lib/Thelia/ImportExport/AbstractHandler.php
	nouveau fichier: core/lib/Thelia/ImportExport/Export/ExportHandler.php
	modifié:         core/lib/Thelia/ImportExport/Export/MailingExport.php
	renommé:         core/lib/Thelia/ImportExport/ImportHandler.php -> core/lib/Thelia/ImportExport/Import/ImportHandler.php
	modifié:         core/lib/Thelia/ImportExport/Import/ProductStockImport.php
	modifié:         core/lib/Thelia/Model/Export.php
	modifié:         core/lib/Thelia/Model/Import.php
	modifié:         core/lib/Thelia/Tests/ImportExport/Export/MailingExportTest.php
	modifié:         core/lib/Thelia/Tools/URL.php
	modifié:         templates/backOffice/default/ajax/import-modal.html
This commit is contained in:
Benjamin Perche
2014-07-17 10:52:17 +02:00
parent af5d355e19
commit a6f008fde2
23 changed files with 230 additions and 126 deletions

View File

@@ -26,8 +26,8 @@ use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Loader\FileLoader;
use Thelia\Core\Translation\Translator;
use Thelia\ImportExport\ExportHandler;
use Thelia\ImportExport\ImportHandler;
use Thelia\ImportExport\Export\ExportHandler;
use Thelia\ImportExport\Import\ImportHandler;
use Thelia\Model\Export;
use Thelia\Model\ExportCategory;
use Thelia\Model\ExportCategoryQuery;
@@ -381,7 +381,7 @@ class XmlFileLoader extends FileLoader
"The class \"%class\" must extend %baseClass",
[
"%class" => $class,
"%baseClass" => "Thelia\\ImportExport\\ExportHandler",
"%baseClass" => "Thelia\\ImportExport\\Export\\ExportHandler",
]
)
);

View File

@@ -14,7 +14,7 @@ namespace Thelia\Core\Event\ImportExport;
use Thelia\Core\Event\ActionEvent;
use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder;
use Thelia\Core\FileFormat\Formatting\AbstractFormatter;
use Thelia\ImportExport\ExportHandler;
use Thelia\ImportExport\Export\ExportHandler;
/**
* Class Export
@@ -23,7 +23,7 @@ use Thelia\ImportExport\ExportHandler;
*/
class Export extends ActionEvent
{
/** @var \Thelia\ImportExport\ExportHandler */
/** @var \Thelia\ImportExport\Export\ExportHandler */
protected $handler;
/** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter */
@@ -34,7 +34,7 @@ class Export extends ActionEvent
public function __construct(
AbstractFormatter $formatter,
ExportHandler $handler,
\Thelia\ImportExport\Export\ExportHandler $handler,
AbstractArchiveBuilder $archiveBuilder = null
) {
$this->archiveBuilder = $archiveBuilder;
@@ -81,7 +81,7 @@ class Export extends ActionEvent
}
/**
* @param ExportHandler $handler
* @param \Thelia\ImportExport\Export\ExportHandler $handler
* @return $this
*/
public function setHandler(ExportHandler $handler)
@@ -92,7 +92,7 @@ class Export extends ActionEvent
}
/**
* @return \Thelia\ImportExport\ExportHandler
* @return \Thelia\ImportExport\Export\ExportHandler
*/
public function getHandler()
{

View File

@@ -103,4 +103,39 @@ class ArchiveBuilderManager
)
);
}
/**
* @return array
*
* Return the extensions handled by archive builders
*/
public function getExtensions()
{
$extensions = [];
/** @var AbstractArchiveBuilder $archiveBuilder */
foreach ($this->archiveBuilders as $archiveBuilder) {
$extensions += [$archiveBuilder->getName() => $archiveBuilder->getExtension()];
}
return $extensions;
}
/**
* @param $extension
* @return bool|AbstractArchiveBuilder
*/
public function getArchiveBuilderByExtension($extension)
{
$extensions = $this->getExtensions();
if (!in_array($extension, $extensions)) {
return false;
} else {
$flip = array_flip($extensions);
$archiveBuilderName = $flip[$extension];
return $this->archiveBuilders[$archiveBuilderName];
}
}
}

View File

@@ -0,0 +1,33 @@
<?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\Core\FileFormat;
/**
* Class FormatType
* @package Thelia\Core\FileFormat
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class FormatType
{
/**
* This type is for unbounded formats, in general serialization formats
* example: XML, json, yaml
*/
const UNBOUNDED = "export.unbounded";
/**
* This type is for tabled format ( matrix ), most used by spreadsheet application.
* example: CSV, ODS, XLS
*/
const TABLE = "export.table";
}

View File

@@ -13,7 +13,7 @@
namespace Thelia\Core\FileFormat\Formatting\Formatter;
use Thelia\Core\FileFormat\Formatting\AbstractFormatter;
use Thelia\Core\FileFormat\Formatting\FormatterData;
use Thelia\ImportExport\Export\ExportType;
use Thelia\Core\FileFormat\FormatType;
/**
* Class JsonFormatter
@@ -88,8 +88,8 @@ class JsonFormatter extends AbstractFormatter
);
}
public function getExportType()
public function getHandledType()
{
return ExportType::EXPORT_UNBOUNDED;
return FormatType::UNBOUNDED;
}
}

View File

@@ -14,7 +14,7 @@ namespace Thelia\Core\FileFormat\Formatting\Formatter;
use Thelia\Core\FileFormat\Formatter\Exception\BadFormattedStringException;
use Thelia\Core\FileFormat\Formatting\AbstractFormatter;
use Thelia\Core\FileFormat\Formatting\FormatterData;
use Thelia\ImportExport\Export\ExportType;
use Thelia\Core\FileFormat\FormatType;
/**
* Class XMLFormatter
@@ -157,8 +157,8 @@ class XMLFormatter extends AbstractFormatter
return $data->setData($array);
}
public function getExportType()
public function getHandledType()
{
return ExportType::EXPORT_UNBOUNDED;
return FormatType::UNBOUNDED;
}
}

View File

@@ -42,11 +42,11 @@ interface FormatterInterface
*
* return a string that defines the handled format type.
*
* Thelia types are defined in \Thelia\ImportExport\Export\ExportType
* Thelia types are defined in \Thelia\Core\FileFormat\FormatType
*
* examples:
* return ExportType::EXPORT_TABLE;
* return ExportType::EXPORT_UNBOUNDED;
* return FormatType::TABLE;
* return FormatType::UNBOUNDED;
*/
public function getExportType();
public function getHandledType();
}

View File

@@ -99,4 +99,59 @@ class FormatterManager
)
);
}
/**
* @return array
*
* Return the extensions handled by archive builders
*/
public function getExtensions()
{
$extensions = [];
/** @var AbstractFormatter $formatter */
foreach ($this->formatters as $formatter) {
$extensions += [$formatter->getName() => $formatter->getExtension()];
}
return $extensions;
}
/**
* @param $extension
* @return bool|AbstractFormatter
*/
public function getFormatterByExtension($extension)
{
$extensions = $this->getExtensions();
if (!in_array($extension, $extensions)) {
return false;
} else {
$flip = array_flip($extensions);
$formatterName = $flip[$extension];
return $this->formatters[$formatterName];
}
}
public function getFormattersByTypes($types)
{
if (!is_array($types)) {
$types = [$types];
}
$selectedFormatters = [];
/** @var AbstractFormatter $formatter */
foreach ($this->formatters as $formatter) {
$handledType = $formatter->getHandledType();
if (in_array($handledType, $types)) {
$selectedFormatters += [$formatter->getName() => $formatter];
}
}
return $selectedFormatters;
}
}

View File

@@ -49,7 +49,7 @@ class Formatter extends BaseLoop implements ArraySearchLoopInterface
if (null !== $export) {
$handlerInstance = $export->getHandleClassInstance($this->container);
$types = $handlerInstance->getHandledType();
$types = $handlerInstance->getHandledTypes();
if (is_scalar($types)) {
$types = [$types];
@@ -57,7 +57,7 @@ class Formatter extends BaseLoop implements ArraySearchLoopInterface
/** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter $formatter */
foreach ($rawFormatters as $key=>$formatter) {
if (in_array($formatter->getExportType(), $types)) {
if (in_array($formatter->getHandledType(), $types)) {
$formatters[$key] = $formatter;
}
}

View File

@@ -14,7 +14,6 @@ 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;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;

View File

@@ -84,7 +84,7 @@ class ProductSaleElements extends BaseLoop implements PropelSearchLoopInterface
break;
case "quantity_reverse":
$search->orderByQuantity(Criteria::DESC);
break;
break;
case "min_price":
$search->addAscendingOrderByColumn('price_FINAL_PRICE', Criteria::ASC);
break;