Add BEFORE_EXPORT event and fix bug on modal
modifié: core/lib/Thelia/Controller/Admin/ImportExportController.php nouveau fichier: core/lib/Thelia/Core/Event/ImportExport/Export.php modifié: core/lib/Thelia/Core/Event/TheliaEvents.php modifié: core/lib/Thelia/Core/FileFormat/Formatting/Formatter/XMLFormatter.php modifié: templates/backOffice/default/ajax/export-modal.html modifié: templates/backOffice/default/export-page.html
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
use Thelia\Core\Event\ImportExport\Export as ExportEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\HttpFoundation\Response;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Loop\Export as ExportLoop;
|
||||
@@ -115,12 +117,24 @@ class ImportExportController extends BaseAdminController
|
||||
$boundForm->get("formatter")->getData()
|
||||
);
|
||||
|
||||
$formattedContent = $formatter->encode($data);
|
||||
|
||||
$filename = $formatter::FILENAME . "." . $formatter->getExtension();
|
||||
|
||||
if (!$boundForm->get("do_compress")->getData()) {
|
||||
|
||||
/**
|
||||
* Build an event containing the formatter and the handler.
|
||||
* Used for specific configuration (e.g: XML node names)
|
||||
*/
|
||||
$event = new ExportEvent($formatter, $handler);
|
||||
|
||||
if (!$boundForm->get("do_compress")->getData())
|
||||
{
|
||||
/**
|
||||
* Dispatch the event
|
||||
*/
|
||||
$this->dispatch(TheliaEvents::BEFORE_EXPORT, $event);
|
||||
|
||||
$formattedContent = $formatter->encode($data);
|
||||
|
||||
return new Response(
|
||||
$formattedContent,
|
||||
@@ -137,21 +151,31 @@ class ImportExportController extends BaseAdminController
|
||||
$boundForm->get("archive_builder")->getData()
|
||||
);
|
||||
|
||||
/**
|
||||
* Put the images in the archive
|
||||
*/
|
||||
if ($boundForm->get("images")->getData() && $handler instanceof ImagesExportInterface) {
|
||||
foreach ($handler->getImagesPaths() as $image) {
|
||||
$archiveBuilder->addFile($image, "images");
|
||||
$event->setArchiveBuilder($archiveBuilder);
|
||||
$this->dispatch(TheliaEvents::BEFORE_EXPORT, $event);
|
||||
|
||||
$formattedContent = $formatter->encode($data);
|
||||
|
||||
$includeImages = $boundForm->get("images")->getData();
|
||||
$includeDocuments = $boundForm->get("documents")->getData();
|
||||
|
||||
if ($includeImages && $handler instanceof ImagesExportInterface) {
|
||||
foreach ($handler->getImagesPaths() as $name => $documentPath) {
|
||||
$archiveBuilder->addFile(
|
||||
$documentPath,
|
||||
$handler::IMAGES_DIRECTORY,
|
||||
is_integer($name) ? null : $name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Then the documents
|
||||
*/
|
||||
if ($boundForm->get("documents")->getData() && $handler instanceof DocumentsExportInterface) {
|
||||
foreach ($handler->getDocumentsPaths() as $document) {
|
||||
$archiveBuilder->addFile($document, "documents");
|
||||
if ($includeDocuments && $handler instanceof DocumentsExportInterface) {
|
||||
foreach ($handler->getDocumentsPaths() as $name => $documentPath) {
|
||||
$archiveBuilder->addFile(
|
||||
$documentPath,
|
||||
$handler::DOCUMENTS_DIRECTORY,
|
||||
is_integer($name) ? null : $name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
101
core/lib/Thelia/Core/Event/ImportExport/Export.php
Normal file
101
core/lib/Thelia/Core/Event/ImportExport/Export.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?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\Event\ImportExport;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder;
|
||||
use Thelia\Core\FileFormat\Formatting\AbstractFormatter;
|
||||
use Thelia\ImportExport\ExportHandler;
|
||||
|
||||
/**
|
||||
* Class Export
|
||||
* @package Thelia\Core\Event\ImportExport
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class Export extends ActionEvent
|
||||
{
|
||||
/** @var \Thelia\ImportExport\ExportHandler */
|
||||
protected $handler;
|
||||
|
||||
/** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter */
|
||||
protected $formatter;
|
||||
|
||||
/** @var \Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder */
|
||||
protected $archiveBuilder;
|
||||
|
||||
function __construct(
|
||||
AbstractFormatter $formatter,
|
||||
ExportHandler $handler,
|
||||
AbstractArchiveBuilder $archiveBuilder = null
|
||||
) {
|
||||
$this->archiveBuilder = $archiveBuilder;
|
||||
$this->formatter = $formatter;
|
||||
$this->handler = $handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractArchiveBuilder $archiveBuilder
|
||||
* @return $this
|
||||
*/
|
||||
public function setArchiveBuilder(AbstractArchiveBuilder $archiveBuilder)
|
||||
{
|
||||
$this->archiveBuilder = $archiveBuilder;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder
|
||||
*/
|
||||
public function getArchiveBuilder()
|
||||
{
|
||||
return $this->archiveBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractFormatter $formatter
|
||||
* @return $this
|
||||
*/
|
||||
public function setFormatter(AbstractFormatter $formatter)
|
||||
{
|
||||
$this->formatter = $formatter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Core\FileFormat\Formatting\AbstractFormatter
|
||||
*/
|
||||
public function getFormatter()
|
||||
{
|
||||
return $this->formatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ExportHandler $handler
|
||||
* @return $this
|
||||
*/
|
||||
public function setHandler(ExportHandler $handler)
|
||||
{
|
||||
$this->handler = $handler;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\ImportExport\ExportHandler
|
||||
*/
|
||||
public function getHandler()
|
||||
{
|
||||
return $this->handler;
|
||||
}
|
||||
}
|
||||
@@ -766,4 +766,8 @@ final class TheliaEvents
|
||||
|
||||
const BEFORE_UPDATEBRAND = "action.before_updateBrand";
|
||||
const AFTER_UPDATEBRAND = "action.after_updateBrand";
|
||||
|
||||
// -- Export ----------------------------------------------
|
||||
|
||||
const BEFORE_EXPORT = "Thelia.before.export";
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ class XMLFormatter extends AbstractFormatter
|
||||
{
|
||||
public $root = "data";
|
||||
public $nodeName = "node";
|
||||
public $rowName = "row";
|
||||
|
||||
/**
|
||||
* @return string
|
||||
@@ -85,7 +86,13 @@ class XMLFormatter extends AbstractFormatter
|
||||
$node = $container->appendChild(new \DOMElement($this->nodeName));
|
||||
$this->recursiveBuild($entry, $node);
|
||||
} else {
|
||||
$container->appendChild(new \DOMElement($key, $entry));
|
||||
$node = new \DOMElement($this->nodeName);
|
||||
$container->appendChild($node);
|
||||
|
||||
/** @var \DOMElement $lastChild */
|
||||
$lastChild = $container->lastChild;
|
||||
$lastChild->setAttribute("name",$key);
|
||||
$lastChild->setAttribute("value", $entry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +109,13 @@ class XMLFormatter extends AbstractFormatter
|
||||
$newNode = $node->appendChild(new \DOMElement($key));
|
||||
$this->recursiveBuild($entry, $newNode);
|
||||
} else {
|
||||
$node->appendChild(new \DOMElement($key, $entry));
|
||||
$inputNode = new \DOMElement($this->rowName);
|
||||
$node->appendChild($inputNode);
|
||||
|
||||
/** @var \DOMElement $lastChild */
|
||||
$lastChild = $node->lastChild;
|
||||
$lastChild->setAttribute("name",$key);
|
||||
$lastChild->setAttribute("value", $entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,21 +15,16 @@
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
{form_field form=$form field="formatter"}
|
||||
<div class="form-group {if $error}has-error{/if}">
|
||||
<label for="{$label_attr.for}">
|
||||
{$label}
|
||||
</label>
|
||||
<select name="{$name}" id="{$label_attr.for}">
|
||||
{loop name="export-formatters" type="formatter" export=$ID}
|
||||
<option value="{$NAME}" {if $value == $NAME}selected{/if}>
|
||||
{$NAME} (.{$EXTENSION})
|
||||
</option>
|
||||
{/loop}
|
||||
</select>
|
||||
{if $error}
|
||||
<div class="error-field">{$message}</div>
|
||||
{/if}
|
||||
</div>
|
||||
<label for="{$label_attr.for}">
|
||||
{$label}
|
||||
</label>
|
||||
<select name="{$name}" id="{$label_attr.for}">
|
||||
{loop name="export-formatters" type="formatter" export=$ID}
|
||||
<option value="{$NAME}" {if $value == $NAME}selected{/if}>
|
||||
{$NAME} (.{$EXTENSION})
|
||||
</option>
|
||||
{/loop}
|
||||
</select>
|
||||
{/form_field}
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
@@ -45,7 +40,10 @@
|
||||
</div>
|
||||
<div class="row export-compression-selection-row">
|
||||
<div class="col-md-4">
|
||||
{custom_render_form_field form=$form field="archive_builder"}
|
||||
{form_field form=$form field="archive_builder"}
|
||||
<label for="{$label_attr.for}">
|
||||
{$label}
|
||||
</label>
|
||||
<select name="{$name}" id="{$label_attr.for}">
|
||||
{loop name="export-archive-builder" type="archive-builder"}
|
||||
<option value="{$NAME}" {if $value == $NAME}selected{/if}>
|
||||
@@ -53,7 +51,7 @@
|
||||
</option>
|
||||
{/loop}
|
||||
</select>
|
||||
{/custom_render_form_field}
|
||||
{/form_field}
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
{form_field form=$form field="images"}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{extends file="admin-layout.tpl"}
|
||||
|
||||
{block name="no-return-functions"}
|
||||
{$admin_current_location = 'modules'}
|
||||
{$admin_current_location = 'tools'}
|
||||
{/block}
|
||||
|
||||
{block name="page-title"}{intl l='Export'}: {$TITLE}{/block}
|
||||
|
||||
Reference in New Issue
Block a user