From dfda04ddd24634cd0154550c8082c0dc3030a502 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 1 Oct 2013 09:51:07 +0200 Subject: [PATCH] create contentAddFolder process --- core/lib/Thelia/Action/Content.php | 34 ++++++++-- .../Thelia/Config/Resources/routing/admin.xml | 8 +++ .../Controller/Admin/ContentController.php | 23 +++++++ .../Controller/Admin/ProductController.php | 3 +- .../Event/Content/ContentAddFolderEvent.php | 66 +++++++++++++++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 5 +- .../includes/content-folder-management.html | 4 +- 7 files changed, 133 insertions(+), 10 deletions(-) create mode 100644 core/lib/Thelia/Core/Event/Content/ContentAddFolderEvent.php diff --git a/core/lib/Thelia/Action/Content.php b/core/lib/Thelia/Action/Content.php index 300e269f6..fa4229a02 100644 --- a/core/lib/Thelia/Action/Content.php +++ b/core/lib/Thelia/Action/Content.php @@ -22,13 +22,17 @@ /*************************************************************************************/ namespace Thelia\Action; + use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Thelia\Core\Event\Content\ContentAddFolderEvent; use Thelia\Core\Event\Content\ContentCreateEvent; use Thelia\Core\Event\Content\ContentDeleteEvent; use Thelia\Core\Event\Content\ContentToggleVisibilityEvent; use Thelia\Core\Event\Content\ContentUpdateEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\UpdatePositionEvent; +use Thelia\Model\ContentFolder; +use Thelia\Model\ContentFolderQuery; use Thelia\Model\ContentQuery; use Thelia\Model\Content as ContentModel; @@ -123,6 +127,23 @@ class Content extends BaseAction implements EventSubscriberInterface } } + public function addFolder(ContentAddFolderEvent $event) + { + if(ContentFolderQuery::create() + ->filterByContent($event->getContent()) + ->filterByFolderId($event->getFolderId()) + ->count() <= 0 + ) { + $contentFolder = new ContentFolder(); + + $contentFolder + ->setFolderId($event->getFolderId()) + ->setContent($event->getContent()) + ->setDefaultFolder(false) + ->save(); + } + } + /** * Returns an array of event names this subscriber wants to listen to. * @@ -146,12 +167,15 @@ class Content extends BaseAction implements EventSubscriberInterface public static function getSubscribedEvents() { return array( - TheliaEvents::CONTENT_CREATE => array("create", 128), - TheliaEvents::CONTENT_UPDATE => array("update", 128), - TheliaEvents::CONTENT_DELETE => array("delete", 128), - TheliaEvents::CONTENT_TOGGLE_VISIBILITY => array("toggleVisibility", 128), + TheliaEvents::CONTENT_CREATE => array('create', 128), + TheliaEvents::CONTENT_UPDATE => array('update', 128), + TheliaEvents::CONTENT_DELETE => array('delete', 128), + TheliaEvents::CONTENT_TOGGLE_VISIBILITY => array('toggleVisibility', 128), - TheliaEvents::CONTENT_UPDATE_POSITION => array("updatePosition", 128), + TheliaEvents::CONTENT_UPDATE_POSITION => array('updatePosition', 128), + + TheliaEvents::CONTENT_ADD_FOLDER => array('addFolder', 128), + TheliaEvents::CONTENT_REMOVE_FOLDER => array('removeFolder', 128), ); } diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 61583054a..246279f08 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -395,6 +395,14 @@ Thelia\Controller\Admin\ContentController::deleteAction + + Thelia\Controller\Admin\ContentController::addAdditionalCategoryAction + + + + Thelia\Controller\Admin\ContentController::deleteAdditionalCategoryAction + + diff --git a/core/lib/Thelia/Controller/Admin/ContentController.php b/core/lib/Thelia/Controller/Admin/ContentController.php index 86082a0f4..6929be41c 100644 --- a/core/lib/Thelia/Controller/Admin/ContentController.php +++ b/core/lib/Thelia/Controller/Admin/ContentController.php @@ -22,6 +22,7 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; +use Thelia\Core\Event\Content\ContentAddFolderEvent; use Thelia\Core\Event\Content\ContentCreateEvent; use Thelia\Core\Event\Content\ContentDeleteEvent; use Thelia\Core\Event\Content\ContentToggleVisibilityEvent; @@ -60,6 +61,28 @@ class ContentController extends AbstractCrudController ); } + public function addAdditionalFolderAction() + { + // Check current user authorization + if (null !== $response = $this->checkAuth('admin.content.update')) return $response; + + $folder_id = intval($this->getRequest()->request->get('additional_folder_id')); + + if ($folder_id > 0) { + $event = new ContentAddFolderEvent( + $this->getExistingObject(), + $folder_id + ); + + try { + + } catch (\Exception $e) { + $this->errorPage($e); + } + } + + } + /** * Return the creation form for this object */ diff --git a/core/lib/Thelia/Controller/Admin/ProductController.php b/core/lib/Thelia/Controller/Admin/ProductController.php index 6780bb58a..4ff40abff 100644 --- a/core/lib/Thelia/Controller/Admin/ProductController.php +++ b/core/lib/Thelia/Controller/Admin/ProductController.php @@ -24,6 +24,7 @@ namespace Thelia\Controller\Admin; use Thelia\Core\Event\Product\ProductAddCategoryEvent; +use Thelia\Core\Event\Product\ProductDeleteCategoryEvent; use Thelia\Core\Event\Product\ProductDeleteEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\Product\ProductUpdateEvent; @@ -613,7 +614,7 @@ class ProductController extends AbstractCrudController // Check current user authorization if (null !== $response = $this->checkAuth("admin.products.update")) return $response; - $category_id = intval($this->getRequest()->get('additional_category_id')); + $category_id = intval($this->getRequest()->request->get('additional_category_id')); if ($category_id > 0) { diff --git a/core/lib/Thelia/Core/Event/Content/ContentAddFolderEvent.php b/core/lib/Thelia/Core/Event/Content/ContentAddFolderEvent.php new file mode 100644 index 000000000..a1d1d44e1 --- /dev/null +++ b/core/lib/Thelia/Core/Event/Content/ContentAddFolderEvent.php @@ -0,0 +1,66 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Content; +use Thelia\Model\Content; + + +/** + * Class ContentAddFolderEvent + * @package Thelia\Core\Event\Content + * @author Manuel Raynaud + */ +class ContentAddFolderEvent extends ContentEvent +{ + + /** + * @var int folder id + */ + protected $folderId; + + public function __construct(Content $content, $folderId) + { + $this->folderId = $folderId; + + parent::__construct($content); + } + + /** + * @param int $folderId + */ + public function setFolderId($folderId) + { + $this->folderId = $folderId; + } + + /** + * @return int + */ + public function getFolderId() + { + return $this->folderId; + } + + + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 451adf33b..29f45dd6d 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -193,8 +193,9 @@ final class TheliaEvents const CONTENT_TOGGLE_VISIBILITY = "action.toggleContentVisibility"; const CONTENT_UPDATE_POSITION = "action.updateContentPosition"; -// const FOLDER_ADD_CONTENT = "action.categoryAddContent"; -// const FOLDER_REMOVE_CONTENT = "action.categoryRemoveContent"; + const CONTENT_ADD_FOLDER = "action.contentAddFolder"; + const CONTENT_REMOVE_FOLDER = "action.contentRemoveFolder"; + const BEFORE_CREATECONTENT = "action.before_createContent"; const AFTER_CREATECONTENT = "action.after_createContent"; diff --git a/templates/admin/default/includes/content-folder-management.html b/templates/admin/default/includes/content-folder-management.html index 04bcd5a4a..5200ebb3e 100644 --- a/templates/admin/default/includes/content-folder-management.html +++ b/templates/admin/default/includes/content-folder-management.html @@ -4,7 +4,7 @@
-