Merge branch 'master' of github.com:thelia/thelia
This commit is contained in:
@@ -224,7 +224,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
* @param unknown $updateEvent the update event
|
||||
* @return Response a response, or null to continue normal processing
|
||||
*/
|
||||
protected function performAdditionalUpdateAction($updateeEvent)
|
||||
protected function performAdditionalUpdateAction($updateEvent)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,13 @@ use Thelia\Form\CategoryModificationForm;
|
||||
use Thelia\Form\CategoryCreationForm;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\Event\CategoryToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\CategoryDeleteContentEvent;
|
||||
use Thelia\Core\Event\CategoryAddContentEvent;
|
||||
use Thelia\Model\CategoryAssociatedContent;
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Model\ContentQuery;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Model\CategoryAssociatedContentQuery;
|
||||
|
||||
/**
|
||||
* Manages categories
|
||||
@@ -152,31 +159,37 @@ class CategoryController extends AbstractCrudController
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
protected function getEditionArguments()
|
||||
{
|
||||
return array(
|
||||
'category_id' => $this->getRequest()->get('category_id', 0),
|
||||
'folder_id' => $this->getRequest()->get('folder_id', 0),
|
||||
'current_tab' => $this->getRequest()->get('current_tab', 'general')
|
||||
);
|
||||
}
|
||||
|
||||
protected function renderListTemplate($currentOrder) {
|
||||
return $this->render('categories',
|
||||
array(
|
||||
'category_order' => $currentOrder,
|
||||
'category_id' => $this->getRequest()->get('category_id', 0)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function renderEditionTemplate() {
|
||||
return $this->render('category-edit', array('category_id' => $this->getRequest()->get('category_id', 0)));
|
||||
}
|
||||
|
||||
protected function redirectToEditionTemplate() {
|
||||
$this->redirectToRoute(
|
||||
"admin.categories.update",
|
||||
array('category_id' => $this->getRequest()->get('category_id', 0))
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
protected function redirectToListTemplate() {
|
||||
$this->redirectToRoute(
|
||||
'admin.categories.default',
|
||||
array('category_id' => $this->getRequest()->get('category_id', 0))
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
protected function renderEditionTemplate() {
|
||||
|
||||
return $this->render('category-edit', $this->getEditionArguments());
|
||||
}
|
||||
|
||||
protected function redirectToEditionTemplate() {
|
||||
$this->redirectToRoute("admin.categories.update", $this->getEditionArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,6 +222,18 @@ class CategoryController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
protected function performAdditionalUpdateAction($updateEvent)
|
||||
{
|
||||
if ($this->getRequest()->get('save_mode') != 'stay') {
|
||||
|
||||
// Redirect to parent category list
|
||||
$this->redirectToRoute(
|
||||
'admin.categories.default',
|
||||
array('category_id' => $updateEvent->getCategory()->getParent())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function performAdditionalUpdatePositionAction($event)
|
||||
{
|
||||
|
||||
@@ -224,4 +249,81 @@ class CategoryController extends AbstractCrudController
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getAvailableRelatedContentAction($categoryId, $folderId) {
|
||||
|
||||
$result = array();
|
||||
|
||||
$folders = FolderQuery::create()->filterById($folderId)->find();
|
||||
|
||||
if ($folders !== null) {
|
||||
|
||||
$list = ContentQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->filterByFolder($folders, Criteria::IN)
|
||||
->filterById(CategoryAssociatedContentQuery::create()->select('content_id')->findByCategoryId($categoryId), Criteria::NOT_IN)
|
||||
->find();
|
||||
;
|
||||
|
||||
if ($list !== null) {
|
||||
foreach($list as $item) {
|
||||
$result[] = array('id' => $item->getId(), 'title' => $item->getTitle());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->jsonResponse(json_encode($result));
|
||||
}
|
||||
|
||||
public function addRelatedContentAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.categories.update")) return $response;
|
||||
|
||||
$content_id = intval($this->getRequest()->get('content_id'));
|
||||
|
||||
if ($content_id > 0) {
|
||||
|
||||
$event = new CategoryAddContentEvent(
|
||||
$this->getExistingObject(),
|
||||
$content_id
|
||||
);
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::CATEGORY_ADD_CONTENT, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
}
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
public function deleteRelatedContentAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.categories.update")) return $response;
|
||||
|
||||
$content_id = intval($this->getRequest()->get('content_id'));
|
||||
|
||||
if ($content_id > 0) {
|
||||
|
||||
$event = new CategoryDeleteContentEvent(
|
||||
$this->getExistingObject(),
|
||||
$content_id
|
||||
);
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::CATEGORY_REMOVE_CONTENT, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
}
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,14 @@ class BaseController extends ContainerAware
|
||||
return new Response();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a JSON response
|
||||
*/
|
||||
protected function jsonResponse($json_data)
|
||||
{
|
||||
return new Response($json_data, 200, array('content-type' => 'application/json'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a Thelia event
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user