Merge branch 'master' of github.com:thelia/thelia

This commit is contained in:
Etienne Roudeix
2013-09-17 15:02:38 +02:00
20 changed files with 531 additions and 42 deletions

View File

@@ -36,6 +36,10 @@ use Thelia\Core\Event\CategoryDeleteEvent;
use Thelia\Model\ConfigQuery;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Core\Event\CategoryToggleVisibilityEvent;
use Thelia\Core\Event\CategoryAddContentEvent;
use Thelia\Core\Event\CategoryDeleteContentEvent;
use Thelia\Model\CategoryAssociatedContent;
use Thelia\Model\CategoryAssociatedContentQuery;
class Category extends BaseAction implements EventSubscriberInterface
{
@@ -147,6 +151,33 @@ class Category extends BaseAction implements EventSubscriberInterface
}
}
public function addContent(CategoryAddContentEvent $event) {
if (CategoryAssociatedContentQuery::create()
->filterByContentId($event->getContentId())
->filterByCategory($event->getCategory())->count() <= 0) {
$content = new CategoryAssociatedContent();
$content
->setCategory($event->getCategory())
->setContentId($event->getContentId())
->save()
;
}
}
public function removeContent(CategoryDeleteContentEvent $event) {
$content = CategoryAssociatedContentQuery::create()
->filterByContentId($event->getContentId())
->filterByCategory($event->getCategory())->findOne()
;
if ($content !== null) $content->delete();
}
/**
* {@inheritDoc}
*/
@@ -157,7 +188,12 @@ class Category extends BaseAction implements EventSubscriberInterface
TheliaEvents::CATEGORY_UPDATE => array("update", 128),
TheliaEvents::CATEGORY_DELETE => array("delete", 128),
TheliaEvents::CATEGORY_TOGGLE_VISIBILITY => array("toggleVisibility", 128),
TheliaEvents::CATEGORY_UPDATE_POSITION => array("updatePosition", 128)
TheliaEvents::CATEGORY_UPDATE_POSITION => array("updatePosition", 128),
TheliaEvents::CATEGORY_ADD_CONTENT => array("addContent", 128),
TheliaEvents::CATEGORY_REMOVE_CONTENT => array("removeContent", 128),
);
}
}

View File

@@ -95,12 +95,25 @@
<route id="admin.categories.update-position" path="/admin/categories/update-position">
<default key="_controller">Thelia\Controller\Admin\CategoryController::updatePositionAction</default>
</route>
<route id="admin.categories.related-content.add" path="/admin/categories/related-content/add">
<default key="_controller">Thelia\Controller\Admin\CategoryController::addRelatedContentAction</default>
</route>
<route id="admin.categories.related-content.delete" path="/admin/categories/related-content/delete">
<default key="_controller">Thelia\Controller\Admin\CategoryController::deleteRelatedContentAction</default>
</route>
<route id="admin.category.available-related-content" path="/admin/category/{categoryId}/available-related-content/{folderId}.{_format}" methods="GET">
<default key="_controller">Thelia\Controller\Admin\CategoryController::getAvailableRelatedContentAction</default>
<requirement key="_format">xml|json</requirement>
</route>
<route id="admin.category.ajax" path="/admin/catalog/category/parent/{parentId}.{_format}" methods="GET">
<default key="_controller">Thelia\Controller\Admin\CategoryController::getByParentIdAction</default>
<requirement key="_format">xml|json</requirement>
</route>
<!-- Route to the Coupon controller (process Coupon browsing) -->
<route id="admin.coupon.list" path="/admin/coupon/">

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

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
*

View File

@@ -0,0 +1,48 @@
<?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;
use Thelia\Model\Category;
class CategoryAddContentEvent extends CategoryEvent
{
protected $content_id;
public function __construct(Category $category, $content_id)
{
parent::__construct($category);
$this->content_id = $content_id;
}
public function getContentId()
{
return $this->content_id;
}
public function setContentId($content_id)
{
$this->content_id = $content_id;
}
}

View File

@@ -0,0 +1,48 @@
<?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;
use Thelia\Model\Category;
class CategoryDeleteContentEvent extends CategoryEvent
{
protected $content_id;
public function __construct(Category $category, $content_id)
{
parent::__construct($category);
$this->content_id = $content_id;
}
public function getContentId()
{
return $this->content_id;
}
public function setContentId($content_id)
{
$this->content_id = $content_id;
}
}

View File

@@ -153,6 +153,9 @@ final class TheliaEvents
const CATEGORY_TOGGLE_VISIBILITY = "action.toggleCategoryVisibility";
const CATEGORY_UPDATE_POSITION = "action.updateCategoryPosition";
const CATEGORY_ADD_CONTENT = "action.categoryAddContent";
const CATEGORY_REMOVE_CONTENT = "action.categoryRemoveContent";
const BEFORE_CREATECATEGORY = "action.before_createcategory";
const AFTER_CREATECATEGORY = "action.after_createcategory";

View File

