create contentAddFolder process
This commit is contained in:
@@ -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),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -395,6 +395,14 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\ContentController::deleteAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.content.additional-folder.add" path="/admin/products/category/add">
|
||||
<default key="_controller">Thelia\Controller\Admin\ContentController::addAdditionalCategoryAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.content.additional-folder.delete" path="/admin/products/category/delete">
|
||||
<default key="_controller">Thelia\Controller\Admin\ContentController::deleteAdditionalCategoryAction</default>
|
||||
</route>
|
||||
|
||||
|
||||
<!-- Route to the Coupon controller (process Coupon browsing) -->
|
||||
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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) {
|
||||
|
||||
|
||||
66
core/lib/Thelia/Core/Event/Content/ContentAddFolderEvent.php
Normal file
66
core/lib/Thelia/Core/Event/Content/ContentAddFolderEvent.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\Content;
|
||||
use Thelia\Model\Content;
|
||||
|
||||
|
||||
/**
|
||||
* Class ContentAddFolderEvent
|
||||
* @package Thelia\Core\Event\Content
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -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";
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div class="col-md-6">
|
||||
<div class="well well-sm">
|
||||
<div class="form-group">
|
||||
<form method="POST" action="{url path='/admin/products/category/add'}" id="related_content_form">
|
||||
<form method="POST" action="{url path='/admin/content/folder/add'}" id="related_content_form">
|
||||
|
||||
<p class="title title-without-tabs">{intl l='Additional categories'}</p>
|
||||
<p>{intl l='A content could be attached to more than one folder. Select here the additional fodlers for this content.'}
|
||||
@@ -22,7 +22,7 @@
|
||||
{ifloop rel="folders"}
|
||||
<div class="input-group">
|
||||
|
||||
<select name="additional_category_id" id="accessory_category_id" class="form-control">
|
||||
<select name="additional_folder_id" id="additional_folder_id" class="form-control">
|
||||
<option value="">{intl l='Select a folder...'}</option>
|
||||
{loop name="folders" type="folder-tree" folder="0" exclude=$exclude_from_tree backend_context="1" lang="$edit_language_id"}
|
||||
<option value="{$ID}" style="padding-left: {3 + $LEVEL * 20}px" {if $DEFAULT_FOLDER==$ID}disabled="disabled"{/if}>
|
||||
|
||||
Reference in New Issue
Block a user