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 -->
|
<!-- export management -->
|
||||||
|
|
||||||
<route id="export.generic" path="/admin/export/{key}">
|
<route id="export.list" path="/admin/export">
|
||||||
<default key="_controller">Thelia\Controller\Admin\ImportExportController::export</default>
|
<default key="_controller">Thelia\Controller\Admin\ExportController::indexAction</default>
|
||||||
<requirement key="key">\d+</requirement>
|
|
||||||
</route>
|
</route>
|
||||||
|
|
||||||
<route id="import.generic" path="/admin/import/{key}">
|
<route id="export.position" path="/admin/export/position/{action}/{id}">
|
||||||
<default key="_controller">Thelia\Controller\Admin\ImportExportController::import</default>
|
<default key="_controller">Thelia\Controller\Admin\ExportController::changePosition</default>
|
||||||
<requirement key="key">\d+</requirement>
|
<requirement key="action">up|down</requirement>
|
||||||
|
<requirement key="id">\d+</requirement>
|
||||||
</route>
|
</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 -->
|
<!-- Routes to the Brands controller -->
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ namespace Thelia\Controller\Admin;
|
|||||||
|
|
||||||
use Thelia\Core\Security\AccessManager;
|
use Thelia\Core\Security\AccessManager;
|
||||||
use Thelia\Core\Security\Resource\AdminResources;
|
use Thelia\Core\Security\Resource\AdminResources;
|
||||||
|
use Thelia\Core\Template\Loop\ImportExportType;
|
||||||
|
use Thelia\Core\Translation\Translator;
|
||||||
|
use Thelia\Model\ExportQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ExportController
|
* Class ExportController
|
||||||
@@ -22,18 +25,78 @@ use Thelia\Core\Security\Resource\AdminResources;
|
|||||||
*/
|
*/
|
||||||
class ExportController extends BaseAdminController
|
class ExportController extends BaseAdminController
|
||||||
{
|
{
|
||||||
|
|
||||||
public function indexAction()
|
public function indexAction()
|
||||||
{
|
{
|
||||||
if (null !== $response = $this->checkAuth([AdminResources::EXPORT], [], [AccessManager::VIEW])) {
|
if (null !== $response = $this->checkAuth([AdminResources::EXPORT], [], [AccessManager::VIEW])) {
|
||||||
return $response;
|
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');
|
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;
|
namespace Thelia\Controller\Admin;
|
||||||
|
use Thelia\Core\HttpFoundation\Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ImportExportController
|
* 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
|
abstract class ImportExportType extends BaseLoop implements PropelSearchLoopInterface
|
||||||
{
|
{
|
||||||
|
const DEFAULT_ORDER = "manual";
|
||||||
|
|
||||||
protected $timestampable = true;
|
protected $timestampable = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,9 +51,9 @@ abstract class ImportExportType extends BaseLoop implements PropelSearchLoopInte
|
|||||||
->set("ID", $type->getId())
|
->set("ID", $type->getId())
|
||||||
->set("TITLE", $type->getTitle())
|
->set("TITLE", $type->getTitle())
|
||||||
->set("DESCRIPTION", $type->getDescription())
|
->set("DESCRIPTION", $type->getDescription())
|
||||||
->set("URL", $type->isImport() ? $url : null)
|
->set("URL", $url)
|
||||||
->set("POSITION", $type->getPosition())
|
->set("POSITION", $type->getPosition())
|
||||||
->set("CATEGORY_ID", $type->getImportExportCategoryId())
|
->set("CATEGORY_ID", $type->getByName($this->getCategoryName()))
|
||||||
;
|
;
|
||||||
|
|
||||||
$loopResult->addRow($loopResultRow);
|
$loopResult->addRow($loopResultRow);
|
||||||
@@ -137,13 +139,18 @@ abstract class ImportExportType extends BaseLoop implements PropelSearchLoopInte
|
|||||||
new Argument(
|
new Argument(
|
||||||
"order",
|
"order",
|
||||||
new TypeCollection(
|
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 getBaseUrl();
|
||||||
|
|
||||||
abstract protected function getQueryModel();
|
abstract protected function getQueryModel();
|
||||||
|
|||||||
@@ -2,9 +2,72 @@
|
|||||||
|
|
||||||
namespace Thelia\Model;
|
namespace Thelia\Model;
|
||||||
|
|
||||||
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
use Thelia\Model\Base\Export as BaseExport;
|
use Thelia\Model\Base\Export as BaseExport;
|
||||||
|
use Thelia\Model\Map\ExportTableMap;
|
||||||
|
|
||||||
class Export extends BaseExport
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
0
templates/backOffice/default/export-page.html
Normal file
0
templates/backOffice/default/export-page.html
Normal file
@@ -42,18 +42,41 @@
|
|||||||
</caption>
|
</caption>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="col-md-10">
|
<th class="col-md-1">
|
||||||
{intl l="Name"}
|
<a href="{url path="/admin/export"}?export_order=id{if $export_order == "id"}_reverse{/if}">
|
||||||
|
{intl l="ID"}
|
||||||
|
</a>
|
||||||
|
</th>
|
||||||
|
<th class="col-md-9">
|
||||||
|
<a href="{url path="/admin/export"}?export_order=alpha{if $export_order == "alpha"}_reverse{/if}">
|
||||||
|
{intl l="Name"}
|
||||||
|
</a>
|
||||||
</th>
|
</th>
|
||||||
<th class="col-md-2">
|
<th class="col-md-2">
|
||||||
{intl l="Position"}
|
<a href="{url path="/admin/export"}?export_order=manual{if $export_order == "manual"}_reverse{/if}">
|
||||||
|
{intl l="Position"}
|
||||||
|
</a>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{loop name="export-categ-list" type="export" category=$ID}
|
{loop name="export-categ-list" type="export" order=$export_order category=$ID}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{$URL}">{$TITLE}</a></td>
|
<td>
|
||||||
|
{$ID}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="{$URL}">{$TITLE}</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="{url path="/admin/export"}/position/up/{$ID}">
|
||||||
|
<span class="glyphicon glyphicon-arrow-up"></span>
|
||||||
|
</a>
|
||||||
|
{$POSITION}
|
||||||
|
<a href="{url path="/admin/export/position/down"}/{$ID}">
|
||||||
|
<span class="glyphicon glyphicon-arrow-down"></span>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/loop}
|
{/loop}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
0
templates/backOffice/default/import-page.html
Normal file
0
templates/backOffice/default/import-page.html
Normal file
Reference in New Issue
Block a user