From 396bafd7a954e574313e3f3c47f55d8add486822 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 1 Aug 2014 12:25:51 +0200 Subject: [PATCH] =?UTF-8?q?Refactor=20position=20management=20with=20trait?= =?UTF-8?q?=20=09nouveau=20fichier:=20core/lib/Thelia/Action/Export.php=20?= =?UTF-8?q?=09nouveau=20fichier:=20core/lib/Thelia/Action/Import.php=20=09?= =?UTF-8?q?modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Config/?= =?UTF-8?q?Resources/action.xml=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20core/lib/Thelia/Config/Resources/routing/admin.xml=20=09modi?= =?UTF-8?q?fi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Controller/?= =?UTF-8?q?Admin/ExportController.php=20=09modifi=C3=A9:=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20core/lib/Thelia/Controller/Admin/ImportController.php?= =?UTF-8?q?=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/C?= =?UTF-8?q?ore/Event/TheliaEvents.php=20=09modifi=C3=A9:=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20core/lib/Thelia/ImportExport/Export/Type/ProductTaxedP?= =?UTF-8?q?ricesExport.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20co?= =?UTF-8?q?re/lib/Thelia/Model/Export.php=20=09modifi=C3=A9:=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20core/lib/Thelia/Model/ExportCategory.php=20=09mo?= =?UTF-8?q?difi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Model/Imp?= =?UTF-8?q?ort.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/T?= =?UTF-8?q?helia/Model/ImportCategory.php=20=09modifi=C3=A9:=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20templates/backOffice/default/export.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Thelia/Action/Export.php | 91 +++++++++++++ core/lib/Thelia/Action/Import.php | 91 +++++++++++++ core/lib/Thelia/Config/Resources/action.xml | 10 ++ .../Thelia/Config/Resources/routing/admin.xml | 128 +++++++----------- .../Controller/Admin/ExportController.php | 62 ++++----- .../Controller/Admin/ImportController.php | 63 ++++----- core/lib/Thelia/Core/Event/TheliaEvents.php | 6 + .../Export/Type/ProductTaxedPricesExport.php | 4 - core/lib/Thelia/Model/Export.php | 113 ++-------------- core/lib/Thelia/Model/ExportCategory.php | 83 +----------- core/lib/Thelia/Model/Import.php | 107 +-------------- core/lib/Thelia/Model/ImportCategory.php | 83 +----------- templates/backOffice/default/export.html | 77 +++++++++-- 13 files changed, 379 insertions(+), 539 deletions(-) create mode 100644 core/lib/Thelia/Action/Export.php create mode 100644 core/lib/Thelia/Action/Import.php diff --git a/core/lib/Thelia/Action/Export.php b/core/lib/Thelia/Action/Export.php new file mode 100644 index 000000000..138c594d6 --- /dev/null +++ b/core/lib/Thelia/Action/Export.php @@ -0,0 +1,91 @@ + + */ +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), + ); + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Action/Import.php b/core/lib/Thelia/Action/Import.php new file mode 100644 index 000000000..57f82336c --- /dev/null +++ b/core/lib/Thelia/Action/Import.php @@ -0,0 +1,91 @@ + + */ +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), + ); + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index f8ea66a4f..62e017195 100644 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -163,6 +163,16 @@ + + + + + + + + + + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 4459a43f5..a2a4b7838 100644 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -1158,86 +1158,6 @@ Thelia\Controller\Admin\TranslationsController::updateAction - - - - Thelia\Controller\Admin\ExportController::indexAction - - - - Thelia\Controller\Admin\ExportController::changePosition - up|down - \d+ - - - - Thelia\Controller\Admin\ExportController::updatePosition - \d+ - \d+ - - - - Thelia\Controller\Admin\ExportController::changeCategoryPosition - up|down - \d+ - - - - Thelia\Controller\Admin\ExportController::updateCategoryPosition - \d+ - \d+ - - - - Thelia\Controller\Admin\ExportController::export - \d+ - - - - Thelia\Controller\Admin\ExportController::exportView - \d+ - - - - - - Thelia\Controller\Admin\ImportController::indexAction - - - - Thelia\Controller\Admin\ImportController::changePosition - up|down - \d+ - - - - Thelia\Controller\Admin\ImportController::updatePosition - \d+ - \d+ - - - - Thelia\Controller\Admin\ImportController::changeCategoryPosition - up|down - \d+ - - - - Thelia\Controller\Admin\ImportController::updateCategoryPosition - \d+ - \d+ - - - - Thelia\Controller\Admin\ImportController::import - \d+ - - - - Thelia\Controller\Admin\ImportController::importView - \d+ - - @@ -1274,6 +1194,54 @@ Thelia\Controller\Admin\BrandController::deleteAction + + + + Thelia\Controller\Admin\ExportController::indexAction + + + + Thelia\Controller\Admin\ExportController::changePosition + + + + Thelia\Controller\Admin\ExportController::changeCategoryPosition + + + + Thelia\Controller\Admin\ExportController::export + \d+ + + + + Thelia\Controller\Admin\ExportController::exportView + \d+ + + + + + + Thelia\Controller\Admin\ImportController::indexAction + + + + Thelia\Controller\Admin\ImportController::changePosition + + + + Thelia\Controller\Admin\ImportController::changeCategoryPosition + + + + Thelia\Controller\Admin\ImportController::import + \d+ + + + + Thelia\Controller\Admin\ImportController::importView + \d+ + + diff --git a/core/lib/Thelia/Controller/Admin/ExportController.php b/core/lib/Thelia/Controller/Admin/ExportController.php index 959cce38a..bf9c6bb55 100644 --- a/core/lib/Thelia/Controller/Admin/ExportController.php +++ b/core/lib/Thelia/Controller/Admin/ExportController.php @@ -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) diff --git a/core/lib/Thelia/Controller/Admin/ImportController.php b/core/lib/Thelia/Controller/Admin/ImportController.php index 96ec4ed85..c824b0e0e 100644 --- a/core/lib/Thelia/Controller/Admin/ImportController.php +++ b/core/lib/Thelia/Controller/Admin/ImportController.php @@ -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"); - if ($action === "up") { - $import->upPosition(); - } elseif ($action === "down") { - $import->downPosition(); - } + $this->getImport($id); - $this->setOrders(null, "manual"); + $event = new UpdatePositionEvent($id, $this->getMode($mode), $value); + $this->dispatch(TheliaEvents::IMPORT_CHANGE_POSITION, $event); - 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) diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index ef86b62c6..3fdb34512 100644 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -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"; } diff --git a/core/lib/Thelia/ImportExport/Export/Type/ProductTaxedPricesExport.php b/core/lib/Thelia/ImportExport/Export/Type/ProductTaxedPricesExport.php index fe1346dec..953635c54 100644 --- a/core/lib/Thelia/ImportExport/Export/Type/ProductTaxedPricesExport.php +++ b/core/lib/Thelia/ImportExport/Export/Type/ProductTaxedPricesExport.php @@ -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 diff --git a/core/lib/Thelia/Model/Export.php b/core/lib/Thelia/Model/Export.php index a5fe33d2b..879baf60b 100644 --- a/core/lib/Thelia/Model/Export.php +++ b/core/lib/Thelia/Model/Export.php @@ -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; } } diff --git a/core/lib/Thelia/Model/ExportCategory.php b/core/lib/Thelia/Model/ExportCategory.php index 44f8dce9a..00f7c53bf 100644 --- a/core/lib/Thelia/Model/ExportCategory.php +++ b/core/lib/Thelia/Model/ExportCategory.php @@ -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; } diff --git a/core/lib/Thelia/Model/Import.php b/core/lib/Thelia/Model/Import.php index 250e9cce6..1a26fc18b 100644 --- a/core/lib/Thelia/Model/Import.php +++ b/core/lib/Thelia/Model/Import.php @@ -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() - ; - } } diff --git a/core/lib/Thelia/Model/ImportCategory.php b/core/lib/Thelia/Model/ImportCategory.php index 9d079c84e..f630c624c 100644 --- a/core/lib/Thelia/Model/ImportCategory.php +++ b/core/lib/Thelia/Model/ImportCategory.php @@ -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; } diff --git a/templates/backOffice/default/export.html b/templates/backOffice/default/export.html index 03f905564..47bc6c0f8 100644 --- a/templates/backOffice/default/export.html +++ b/templates/backOffice/default/export.html @@ -38,16 +38,18 @@
-
+
@@ -103,13 +105,15 @@ {$DESCRIPTION nofilter}
- - - - {$POSITION} - - - + {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}
- - - - {$POSITION} - - - + {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 + }
@@ -144,12 +148,55 @@ {javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'} {/javascripts} + + {javascripts file='assets/js/bootstrap-editable/bootstrap-editable.js'} + + {/javascripts} + {/block} {block name="javascript-last-call"}