implement process for changing folder position

This commit is contained in:
Manuel Raynaud
2013-09-20 20:38:39 +02:00
parent abac607534
commit cc2a3914a9
3 changed files with 61 additions and 1 deletions

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Event\FolderDeleteEvent;
use Thelia\Core\Event\FolderToggleVisibilityEvent;
use Thelia\Core\Event\FolderUpdateEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Model\FolderQuery;
use Thelia\Model\Folder as FolderModel;
@@ -100,6 +101,26 @@ class Folder extends BaseAction implements EventSubscriberInterface {
}
public function updatePosition(UpdatePositionEvent $event)
{
if(null !== $folder = FolderQuery::create()->findPk($event->getObjectId())) {
$folder->setDispatcher($this->getDispatcher());
switch($event->getMode())
{
case UpdatePositionEvent::POSITION_ABSOLUTE:
$folder->changeAbsolutePosition($event->getPosition());
break;
case UpdatePositionEvent::POSITION_DOWN:
$folder->movePositionDown();
break;
case UpdatePositionEvent::POSITION_UP:
$folder->movePositionUp();
break;
}
}
}
/**
* Returns an array of event names this subscriber wants to listen to.
*

View File

@@ -216,6 +216,10 @@
<default key="_controller">Thelia\Controller\Admin\FolderController::deleteAction</default>
</route>
<route id="admin.folders.update-position" path="/admin/folders/update-position">
<default key="_controller">Thelia\Controller\Admin\FolderController::updatePositionAction</default>
</route>
<!-- Route to the Coupon controller (process Coupon browsing) -->
<route id="admin.coupon.list" path="/admin/coupon/">

View File

@@ -27,6 +27,7 @@ use Thelia\Core\Event\FolderDeleteEvent;
use Thelia\Core\Event\FolderToggleVisibilityEvent;
use Thelia\Core\Event\FolderUpdateEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Form\FolderCreationForm;
use Thelia\Form\FolderModificationForm;
use Thelia\Model\FolderQuery;
@@ -149,13 +150,27 @@ class FolderController extends AbstractCrudController
}
/**
*
* @return FolderToggleVisibilityEvent|void
*/
protected function createToggleVisibilityEvent()
{
return new FolderToggleVisibilityEvent($this->getExistingObject());
}
/**
* @param $positionChangeMode
* @param $positionValue
* @return UpdatePositionEvent|void
*/
protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
return new UpdatePositionEvent(
$this->getRequest()->get('folder_id', null),
$positionChangeMode,
$positionValue
);
}
/**
* Return true if the event contains the object, e.g. the action has updated the object in the event.
*
@@ -272,6 +287,26 @@ class FolderController extends AbstractCrudController
);
}
/**
* @param $event \Thelia\Core\Event\UpdatePositionEvent
* @return null|Response
*/
protected function performAdditionalUpdatePositionAction($event)
{
$folder = FolderQuery::create()->findPk($event->getObjectId());
if ($folder != null) {
// Redirect to parent category list
$this->redirectToRoute(
'admin.folders.default',
array('folder_id' => $folder->getParent())
);
}
return null;
}
/**
* Redirect to the edition template
*/