Export positions
modifié: core/lib/Thelia/Config/Resources/routing/admin.xml modifié: core/lib/Thelia/Controller/Admin/ExportController.php modifié: core/lib/Thelia/Controller/Admin/ImportExportController.php modifié: core/lib/Thelia/Core/Template/Loop/ImportExportType.php modifié: core/lib/Thelia/Model/Export.php nouveau fichier: templates/backOffice/default/export-page.html modifié: templates/backOffice/default/export.html nouveau fichier: templates/backOffice/default/import-page.html
This commit is contained in:
@@ -1160,16 +1160,44 @@
|
||||
|
||||
<!-- export management -->
|
||||
|
||||
<route id="export.generic" path="/admin/export/{key}">
|
||||
<default key="_controller">Thelia\Controller\Admin\ImportExportController::export</default>
|
||||
<requirement key="key">\d+</requirement>
|
||||
<route id="export.list" path="/admin/export">
|
||||
<default key="_controller">Thelia\Controller\Admin\ExportController::indexAction</default>
|
||||
</route>
|
||||
|
||||
<route id="import.generic" path="/admin/import/{key}">
|
||||
<default key="_controller">Thelia\Controller\Admin\ImportExportController::import</default>
|
||||
<requirement key="key">\d+</requirement>
|
||||
<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.action" path="/admin/export/{id}" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Admin\ImportExportController::export</default>
|
||||
<requirement key="id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="export.view" path="/admin/export/{id}" methods="get">
|
||||
<default key="_controller">Thelia\Controller\Admin\ImportExportController::exportView</default>
|
||||
<requirement key="id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="import.action" path="/admin/import/{id}" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Admin\ImportExportController::import</default>
|
||||
<requirement key="id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
<route id="import.view" path="/admin/import/{id}" methods="get">
|
||||
<default key="_controller">Thelia\Controller\Admin\ImportExportController::importView</default>
|
||||
<requirement key="id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Routes to the Brands controller -->
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user