Finished category related content management

This commit is contained in:
franck
2013-09-17 13:50:01 +02:00
parent d097851522
commit 3d78af8b97
16 changed files with 486 additions and 24 deletions

View File

@@ -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;
}

View File

@@ -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
@@ -162,14 +169,23 @@ class CategoryController extends AbstractCrudController
}
protected function renderEditionTemplate() {
return $this->render('category-edit', array('category_id' => $this->getRequest()->get('category_id', 0)));
return $this->render('category-edit',
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 redirectToEditionTemplate() {
$this->redirectToRoute(
"admin.categories.update",
array('category_id' => $this->getRequest()->get('category_id', 0))
);
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 redirectToListTemplate() {
@@ -209,6 +225,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 +252,80 @@ 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()
->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();
}
}

View File

@@ -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
*