diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 31823709f..52d4d6ca3 100644 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -1160,16 +1160,44 @@ - - Thelia\Controller\Admin\ImportExportController::export - \d+ + + Thelia\Controller\Admin\ExportController::indexAction - - Thelia\Controller\Admin\ImportExportController::import - \d+ + + Thelia\Controller\Admin\ExportController::changePosition + up|down + \d+ + + Thelia\Controller\Admin\ExportController::updatePosition + \d+ + \d+ + + + + Thelia\Controller\Admin\ImportExportController::export + \d+ + + + + Thelia\Controller\Admin\ImportExportController::exportView + \d+ + + + + Thelia\Controller\Admin\ImportExportController::import + \d+ + + + + Thelia\Controller\Admin\ImportExportController::importView + \d+ + + + + diff --git a/core/lib/Thelia/Controller/Admin/ExportController.php b/core/lib/Thelia/Controller/Admin/ExportController.php index 90c79dc23..69832b9e8 100644 --- a/core/lib/Thelia/Controller/Admin/ExportController.php +++ b/core/lib/Thelia/Controller/Admin/ExportController.php @@ -14,6 +14,9 @@ namespace Thelia\Controller\Admin; use Thelia\Core\Security\AccessManager; use Thelia\Core\Security\Resource\AdminResources; +use Thelia\Core\Template\Loop\ImportExportType; +use Thelia\Core\Translation\Translator; +use Thelia\Model\ExportQuery; /** * Class ExportController @@ -22,18 +25,78 @@ use Thelia\Core\Security\Resource\AdminResources; */ class ExportController extends BaseAdminController { - public function indexAction() { if (null !== $response = $this->checkAuth([AdminResources::EXPORT], [], [AccessManager::VIEW])) { return $response; } + $export_order = $this->getRequest()->query->get("export_order"); + + if (!in_array($export_order, ImportExportType::getAllowedOrders())) { + $export_order = ImportExportType::DEFAULT_ORDER; + } + + $this->getParserContext() + ->set("export_order", $export_order) + ; + return $this->render('export'); } - public function export($exportType) + public function changePosition($action, $id) { + if (null !== $response = $this->checkAuth([AdminResources::EXPORT], [], [AccessManager::UPDATE])) { + return $response; + } + $export = $this->getExport($id); + + if ($action === "up") { + $export->upPosition(); + } elseif ($action === "down") { + $export->downPosition(); + } + + $this->getParserContext() + ->set("export_order", "manual") + ; + + return $this->render('export'); + } + + public function updatePosition($id, $value) + { + if (null !== $response = $this->checkAuth([AdminResources::EXPORT], [], [AccessManager::UPDATE])) { + return $response; + } + + $export = $this->getExport($id); + + $export->updatePosition($value); + + $this->getParserContext() + ->set("export_order", "manual") + ; + + return $this->render('export'); + } + + + protected function getExport($id) + { + $export = ExportQuery::create()->findPk($id); + + if (null === $export) { + throw new \ErrorException( + Translator::getInstance()->trans( + "There is no id \"%id\" in the exports", + [ + "%id" => $id + ] + ) + ); + } + return $export; } } diff --git a/core/lib/Thelia/Controller/Admin/ImportExportController.php b/core/lib/Thelia/Controller/Admin/ImportExportController.php index 4e35fa0bf..4226ef0e4 100644 --- a/core/lib/Thelia/Controller/Admin/ImportExportController.php +++ b/core/lib/Thelia/Controller/Admin/ImportExportController.php @@ -11,6 +11,7 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; +use Thelia\Core\HttpFoundation\Response; /** * Class ImportExportController @@ -28,4 +29,14 @@ class ImportExportController extends BaseAdminController { } + + public function importView() + { + return $this->render("import-page"); + } + + public function exportView() + { + return $this->render("export-page"); + } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Loop/ImportExportType.php b/core/lib/Thelia/Core/Template/Loop/ImportExportType.php index ae02e6854..13ecf422d 100644 --- a/core/lib/Thelia/Core/Template/Loop/ImportExportType.php +++ b/core/lib/Thelia/Core/Template/Loop/ImportExportType.php @@ -29,6 +29,8 @@ use Thelia\Type\TypeCollection; */ abstract class ImportExportType extends BaseLoop implements PropelSearchLoopInterface { + const DEFAULT_ORDER = "manual"; + protected $timestampable = true; /** @@ -49,9 +51,9 @@ abstract class ImportExportType extends BaseLoop implements PropelSearchLoopInte ->set("ID", $type->getId()) ->set("TITLE", $type->getTitle()) ->set("DESCRIPTION", $type->getDescription()) - ->set("URL", $type->isImport() ? $url : null) + ->set("URL", $url) ->set("POSITION", $type->getPosition()) - ->set("CATEGORY_ID", $type->getImportExportCategoryId()) + ->set("CATEGORY_ID", $type->getByName($this->getCategoryName())) ; $loopResult->addRow($loopResultRow); @@ -137,13 +139,18 @@ abstract class ImportExportType extends BaseLoop implements PropelSearchLoopInte new Argument( "order", new TypeCollection( - new EnumListType(["id", "id_reverse", "alpha", "alpha_reverse", "manual", "manual_reverse"]) + new EnumListType(static::getAllowedOrders()) ), - "manual" + static::DEFAULT_ORDER ) ); } + public static function getAllowedOrders() + { + return ["id", "id_reverse", "alpha", "alpha_reverse", "manual", "manual_reverse"]; + } + abstract protected function getBaseUrl(); abstract protected function getQueryModel(); diff --git a/core/lib/Thelia/Model/Export.php b/core/lib/Thelia/Model/Export.php index 1f1d5e100..1abef0932 100644 --- a/core/lib/Thelia/Model/Export.php +++ b/core/lib/Thelia/Model/Export.php @@ -2,9 +2,72 @@ namespace Thelia\Model; +use Propel\Runtime\ActiveQuery\Criteria; use Thelia\Model\Base\Export as BaseExport; +use Thelia\Model\Map\ExportTableMap; class Export extends BaseExport { + 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 = ExportQuery::create() + ->orderByPosition(Criteria::DESC) + ->select(ExportTableMap::POSITION) + ->findOne() + ; + + $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(); + } } diff --git a/templates/backOffice/default/export-page.html b/templates/backOffice/default/export-page.html new file mode 100644 index 000000000..e69de29bb diff --git a/templates/backOffice/default/export.html b/templates/backOffice/default/export.html index e1a1b0b87..889e74449 100644 --- a/templates/backOffice/default/export.html +++ b/templates/backOffice/default/export.html @@ -42,18 +42,41 @@ - - {intl l="Name"} + + + {intl l="ID"} + + + + + {intl l="Name"} + - {intl l="Position"} + + {intl l="Position"} + - {loop name="export-categ-list" type="export" category=$ID} + {loop name="export-categ-list" type="export" order=$export_order category=$ID} - {$TITLE} + + {$ID} + + + {$TITLE} + + + + + + {$POSITION} + + + + {/loop} diff --git a/templates/backOffice/default/import-page.html b/templates/backOffice/default/import-page.html new file mode 100644 index 000000000..e69de29bb