Refactor position management with trait
nouveau fichier: core/lib/Thelia/Action/Export.php nouveau fichier: core/lib/Thelia/Action/Import.php modifié: core/lib/Thelia/Config/Resources/action.xml modifié: core/lib/Thelia/Config/Resources/routing/admin.xml modifié: core/lib/Thelia/Controller/Admin/ExportController.php modifié: core/lib/Thelia/Controller/Admin/ImportController.php modifié: core/lib/Thelia/Core/Event/TheliaEvents.php modifié: core/lib/Thelia/ImportExport/Export/Type/ProductTaxedPricesExport.php modifié: core/lib/Thelia/Model/Export.php modifié: core/lib/Thelia/Model/ExportCategory.php modifié: core/lib/Thelia/Model/Import.php modifié: core/lib/Thelia/Model/ImportCategory.php modifié: templates/backOffice/default/export.html
This commit is contained in:
91
core/lib/Thelia/Action/Export.php
Normal file
91
core/lib/Thelia/Action/Export.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?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\Action;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\Cache\CacheEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Model\ExportCategoryQuery;
|
||||
use Thelia\Model\ExportQuery;
|
||||
|
||||
/**
|
||||
* Class Export
|
||||
* @package Thelia\Action
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class Export extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function changeCategoryPosition(UpdatePositionEvent $event)
|
||||
{
|
||||
$this->genericUpdatePosition(new ExportCategoryQuery(), $event);
|
||||
|
||||
$this->cacheClear($event->getDispatcher());
|
||||
}
|
||||
|
||||
public function changeExportPosition(UpdatePositionEvent $event)
|
||||
{
|
||||
$this->genericUpdatePosition(new ExportQuery(), $event);
|
||||
|
||||
$this->cacheClear($event->getDispatcher());
|
||||
}
|
||||
|
||||
protected function cacheClear(EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$cacheEvent = new CacheEvent(
|
||||
$this->container->getParameter('kernel.cache_dir')
|
||||
);
|
||||
|
||||
$dispatcher->dispatch(TheliaEvents::CACHE_CLEAR, $cacheEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber wants to listen to.
|
||||
*
|
||||
* The array keys are event names and the value can be:
|
||||
*
|
||||
* * The method name to call (priority defaults to 0)
|
||||
* * An array composed of the method name to call and the priority
|
||||
* * An array of arrays composed of the method names to call and respective
|
||||
* priorities, or 0 if unset
|
||||
*
|
||||
* For instance:
|
||||
*
|
||||
* * array('eventName' => 'methodName')
|
||||
* * array('eventName' => array('methodName', $priority))
|
||||
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
|
||||
*
|
||||
* @return array The event names to listen to
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
TheliaEvents::EXPORT_CATEGORY_CHANGE_POSITION => array("changeCategoryPosition", 128),
|
||||
TheliaEvents::EXPORT_CHANGE_POSITION => array("changeExportPosition", 128),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
91
core/lib/Thelia/Action/Import.php
Normal file
91
core/lib/Thelia/Action/Import.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?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\Action;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\Cache\CacheEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Model\ImportCategoryQuery;
|
||||
use Thelia\Model\ImportQuery;
|
||||
|
||||
/**
|
||||
* Class Import
|
||||
* @package Thelia\Action
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class Import extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function changeCategoryPosition(UpdatePositionEvent $event)
|
||||
{
|
||||
$this->genericUpdatePosition(new ImportCategoryQuery(), $event);
|
||||
|
||||
$this->cacheClear($event->getDispatcher());
|
||||
}
|
||||
|
||||
public function changeImportPosition(UpdatePositionEvent $event)
|
||||
{
|
||||
$this->genericUpdatePosition(new ImportQuery(), $event);
|
||||
|
||||
$this->cacheClear($event->getDispatcher());
|
||||
}
|
||||
|
||||
protected function cacheClear(EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$cacheEvent = new CacheEvent(
|
||||
$this->container->getParameter('kernel.cache_dir')
|
||||
);
|
||||
|
||||
$dispatcher->dispatch(TheliaEvents::CACHE_CLEAR, $cacheEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber wants to listen to.
|
||||
*
|
||||
* The array keys are event names and the value can be:
|
||||
*
|
||||
* * The method name to call (priority defaults to 0)
|
||||
* * An array composed of the method name to call and the priority
|
||||
* * An array of arrays composed of the method names to call and respective
|
||||
* priorities, or 0 if unset
|
||||
*
|
||||
* For instance:
|
||||
*
|
||||
* * array('eventName' => 'methodName')
|
||||
* * array('eventName' => array('methodName', $priority))
|
||||
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
|
||||
*
|
||||
* @return array The event names to listen to
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
TheliaEvents::IMPORT_CATEGORY_CHANGE_POSITION => array("changeCategoryPosition", 128),
|
||||
TheliaEvents::IMPORT_CHANGE_POSITION => array("changeImportPosition", 128),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -163,6 +163,16 @@
|
||||
<service id="thelia.action.lang" class="Thelia\Action\Lang">
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
|
||||
<service id="thelia.export.change_position" class="Thelia\Action\Export">
|
||||
<argument type="service" id="service_container" />
|
||||
<tag name="kernel.event_subscriber" />
|
||||
</service>
|
||||
|
||||
<service id="thelia.import.change_position" class="Thelia\Action\Import">
|
||||
<argument type="service" id="service_container" />
|
||||
<tag name="kernel.event_subscriber" />
|
||||
</service>
|
||||
</services>
|
||||
|
||||
</config>
|
||||
|
||||
@@ -1158,86 +1158,6 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\TranslationsController::updateAction</default>
|
||||
</route>
|
||||
|
||||
<!-- export management -->
|
||||
|
||||
<route id="export.list" path="/admin/export">
|
||||
<default key="_controller">Thelia\Controller\Admin\ExportController::indexAction</default>
|
||||
</route>
|
||||
|
||||
<route id="export.position" path="/admin/export/position/{action}/{id}">
|
||||
<default key="_controller">Thelia\Controller\Admin\ExportController::changePosition</default>
|
||||
<requirement key="action">up|down</requirement>
|
||||
<requirement key="id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="export.position.update" path="/admin/export/position/update/{id}/{value}">
|
||||
<default key="_controller">Thelia\Controller\Admin\ExportController::updatePosition</default>
|
||||
<requirement key="id">\d+</requirement>
|
||||
<requirement key="value">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="export.category.position" path="/admin/export/position/category/{action}/{id}">
|
||||
<default key="_controller">Thelia\Controller\Admin\ExportController::changeCategoryPosition</default>
|
||||
<requirement key="action">up|down</requirement>
|
||||
<requirement key="id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="export.category.position.update" path="/admin/export/position/category/update/{id}/{value}">
|
||||
<default key="_controller">Thelia\Controller\Admin\ExportController::updateCategoryPosition</default>
|
||||
<requirement key="id">\d+</requirement>
|
||||
<requirement key="value">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="export.action" path="/admin/export/{id}" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Admin\ExportController::export</default>
|
||||
<requirement key="id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="export.view" path="/admin/export/{id}" methods="get">
|
||||
<default key="_controller">Thelia\Controller\Admin\ExportController::exportView</default>
|
||||
<requirement key="id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<!-- import management -->
|
||||
|
||||
<route id="import.list" path="/admin/import">
|
||||
<default key="_controller">Thelia\Controller\Admin\ImportController::indexAction</default>
|
||||
</route>
|
||||
|
||||
<route id="import.position" path="/admin/import/position/{action}/{id}">
|
||||
<default key="_controller">Thelia\Controller\Admin\ImportController::changePosition</default>
|
||||
<requirement key="action">up|down</requirement>
|
||||
<requirement key="id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="import.position.update" path="/admin/import/position/update/{id}/{value}">
|
||||
<default key="_controller">Thelia\Controller\Admin\ImportController::updatePosition</default>
|
||||
<requirement key="id">\d+</requirement>
|
||||
<requirement key="value">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="import.category.position" path="/admin/import/position/category/{action}/{id}">
|
||||
<default key="_controller">Thelia\Controller\Admin\ImportController::changeCategoryPosition</default>
|
||||
<requirement key="action">up|down</requirement>
|
||||
<requirement key="id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="import.category.position.update" path="/admin/import/position/category/update/{id}/{value}">
|
||||
<default key="_controller">Thelia\Controller\Admin\ImportController::updateCategoryPosition</default>
|
||||
<requirement key="id">\d+</requirement>
|
||||
<requirement key="value">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="import.action" path="/admin/import/{id}" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Admin\ImportController::import</default>
|
||||
<requirement key="id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="import.view" path="/admin/import/{id}" methods="get">
|
||||
<default key="_controller">Thelia\Controller\Admin\ImportController::importView</default>
|
||||
<requirement key="id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<!-- Routes to the Brands controller -->
|
||||
|
||||
<route id="admin.brand.default" path="/admin/brand">
|
||||
@@ -1274,6 +1194,54 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\BrandController::deleteAction</default>
|
||||
</route>
|
||||
|
||||
<!-- export management -->
|
||||
|
||||
<route id="export.list" path="/admin/export">
|
||||
<default key="_controller">Thelia\Controller\Admin\ExportController::indexAction</default>
|
||||
</route>
|
||||
|
||||
<route id="export.position" path="/admin/export/position">
|
||||
<default key="_controller">Thelia\Controller\Admin\ExportController::changePosition</default>
|
||||
</route>
|
||||
|
||||
<route id="export.category.position" path="/admin/export/position/category">
|
||||
<default key="_controller">Thelia\Controller\Admin\ExportController::changeCategoryPosition</default>
|
||||
</route>
|
||||
|
||||
<route id="export.mode" path="/admin/export/{id}" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Admin\ExportController::export</default>
|
||||
<requirement key="id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="export.view" path="/admin/export/{id}" methods="get">
|
||||
<default key="_controller">Thelia\Controller\Admin\ExportController::exportView</default>
|
||||
<requirement key="id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<!-- import management -->
|
||||
|
||||
<route id="import.list" path="/admin/import">
|
||||
<default key="_controller">Thelia\Controller\Admin\ImportController::indexAction</default>
|
||||
</route>
|
||||
|
||||
<route id="import.position" path="/admin/import/position">
|
||||
<default key="_controller">Thelia\Controller\Admin\ImportController::changePosition</default>
|
||||
</route>
|
||||
|
||||
<route id="import.category.position" path="/admin/import/position/category">
|
||||
<default key="_controller">Thelia\Controller\Admin\ImportController::changeCategoryPosition</default>
|
||||
</route>
|
||||
|
||||
<route id="import.mode" path="/admin/import/{id}" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Admin\ImportController::import</default>
|
||||
<requirement key="id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="import.view" path="/admin/import/{id}" methods="get">
|
||||
<default key="_controller">Thelia\Controller\Admin\ImportController::importView</default>
|
||||
<requirement key="id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<!-- The default route, to display a template -->
|
||||
|
||||
<route id="admin.processTemplate" path="/admin/{template}">
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\FileFormat\Archive\ArchiveBuilderManagerTrait;
|
||||
use Thelia\Core\FileFormat\Formatting\FormatterManagerTrait;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
@@ -328,72 +329,57 @@ class ExportController extends BaseAdminController
|
||||
}
|
||||
|
||||
|
||||
public function changePosition($action, $id)
|
||||
public function changePosition()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth([AdminResources::EXPORT], [], [AccessManager::UPDATE])) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$export = $this->getExport($id);
|
||||
$mode = $this->getRequest()->get("mode");
|
||||
$id = $this->getRequest()->get("id");
|
||||
$value = $this->getRequest()->get("value");
|
||||
|
||||
if ($action === "up") {
|
||||
$export->upPosition();
|
||||
} elseif ($action === "down") {
|
||||
$export->downPosition();
|
||||
}
|
||||
$this->getExport($id);
|
||||
|
||||
$event = new UpdatePositionEvent($id, $this->getMode($mode), $value);
|
||||
$this->dispatch(TheliaEvents::EXPORT_CHANGE_POSITION, $event);
|
||||
|
||||
$this->setOrders(null, "manual");
|
||||
|
||||
return $this->render('export');
|
||||
}
|
||||
|
||||
public function updatePosition($id, $value)
|
||||
public function changeCategoryPosition()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth([AdminResources::EXPORT], [], [AccessManager::UPDATE])) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$export = $this->getExport($id);
|
||||
$mode = $this->getRequest()->get("mode");
|
||||
$id = $this->getRequest()->get("id");
|
||||
$value = $this->getRequest()->get("value");
|
||||
|
||||
$export->updatePosition($value);
|
||||
$this->getCategory($id);
|
||||
|
||||
$this->setOrders(null, "manual");
|
||||
$event = new UpdatePositionEvent($id, $this->getMode($mode), $value);
|
||||
$this->dispatch(TheliaEvents::EXPORT_CATEGORY_CHANGE_POSITION, $event);
|
||||
|
||||
$this->setOrders("manual");
|
||||
|
||||
return $this->render('export');
|
||||
}
|
||||
|
||||
public function changeCategoryPosition($action, $id)
|
||||
public function getMode($action)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth([AdminResources::EXPORT], [], [AccessManager::UPDATE])) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$category = $this->getCategory($id);
|
||||
|
||||
if ($action === "up") {
|
||||
$category->upPosition();
|
||||
$mode = UpdatePositionEvent::POSITION_UP;
|
||||
} elseif ($action === "down") {
|
||||
$category->downPosition();
|
||||
$mode = UpdatePositionEvent::POSITION_DOWN;
|
||||
} else {
|
||||
$mode = UpdatePositionEvent::POSITION_ABSOLUTE;
|
||||
}
|
||||
|
||||
$this->setOrders("manual");
|
||||
|
||||
return $this->render('export');
|
||||
}
|
||||
|
||||
public function updateCategoryPosition($id, $value)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth([AdminResources::EXPORT], [], [AccessManager::UPDATE])) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$category = $this->getCategory($id);
|
||||
|
||||
$category->updatePosition($value);
|
||||
|
||||
$this->setOrders("manual");
|
||||
|
||||
return $this->render('export');
|
||||
return $mode;
|
||||
}
|
||||
|
||||
protected function setOrders($category = null, $export = null)
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
namespace Thelia\Controller\Admin;
|
||||
use Thelia\Core\Event\ImportExport as ImportExportEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder;
|
||||
use Thelia\Core\FileFormat\Archive\ArchiveBuilderManager;
|
||||
use Thelia\Core\FileFormat\Archive\ArchiveBuilderManagerTrait;
|
||||
@@ -426,72 +427,54 @@ class ImportController extends BaseAdminController
|
||||
;
|
||||
}
|
||||
|
||||
public function changePosition($action, $id)
|
||||
public function changePosition()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth([AdminResources::IMPORT], [], [AccessManager::UPDATE])) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$import = $this->getImport($id);
|
||||
$mode = $this->getRequest()->get("mode");
|
||||
$id = $this->getRequest()->get("id");
|
||||
$value = $this->getRequest()->get("value");
|
||||
|
||||
$this->getImport($id);
|
||||
|
||||
$event = new UpdatePositionEvent($id, $this->getMode($mode), $value);
|
||||
$this->dispatch(TheliaEvents::IMPORT_CHANGE_POSITION, $event);
|
||||
|
||||
if ($action === "up") {
|
||||
$import->upPosition();
|
||||
} elseif ($action === "down") {
|
||||
$import->downPosition();
|
||||
}
|
||||
|
||||
$this->setOrders(null, "manual");
|
||||
|
||||
return $this->render('import');
|
||||
}
|
||||
|
||||
public function updatePosition($id, $value)
|
||||
public function changeCategoryPosition()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth([AdminResources::IMPORT], [], [AccessManager::UPDATE])) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$import = $this->getImport($id);
|
||||
$mode = $this->getRequest()->get("mode");
|
||||
$id = $this->getRequest()->get("id");
|
||||
$value = $this->getRequest()->get("value");
|
||||
|
||||
$import->updatePosition($value);
|
||||
$this->getCategory($id);
|
||||
|
||||
$this->setOrders(null, "manual");
|
||||
|
||||
return $this->render('import');
|
||||
}
|
||||
|
||||
public function changeCategoryPosition($action, $id)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth([AdminResources::IMPORT], [], [AccessManager::UPDATE])) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$category = $this->getCategory($id);
|
||||
|
||||
if ($action === "up") {
|
||||
$category->upPosition();
|
||||
} elseif ($action === "down") {
|
||||
$category->downPosition();
|
||||
}
|
||||
$event = new UpdatePositionEvent($id, $this->getMode($mode), $value);
|
||||
$this->dispatch(TheliaEvents::IMPORT_CATEGORY_CHANGE_POSITION, $event);
|
||||
|
||||
$this->setOrders("manual");
|
||||
|
||||
return $this->render('import');
|
||||
}
|
||||
|
||||
public function updateCategoryPosition($id, $value)
|
||||
public function getMode($action)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth([AdminResources::IMPORT], [], [AccessManager::UPDATE])) {
|
||||
return $response;
|
||||
if ($action === "up") {
|
||||
$mode = UpdatePositionEvent::POSITION_UP;
|
||||
} elseif ($action === "down") {
|
||||
$mode = UpdatePositionEvent::POSITION_DOWN;
|
||||
} else {
|
||||
$mode = UpdatePositionEvent::POSITION_ABSOLUTE;
|
||||
}
|
||||
|
||||
$category = $this->getCategory($id);
|
||||
|
||||
$category->updatePosition($value);
|
||||
|
||||
$this->setOrders("manual");
|
||||
|
||||
return $this->render('import');
|
||||
return $mode;
|
||||
}
|
||||
|
||||
protected function getImport($id)
|
||||
|
||||
@@ -772,6 +772,12 @@ final class TheliaEvents
|
||||
const EXPORT_BEFORE_ENCODE = "Thelia.export.encode.before";
|
||||
const EXPORT_AFTER_ENCODE = "Thelia.export.encode.after";
|
||||
|
||||
const EXPORT_CATEGORY_CHANGE_POSITION = "Thelia.export.change_category_position";
|
||||
const EXPORT_CHANGE_POSITION = "Thelia.export.change_position";
|
||||
|
||||
const IMPORT_BEFORE_DECODE = "Thelia.import.decode.before";
|
||||
const IMPORT_AFTER_DECODE = "Thelia.import.decode.after";
|
||||
|
||||
const IMPORT_CATEGORY_CHANGE_POSITION = "Thelia.import.change_category_position";
|
||||
const IMPORT_CHANGE_POSITION = "Thelia.import.change_position";
|
||||
}
|
||||
|
||||
@@ -13,18 +13,14 @@
|
||||
namespace Thelia\ImportExport\Export\Type;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Propel\Runtime\ActiveQuery\Join;
|
||||
use Thelia\Model\Country;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\Lang;
|
||||
use Thelia\Model\Map\AttributeCombinationTableMap;
|
||||
use Thelia\Model\Map\CurrencyTableMap;
|
||||
use Thelia\Model\Map\ProductSaleElementsTableMap;
|
||||
use Thelia\Model\Map\ProductTableMap;
|
||||
use Thelia\Model\Map\TaxRuleI18nTableMap;
|
||||
use Thelia\Model\Map\TaxRuleTableMap;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
use Thelia\Model\TaxRuleQuery;
|
||||
use Thelia\TaxEngine\Calculator;
|
||||
|
||||
/**
|
||||
* Class ProductTaxedPricesExport
|
||||
|
||||
@@ -11,84 +11,16 @@ use Thelia\ImportExport\Export\ExportHandler;
|
||||
use Thelia\ImportExport\Export\ImagesExportInterface;
|
||||
use Thelia\Model\Base\Export as BaseExport;
|
||||
use Thelia\Model\Map\ExportTableMap;
|
||||
use Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
use Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
class Export extends BaseExport
|
||||
{
|
||||
use PositionManagementTrait;
|
||||
use ModelEventDispatcherTrait;
|
||||
|
||||
protected static $cache;
|
||||
|
||||
public function upPosition()
|
||||
{
|
||||
|
||||
if (($position = $this->getPosition()) > 1) {
|
||||
|
||||
$previous = ExportQuery::create()
|
||||
->filterByPosition($position - 1)
|
||||
->findOneByExportCategoryId($this->getExportCategoryId());
|
||||
|
||||
if (null !== $previous) {
|
||||
$previous->setPosition($position)->save();
|
||||
}
|
||||
|
||||
$this->setPosition($position - 1)->save();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function downPosition()
|
||||
{
|
||||
$max = $this->getMaxPosition();
|
||||
|
||||
$count = $this->getExportCategory()->countExports();
|
||||
|
||||
if ($count > $max) {
|
||||
$max = $count;
|
||||
}
|
||||
|
||||
$position = $this->getPosition();
|
||||
|
||||
if ($position < $max) {
|
||||
|
||||
$next = ExportQuery::create()
|
||||
->filterByPosition($position + 1)
|
||||
->findOneByExportCategoryId($this->getExportCategoryId());
|
||||
|
||||
if (null !== $next) {
|
||||
$next->setPosition($position)->save();
|
||||
}
|
||||
|
||||
$this->setPosition($position + 1)->save();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function updatePosition($position)
|
||||
{
|
||||
$reverse = ExportQuery::create()
|
||||
->findOneByPosition($position)
|
||||
;
|
||||
|
||||
if (null !== $reverse) {
|
||||
$reverse->setPosition($this->getPosition())->save();
|
||||
}
|
||||
|
||||
$this->setPosition($position)->save();
|
||||
}
|
||||
|
||||
public function setPositionToLast()
|
||||
{
|
||||
$max = $this->getMaxPosition();
|
||||
|
||||
if (null === $max) {
|
||||
$this->setPosition(1);
|
||||
} else {
|
||||
$this->setPosition($max+1);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
* @return \Thelia\ImportExport\Export\ExportHandler
|
||||
@@ -134,27 +66,6 @@ class Export extends BaseExport
|
||||
return static::$cache = $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConnectionInterface $con
|
||||
*
|
||||
* Handle the position of other exports
|
||||
*/
|
||||
public function delete(ConnectionInterface $con = null)
|
||||
{
|
||||
$imports = ExportQuery::create()
|
||||
->filterByPosition($this->getPosition(), Criteria::GREATER_THAN)
|
||||
->find()
|
||||
;
|
||||
|
||||
foreach ($imports as $import) {
|
||||
$import->setPosition($import->getPosition() - 1);
|
||||
}
|
||||
|
||||
$imports->save();
|
||||
|
||||
parent::delete($con);
|
||||
}
|
||||
|
||||
public function hasImages(ContainerInterface $container)
|
||||
{
|
||||
if (static::$cache === null) {
|
||||
@@ -173,13 +84,13 @@ class Export extends BaseExport
|
||||
return static::$cache instanceof DocumentsExportInterface;
|
||||
}
|
||||
|
||||
public function getMaxPosition()
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
return ExportQuery::create()
|
||||
->filterByExportCategoryId($this->getExportCategoryId())
|
||||
->orderByPosition(Criteria::DESC)
|
||||
->select(ExportTableMap::POSITION)
|
||||
->findOne()
|
||||
;
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,86 +6,11 @@ use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Model\Base\CategoryQuery;
|
||||
use Thelia\Model\Base\ExportCategory as BaseExportCategory;
|
||||
use Thelia\Model\Map\ExportCategoryTableMap;
|
||||
use Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
use Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
class ExportCategory extends BaseExportCategory
|
||||
{
|
||||
public function upPosition()
|
||||
{
|
||||
if (($position = $this->getPosition()) > 1) {
|
||||
|
||||
$previous = ExportCategoryQuery::create()
|
||||
->findOneByPosition($position - 1)
|
||||
;
|
||||
|
||||
if (null !== $previous) {
|
||||
$previous->setPosition($position)->save();
|
||||
}
|
||||
|
||||
$this->setPosition($position - 1)->save();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function downPosition()
|
||||
{
|
||||
$max = ExportCategoryQuery::create()
|
||||
->orderByPosition(Criteria::DESC)
|
||||
->select(ExportCategoryTableMap::POSITION)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
$count = CategoryQuery::create()->count();
|
||||
|
||||
if ($count > $max) {
|
||||
$max = $count;
|
||||
}
|
||||
|
||||
$position = $this->getPosition();
|
||||
|
||||
if ($position < $max) {
|
||||
|
||||
$next = ExportCategoryQuery::create()
|
||||
->findOneByPosition($position + 1)
|
||||
;
|
||||
|
||||
if (null !== $next) {
|
||||
$next->setPosition($position)->save();
|
||||
}
|
||||
|
||||
$this->setPosition($position + 1)->save();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function updatePosition($position)
|
||||
{
|
||||
$reverse = ExportCategoryQuery::create()
|
||||
->findOneByPosition($position)
|
||||
;
|
||||
|
||||
if (null !== $reverse) {
|
||||
$reverse->setPosition($this->getPosition())->save();
|
||||
}
|
||||
|
||||
$this->setPosition($position)->save();
|
||||
}
|
||||
|
||||
public function setPositionToLast()
|
||||
{
|
||||
$max = ExportCategoryQuery::create()
|
||||
->orderByPosition(Criteria::DESC)
|
||||
->select(ExportCategoryTableMap::POSITION)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
if (null === $max) {
|
||||
$this->setPosition(1);
|
||||
} else {
|
||||
$this->setPosition($max+1);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
use PositionManagementTrait;
|
||||
use ModelEventDispatcherTrait;
|
||||
}
|
||||
|
||||
@@ -12,81 +12,13 @@ use Thelia\Core\Translation\Translator;
|
||||
use Thelia\ImportExport\Import\ImportHandler;
|
||||
use Thelia\Model\Base\Import as BaseImport;
|
||||
use Thelia\Model\Map\ImportTableMap;
|
||||
use Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
use Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
class Import extends BaseImport
|
||||
{
|
||||
public function upPosition()
|
||||
{
|
||||
|
||||
if (($position = $this->getPosition()) > 1) {
|
||||
|
||||
$previous = ImportQuery::create()
|
||||
->filterByPosition($position - 1)
|
||||
->findOneByImportCategoryId($this->getImportCategoryId());
|
||||
|
||||
if (null !== $previous) {
|
||||
$previous->setPosition($position)->save();
|
||||
}
|
||||
|
||||
$this->setPosition($position - 1)->save();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function downPosition()
|
||||
{
|
||||
$max = $this->getMaxPosition();
|
||||
|
||||
$count = $this->getImportCategory()->countImports();
|
||||
|
||||
if ($count > $max) {
|
||||
$max = $count;
|
||||
}
|
||||
|
||||
$position = $this->getPosition();
|
||||
|
||||
if ($position < $max) {
|
||||
|
||||
$next = ImportQuery::create()
|
||||
->filterByPosition($position + 1)
|
||||
->findOneByImportCategoryId($this->getImportCategoryId());
|
||||
|
||||
if (null !== $next) {
|
||||
$next->setPosition($position)->save();
|
||||
}
|
||||
|
||||
$this->setPosition($position + 1)->save();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function updatePosition($position)
|
||||
{
|
||||
$reverse = ImportQuery::create()
|
||||
->findOneByPosition($position)
|
||||
;
|
||||
|
||||
if (null !== $reverse) {
|
||||
$reverse->setPosition($this->getPosition())->save();
|
||||
}
|
||||
|
||||
$this->setPosition($position)->save();
|
||||
}
|
||||
|
||||
public function setPositionToLast()
|
||||
{
|
||||
$max = $this->getMaxPosition();
|
||||
|
||||
if (null === $max) {
|
||||
$this->setPosition(1);
|
||||
} else {
|
||||
$this->setPosition($max+1);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
use PositionManagementTrait;
|
||||
use ModelEventDispatcherTrait;
|
||||
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
@@ -128,35 +60,4 @@ class Import extends BaseImport
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConnectionInterface $con
|
||||
*
|
||||
* Handle the position of other imports
|
||||
*/
|
||||
public function delete(ConnectionInterface $con = null)
|
||||
{
|
||||
$imports = ImportQuery::create()
|
||||
->filterByPosition($this->getPosition(), Criteria::GREATER_THAN)
|
||||
->find()
|
||||
;
|
||||
|
||||
foreach ($imports as $import) {
|
||||
$import->setPosition($import->getPosition() - 1);
|
||||
}
|
||||
|
||||
$imports->save();
|
||||
|
||||
parent::delete($con);
|
||||
}
|
||||
|
||||
public function getMaxPosition()
|
||||
{
|
||||
return ImportQuery::create()
|
||||
->filterByImportCategoryId($this->getImportCategoryId())
|
||||
->orderByPosition(Criteria::DESC)
|
||||
->select(ImportTableMap::POSITION)
|
||||
->findOne()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,86 +5,11 @@ namespace Thelia\Model;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Model\Base\ImportCategory as BaseImportCategory;
|
||||
use Thelia\Model\Map\ImportCategoryTableMap;
|
||||
use Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
use Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
class ImportCategory extends BaseImportCategory
|
||||
{
|
||||
public function upPosition()
|
||||
{
|
||||
if (($position = $this->getPosition()) > 1) {
|
||||
|
||||
$previous = ImportCategoryQuery::create()
|
||||
->findOneByPosition($position - 1)
|
||||
;
|
||||
|
||||
if (null !== $previous) {
|
||||
$previous->setPosition($position)->save();
|
||||
}
|
||||
|
||||
$this->setPosition($position - 1)->save();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function downPosition()
|
||||
{
|
||||
$max = ImportCategoryQuery::create()
|
||||
->orderByPosition(Criteria::DESC)
|
||||
->select(ImportCategoryTableMap::POSITION)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
$count = CategoryQuery::create()->count();
|
||||
|
||||
if ($count > $max) {
|
||||
$max = $count;
|
||||
}
|
||||
|
||||
$position = $this->getPosition();
|
||||
|
||||
if ($position < $max) {
|
||||
|
||||
$next = ImportCategoryQuery::create()
|
||||
->findOneByPosition($position + 1)
|
||||
;
|
||||
|
||||
if (null !== $next) {
|
||||
$next->setPosition($position)->save();
|
||||
}
|
||||
|
||||
$this->setPosition($position + 1)->save();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function updatePosition($position)
|
||||
{
|
||||
$reverse = ImportCategoryQuery::create()
|
||||
->findOneByPosition($position)
|
||||
;
|
||||
|
||||
if (null !== $reverse) {
|
||||
$reverse->setPosition($this->getPosition())->save();
|
||||
}
|
||||
|
||||
$this->setPosition($position)->save();
|
||||
}
|
||||
|
||||
public function setPositionToLast()
|
||||
{
|
||||
$max = ImportCategoryQuery::create()
|
||||
->orderByPosition(Criteria::DESC)
|
||||
->select(ImportCategoryTableMap::POSITION)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
if (null === $max) {
|
||||
$this->setPosition(1);
|
||||
} else {
|
||||
$this->setPosition($max+1);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
use PositionManagementTrait;
|
||||
use ModelEventDispatcherTrait;
|
||||
}
|
||||
|
||||
@@ -38,16 +38,18 @@
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="general-block-decorator">
|
||||
<div class="table-responsive" id="category_{$category_title}">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-condensed table-left-aligned">
|
||||
<caption class="clearfix">
|
||||
<a href="{url path="/admin/export/position/category/up/{$ID}{if $url_export}?{$url_export}{/if}#category_{$category_title}"}">
|
||||
<span class="glyphicon glyphicon-arrow-up"></span>
|
||||
</a>
|
||||
{$POSITION}
|
||||
<a href="{url path="/admin/export/position/category/down/{$ID}{if $url_export}?{$url_export}{/if}#category_{$category_title}"}">
|
||||
<span class="glyphicon glyphicon-arrow-down"></span>
|
||||
</a>
|
||||
{admin_position_block
|
||||
resource="admin.export"
|
||||
access="UPDATE"
|
||||
path={url path="admin/export/position/category"}
|
||||
url_parameter="id"
|
||||
in_place_edit_class="exportCategoryPositionChange"
|
||||
position=$POSITION
|
||||
id=$ID
|
||||
}
|
||||
{$TITLE}
|
||||
</caption>
|
||||
<thead>
|
||||
@@ -103,13 +105,15 @@
|
||||
{$DESCRIPTION nofilter}
|
||||
</td>
|
||||
<td>
|
||||
<a href="{url path="/admin/export/position/up/{if $url_category}?{$url_category}{/if}{$ID}#category_{$category_title}"}">
|
||||
<span class="glyphicon glyphicon-arrow-up"></span>
|
||||
</a>
|
||||
{$POSITION}
|
||||
<a href="{url path="/admin/export/position/down/{$ID}{if $url_category}?{$url_category}{/if}#category_{$category_title}"}">
|
||||
<span class="glyphicon glyphicon-arrow-down"></span>
|
||||
</a>
|
||||
{admin_position_block
|
||||
resource="admin.export"
|
||||
access="UPDATE"
|
||||
path={url path="admin/export/position"}
|
||||
url_parameter="id"
|
||||
in_place_edit_class="exportPositionChange"
|
||||
position=$POSITION
|
||||
id=$ID
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group">
|
||||
@@ -144,12 +148,55 @@
|
||||
{javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'}
|
||||
<script src="{$asset_url}"></script>
|
||||
{/javascripts}
|
||||
|
||||
{javascripts file='assets/js/bootstrap-editable/bootstrap-editable.js'}
|
||||
<script src="{$asset_url}"></script>
|
||||
{/javascripts}
|
||||
|
||||
{/block}
|
||||
|
||||
{block name="javascript-last-call"}
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
|
||||
$('.exportPositionChange').editable({
|
||||
type : 'text',
|
||||
title : "{intl l="Enter new export position"}",
|
||||
mode : 'popup',
|
||||
inputclass : 'input-mini',
|
||||
placement : 'left',
|
||||
success : function(response, newValue) {
|
||||
// The URL template
|
||||
var url = "{url noamp='1' path='/admin/export/position' id='__ID__' value='__POS__'}";
|
||||
|
||||
// Perform subtitutions
|
||||
url = url.replace('__ID__', $(this).data('id'))
|
||||
.replace('__POS__', newValue);
|
||||
|
||||
// Reload the page
|
||||
location.href = url;
|
||||
}
|
||||
});
|
||||
|
||||
$('.exportCategoryPositionChange').editable({
|
||||
type : 'text',
|
||||
title : "{intl l="Enter new export category position"}",
|
||||
mode : 'popup',
|
||||
inputclass : 'input-mini',
|
||||
placement : 'left',
|
||||
success : function(response, newValue) {
|
||||
// The URL template
|
||||
var url = "{url noamp='1' path='/admin/export/position/category' id='__ID__' value='__POS__'}";
|
||||
|
||||
// Perform subtitutions
|
||||
url = url.replace('__ID__', $(this).data('id'))
|
||||
.replace('__POS__', newValue);
|
||||
|
||||
// Reload the page
|
||||
location.href = url;
|
||||
}
|
||||
});
|
||||
|
||||
var export_modal = $("#export-modal");
|
||||
|
||||
$(".btn-show-export-modal").click(function() {
|
||||
|
||||
Reference in New Issue
Block a user