@@ -53,8 +53,12 @@ class AssociatedContent extends Content
{
$argumentCollection = parent::getArgDefinitions();
$argumentCollection->addArgument(Argument::createIntTypeArgument('product'))
->addArgument(Argument::createIntTypeArgument('category'));
$argumentCollection
->addArgument(Argument::createIntTypeArgument('product'))
->addArgument(Argument::createIntTypeArgument('category'))
->addArgument(Argument::createIntTypeArgument('exclude_product'))
->addArgument(Argument::createIntTypeArgument('exclude_category'))
;
$argumentCollection->get('order')->default = "associated_content";
@@ -91,6 +95,28 @@ class AssociatedContent extends Content
$search->filterByCategoryId($category, Criteria::EQUAL);
}
$exclude_product = $this->getExcludeProduct();
// If we have to filter by template, find all attributes assigned to this template, and filter by found IDs
if (null !== $exclude_product) {
// Exclure tous les attribut qui sont attachés aux templates indiqués
$search->filterById(
ProductAssociatedContentQuery::create()->filterByProductId($exclude_product)->select('product_id')->find(),
Criteria::NOT_IN
);
}
$exclude_category = $this->getExcludeCategory();
// If we have to filter by template, find all attributes assigned to this template, and filter by found IDs
if (null !== $exclude_category) {
// Exclure tous les attribut qui sont attachés aux templates indiqués
$search->filterById(
CategoryAssociatedContentQuery::create()->filterByProductId($exclude_category)->select('category_id')->find(),
Criteria::NOT_IN
);
}
$order = $this->getOrder();
$orderByAssociatedContent = array_search('associated_content', $order);
$orderByAssociatedContentReverse = array_search('associated_content_reverse', $order);

View File

@@ -61,6 +61,7 @@ class Content extends BaseI18nLoop
return new ArgumentCollection(
Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('folder'),
Argument::createIntListTypeArgument('folder_default'),
Argument::createBooleanTypeArgument('current'),
Argument::createBooleanTypeArgument('current_folder'),
Argument::createIntTypeArgument('depth', 1),
@@ -97,9 +98,18 @@ class Content extends BaseI18nLoop
}
$folder = $this->getFolder();
$folderDefault = $this->getFolderDefault();
if (!is_null($folder) || !is_null($folderDefault)) {
if (!is_null($folder)) {
$folders = FolderQuery::create()->filterById($folder, Criteria::IN)->find();
}
if (!is_null($folderDefault)) {
$folders = FolderQuery::create()->filterById($folderDefault, Criteria::IN)->find();
}
if (!is_null($folder)) {
$folders = FolderQuery::create()->filterById($folder, Criteria::IN)->find();
$depth = $this->getDepth();

View File

@@ -73,6 +73,7 @@ class Product extends BaseI18nLoop
)
),
Argument::createIntListTypeArgument('category'),
Argument::createIntListTypeArgument('category_default'),
Argument::createBooleanTypeArgument('new'),
Argument::createBooleanTypeArgument('promo'),
Argument::createFloatTypeArgument('min_price'),
@@ -170,9 +171,16 @@ class Product extends BaseI18nLoop
}
$category = $this->getCategory();
$categoryDefault = $this->getCategoryDefault();
if (!is_null($category)) {
$categories = CategoryQuery::create()->filterById($category, Criteria::IN)->find();
if (!is_null($category) ||!is_null($categoryDefault)) {
if (!is_null($category)) {
$categories = CategoryQuery::create()->filterById($category, Criteria::IN)->find();
}
if (!is_null($categoryDefault)) {
$categories = CategoryQuery::create()->filterById($categoryDefault, Criteria::IN)->find();
}
$depth = $this->getDepth();

View File

@@ -43,15 +43,18 @@ class CategoryCreationForm extends BaseForm
"label" => Translator::getInstance()->trans("Parent category *"),
"constraints" => array(
new NotBlank()
)
),
"label_attr" => array("for" => "parent_create")
))
->add("locale", "text", array(
"constraints" => array(
new NotBlank()
)
),
"label_attr" => array("for" => "locale_create")
))
->add("visible", "integer", array(
"label" => Translator::getInstance()->trans("This category is online on the front office.")
"label" => Translator::getInstance()->trans("This category is online on the front office."),
"label_attr" => array("for" => "visible_create")
))
;
}

View File

@@ -39,7 +39,8 @@ class CategoryModificationForm extends CategoryCreationForm
->add("url", "text", array(
"label" => Translator::getInstance()->trans("Rewriten URL *"),
"constraints" => array(new NotBlank())
"constraints" => array(new NotBlank()),
"label_attr" => array("for" => "rewriten_url")
))
;

View File

@@ -58,7 +58,8 @@ trait StandardDescriptionFieldsTrait
"label" => Translator::getInstance()->trans("Title"),
"label_attr" => array(
"for" => "title"
)
),
"label_attr" => array("for" => "title_field")
)
);
@@ -67,7 +68,7 @@ trait StandardDescriptionFieldsTrait
->add("chapo", "text", array(
"label" => Translator::getInstance()->trans("Summary"),
"label_attr" => array(
"for" => "summary"
"for" => "summary_field"
)
));
@@ -76,7 +77,7 @@ trait StandardDescriptionFieldsTrait
->add("description", "text", array(
"label" => Translator::getInstance()->trans("Detailed description"),
"label_attr" => array(
"for" => "detailed_description"
"for" => "detailed_description_field"
)
));
@@ -85,7 +86,7 @@ trait StandardDescriptionFieldsTrait
->add("postscriptum", "text", array(
"label" => Translator::getInstance()->trans("Conclusion"),
"label_attr" => array(
"for" => "conclusion"
"for" => "conclusion_field"
)
));
}

View File

@@ -25,4 +25,4 @@ class CategoryDocument extends BaseCategoryDocument
return true;
}
}
}