document positioning
This commit is contained in:
@@ -28,6 +28,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\Document\DocumentCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Document\DocumentDeleteEvent;
|
||||
use Thelia\Core\Event\Document\DocumentEvent;
|
||||
use Thelia\Core\Event\UpdateFilePositionEvent;
|
||||
use Thelia\Exception\ImageException;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Tools\FileManager;
|
||||
@@ -195,6 +196,11 @@ class Document extends BaseCachedFile implements EventSubscriberInterface
|
||||
$event->setModelDocument($event->getModelDocument());
|
||||
}
|
||||
|
||||
public function updatePosition(UpdateFilePositionEvent $event)
|
||||
{
|
||||
return $this->genericUpdatePosition($event->getQuery(), $event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take care of deleting document in the database and file storage
|
||||
*
|
||||
@@ -218,6 +224,7 @@ class Document extends BaseCachedFile implements EventSubscriberInterface
|
||||
TheliaEvents::DOCUMENT_DELETE => array("deleteDocument", 128),
|
||||
TheliaEvents::DOCUMENT_SAVE => array("saveDocument", 128),
|
||||
TheliaEvents::DOCUMENT_UPDATE => array("updateDocument", 128),
|
||||
TheliaEvents::DOCUMENT_UPDATE_POSITION => array("updatePosition", 128),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\Image\ImageCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Image\ImageDeleteEvent;
|
||||
use Thelia\Core\Event\Image\ImageEvent;
|
||||
use Thelia\Core\Event\UpdateImagePositionEvent;
|
||||
use Thelia\Core\Event\UpdateFilePositionEvent;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Tools\FileManager;
|
||||
use Thelia\Tools\URL;
|
||||
@@ -302,7 +302,7 @@ class Image extends BaseCachedFile implements EventSubscriberInterface
|
||||
$event->setModelImage($event->getModelImage());
|
||||
}
|
||||
|
||||
public function updatePosition(UpdateImagePositionEvent $event)
|
||||
public function updatePosition(UpdateFilePositionEvent $event)
|
||||
{
|
||||
return $this->genericUpdatePosition($event->getQuery(), $event);
|
||||
}
|
||||
|
||||
@@ -95,6 +95,11 @@
|
||||
<requirement key="parentType">.*</requirement>
|
||||
<requirement key="parentId">\d+</requirement>
|
||||
</route>
|
||||
<route id="admin.document.update-position" path="/admin/document/type/{parentType}/{parentId}/update-position">
|
||||
<default key="_controller">Thelia\Controller\Admin\FileController::updateDocumentPositionAction</default>
|
||||
<requirement key="parentType">.*</requirement>
|
||||
<requirement key="parentId">\d+</requirement>
|
||||
</route>
|
||||
<route id="admin.document.update.view" path="/admin/document/type/{parentType}/{documentId}/update" methods="get">
|
||||
<default key="_controller">Thelia\Controller\Admin\FileController::viewDocumentAction</default>
|
||||
<requirement key="parentType">.*</requirement>
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Thelia\Controller\Admin;
|
||||
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Thelia\Core\Event\UpdateImagePositionEvent;
|
||||
use Thelia\Core\Event\UpdateFilePositionEvent;
|
||||
use Thelia\Core\HttpFoundation\Response;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Event\Document\DocumentCreateOrUpdateEvent;
|
||||
@@ -615,10 +615,10 @@ class FileController extends BaseAdminController
|
||||
}
|
||||
|
||||
// Feed event
|
||||
$imageUpdateImagePositionEvent = new UpdateImagePositionEvent(
|
||||
$imageUpdateImagePositionEvent = new UpdateFilePositionEvent(
|
||||
$fileManager->getImageModelQuery($parentType),
|
||||
$imageId,
|
||||
UpdateImagePositionEvent::POSITION_ABSOLUTE,
|
||||
UpdateFilePositionEvent::POSITION_ABSOLUTE,
|
||||
$position
|
||||
);
|
||||
|
||||
@@ -650,6 +650,60 @@ class FileController extends BaseAdminController
|
||||
return new Response($message);
|
||||
}
|
||||
|
||||
public function updateDocumentPositionAction($parentType, $parentId)
|
||||
{
|
||||
$message = null;
|
||||
|
||||
$documentId = $this->getRequest()->request->get('document_id');
|
||||
$position = $this->getRequest()->request->get('position');
|
||||
|
||||
$this->checkAuth(AdminResources::retrieve($parentType), array(), AccessManager::UPDATE);
|
||||
$this->checkXmlHttpRequest();
|
||||
|
||||
$fileManager = new FileManager($this->container);
|
||||
$documentModelQuery = $fileManager->getDocumentModelQuery($parentType);
|
||||
$model = $documentModelQuery->findPk($documentId);
|
||||
|
||||
if ($model === null || $position === null) {
|
||||
return $this->pageNotFound();
|
||||
}
|
||||
|
||||
// Feed event
|
||||
$documentUpdateDocumentPositionEvent = new UpdateFilePositionEvent(
|
||||
$fileManager->getDocumentModelQuery($parentType),
|
||||
$documentId,
|
||||
UpdateFilePositionEvent::POSITION_ABSOLUTE,
|
||||
$position
|
||||
);
|
||||
|
||||
// Dispatch Event to the Action
|
||||
try {
|
||||
$this->dispatch(
|
||||
TheliaEvents::DOCUMENT_UPDATE_POSITION,
|
||||
$documentUpdateDocumentPositionEvent
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
$message = $this->getTranslator()
|
||||
->trans(
|
||||
'Fail to update document position',
|
||||
array(),
|
||||
'document'
|
||||
) . $e->getMessage();
|
||||
}
|
||||
|
||||
if(null === $message) {
|
||||
$message = $this->getTranslator()
|
||||
->trans(
|
||||
'Document position updated',
|
||||
array(),
|
||||
'document'
|
||||
);
|
||||
}
|
||||
|
||||
return new Response($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage how a document has to be deleted (AJAX)
|
||||
*
|
||||
|
||||
@@ -404,6 +404,7 @@ final class TheliaEvents
|
||||
* Save given documents
|
||||
*/
|
||||
const DOCUMENT_UPDATE = "action.updateDocument";
|
||||
const DOCUMENT_UPDATE_POSITION = "action.updateDocumentPosition";
|
||||
|
||||
/**
|
||||
* Delete given document
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Thelia\Core\Event;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
||||
|
||||
class UpdateImagePositionEvent extends UpdatePositionEvent
|
||||
class UpdateFilePositionEvent extends UpdatePositionEvent
|
||||
{
|
||||
protected $query;
|
||||
|
||||
@@ -7,6 +7,7 @@ use Propel\Runtime\Connection\ConnectionInterface;
|
||||
|
||||
class CategoryDocument extends BaseCategoryDocument
|
||||
{
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,7 @@ use Propel\Runtime\Connection\ConnectionInterface;
|
||||
|
||||
class ContentDocument extends BaseContentDocument
|
||||
{
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,7 @@ use Propel\Runtime\Connection\ConnectionInterface;
|
||||
|
||||
class FolderDocument extends BaseFolderDocument
|
||||
{
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,7 @@ use Propel\Runtime\Connection\ConnectionInterface;
|
||||
|
||||
class ProductDocument extends BaseProductDocument
|
||||
{
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user