Created AbstractCrudController, and refactored existing controllers

This commit is contained in:
franck
2013-09-12 13:02:40 +02:00
parent 0671c2ce7d
commit c85ec2a9e3
31 changed files with 1033 additions and 566 deletions

View File

@@ -34,7 +34,7 @@ use Thelia\Core\Event\CurrencyUpdateEvent;
use Thelia\Core\Event\CurrencyCreateEvent;
use Thelia\Core\Event\CurrencyDeleteEvent;
use Thelia\Model\ConfigQuery;
use Thelia\Core\Event\CurrencyUpdatePositionEvent;
use Thelia\Core\Event\UpdatePositionEvent;
class Currency extends BaseAction implements EventSubscriberInterface
{
@@ -164,21 +164,25 @@ class Currency extends BaseAction implements EventSubscriberInterface
*
* @param CategoryChangePositionEvent $event
*/
public function updatePosition(CurrencyUpdatePositionEvent $event)
public function updatePosition(UpdatePositionEvent $event)
{
if (null !== $currency = CurrencyQuery::create()->findOneById($event->getObjectId())) {
echo "update =".$event->getObjectId();
if (null !== $currency = CurrencyQuery::create()->findPk($event->getObjectId())) {
$currency->setDispatcher($this->getDispatcher());
$mode = $event->getMode();
echo "loaded $mode !";
if ($mode == CurrencyUpdatePositionEvent::POSITION_ABSOLUTE)
if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE)
return $currency->changeAbsolutePosition($event->getPosition());
else if ($mode == CurrencyUpdatePositionEvent::POSITION_UP)
else if ($mode == UpdatePositionEvent::POSITION_UP)
return $currency->movePositionUp();
else if ($mode == CurrencyUpdatePositionEvent::POSITION_DOWN)
else if ($mode == UpdatePositionEvent::POSITION_DOWN)
return $currency->movePositionDown();
}
exit;
}
/**

View File

@@ -57,6 +57,11 @@
<tag name="kernel.event_subscriber"/>
</service>
<service id="thelia.action.attribute" class="Thelia\Action\Attribute">
<argument type="service" id="service_container"/>
<tag name="kernel.event_subscriber"/>
</service>
<service id="thelia.action.pageNotFound" class="Thelia\Action\PageNotFound">
<argument type="service" id="service_container"/>
<tag name="kernel.event_subscriber"/>

View File

@@ -1,7 +1,7 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
@@ -17,33 +17,369 @@
/* 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/>. */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Controller\Admin;
use Thelia\Core\Event\AttributeDeleteEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Tools\URL;
use Thelia\Core\Event\AttributeUpdateEvent;
use Thelia\Core\Event\AttributeCreateEvent;
use Thelia\Log\Tlog;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Core\Security\Exception\AuthorizationException;
use Thelia\Model\AttributeQuery;
use Thelia\Form\AttributeModificationForm;
use Thelia\Form\AttributeCreationForm;
use Thelia\Core\Event\AttributeUpdatePositionEvent;
use Thelia\Form\AttributeValueCreationForm;
use Thelia\Core\Event\AttributeValueCreateEvent;
use Thelia\Core\Event\AttributeValueDeleteEvent;
/**
* Manages messages sent by mail
* Manages product attributes
*
* @author Franck Allimant <franck@cqfdev.fr>
*/
class AttributeController extends BaseAdminController
{
/**
* The default action is displaying the attributes list.
* Render the attributes list, ensuring the sort order is set.
*
* @return Symfony\Component\HttpFoundation\Response the response
*/
public function defaultAction()
{
if (null !== $response = $this->checkAuth("admin.configuration.attributes.view")) return $response;
return $this->render('product-attributes');
protected function renderList() {
// Find the current order
$order = $this->getRequest()->get(
'order',
$this->getSession()->get('admin.attribute_order', 'manual')
);
// Store the current sort order in session
$this->getSession()->set('admin.attribute_order', $order);
return $this->render('attributes', array('order' => $order));
}
public function updateAction()
{
if (null !== $response = $this->checkAuth("admin.configuration.attributes.update")) return $response;
return $this->render('product-attributes-edit');
/**
* The default action is displaying the product attributes list.
*
* @return Symfony\Component\HttpFoundation\Response the response
*/
public function defaultAction() {
if (null !== $response = $this->checkAuth("admin.configuration.attributes.view")) return $response;
return $this->renderList();
}
}
/**
* Create a new product attribute object
*
* @return Symfony\Component\HttpFoundation\Response the response
*/
public function createAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.attributes.create")) return $response;
$error_msg = false;
// Create the Creation Form
$creationForm = new AttributeCreationForm($this->getRequest());
try {
// Validate the form, create the AttributeCreation event and dispatch it.
$form = $this->validateForm($creationForm, "POST");
$data = $form->getData();
$createEvent = new AttributeCreateEvent();
$createEvent
->setTitle($data['title'])
->setLocale($data["locale"])
->setAddToAllTemplates($data['add_to_all'])
;
$this->dispatch(TheliaEvents::ATTRIBUTE_CREATE, $createEvent);
if (! $createEvent->hasAttribute()) throw new \LogicException($this->getTranslator()->trans("No product attribute was created."));
$createdObject = $createEvent->getAttribute();
// Log product attribute creation
$this->adminLogAppend(sprintf("Attribute %s (ID %s) created", $createdObject->getTitle(), $createdObject->getId()));
// Substitute _ID_ in the URL with the ID of the created object
$successUrl = str_replace('_ID_', $createdObject->getId(), $creationForm->getSuccessUrl());
// Redirect to the success URL
$this->redirect($successUrl);
}
catch (FormValidationException $ex) {
// Form cannot be validated
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
}
catch (\Exception $ex) {
// Any other error
$error_msg = $ex->getMessage();
}
$this->setupFormErrorContext("product attribute creation", $error_msg, $creationForm, $ex);
// At this point, the form has error, and should be redisplayed.
return $this->renderList();
}
/**
* Create a new product attribute value object
*
* @return Symfony\Component\HttpFoundation\Response the response
*/
public function createValueAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.attribute-values.create")) return $response;
$error_msg = false;
// Create the Creation Form
$creationForm = new AttributeValueCreationForm($this->getRequest());
try {
// Validate the form, create the AttributeCreation event and dispatch it.
$form = $this->validateForm($creationForm, "POST");
$data = $form->getData();
$createEvent = new AttributeValueCreateEvent();
$createEvent
->setTitle($data['title'])
->setLocale($data["locale"])
->setAttributeId($data["attribute_id"])
;
$this->dispatch(TheliaEvents::ATTRIBUTE_VALUE_CREATE, $createEvent);
if (! $createEvent->hasAttribute()) throw new \LogicException($this->getTranslator()->trans("No product attribute value was created."));
$createdObject = $createEvent->getAttributeValue();
// Log product attribute creation
$this->adminLogAppend(sprintf("Attribute value %s (ID %s) created", $createdObject->getTitle(), $createdObject->getId()));
// Redirect to the success URL
$this->redirect($creationForm->getSuccessUrl());
}
catch (FormValidationException $ex) {
// Form cannot be validated
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
}
catch (\Exception $ex) {
// Any other error
$error_msg = $ex->getMessage();
}
$this->setupFormErrorContext("product attribute value creation", $error_msg, $creationForm, $ex);
// At this point, the form has error, and should be redisplayed on the edition page
return $this->render('attribute-edit', array('attribute_id' => $this->getRequest()->get('attribute_id')));
}
/**
* Load a product attribute object for modification, and display the edit template.
*
* @return Symfony\Component\HttpFoundation\Response the response
*/
public function changeAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.attributes.update")) return $response;
// Load the product attribute object
$attribute = AttributeQuery::create()
->joinWithI18n($this->getCurrentEditionLocale())
->findOneById($this->getRequest()->get('attribute_id'));
if ($attribute != null) {
// Prepare the data that will hydrate the form
$data = array(
'id' => $attribute->getId(),
'locale' => $attribute->getLocale(),
'title' => $attribute->getTitle(),
'chapo' => $attribute->getChapo(),
'description' => $attribute->getDescription(),
'postscriptum' => $attribute->getPostscriptum()
);
// Setup the object form
$changeForm = new AttributeModificationForm($this->getRequest(), "form", $data);
// Pass it to the parser
$this->getParserContext()->addForm($changeForm);
}
// Render the edition template.
return $this->render('attribute-edit', array('attribute_id' => $this->getRequest()->get('attribute_id')));
}
/**
* Save changes on a modified product attribute object, and either go back to the product attribute list, or stay on the edition page.
*
* @return Symfony\Component\HttpFoundation\Response the response
*/
public function saveChangeAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.attributes.update")) return $response;
$error_msg = false;
// Create the form from the request
$changeForm = new AttributeModificationForm($this->getRequest());
// Get the attribute ID
$attribute_id = $this->getRequest()->get('attribute_id');
try {
// Check the form against constraints violations
$form = $this->validateForm($changeForm, "POST");
// Get the form field values
$data = $form->getData();
$changeEvent = new AttributeUpdateEvent($data['id']);
// Create and dispatch the change event
$changeEvent
->setLocale($data["locale"])
->setTitle($data['title'])
->setChapo($data['chapo'])
->setDescription($data['description'])
->setPostscriptum($data['postscriptum'])
;
$this->dispatch(TheliaEvents::ATTRIBUTE_UPDATE, $changeEvent);
if (! $changeEvent->hasAttribute()) throw new \LogicException($this->getTranslator()->trans("No product attribute was updated."));
// Log product attribute modification
$changedObject = $changeEvent->getAttribute();
$this->adminLogAppend(sprintf("Attribute %s (ID %s) modified", $changedObject->getTitle(), $changedObject->getId()));
// If we have to stay on the same page, do not redirect to the succesUrl,
// just redirect to the edit page again.
if ($this->getRequest()->get('save_mode') == 'stay') {
$this->redirectToRoute(
"admin.configuration.attributes.update",
array('attribute_id' => $attribute_id)
);
}
// Redirect to the success URL
$this->redirect($changeForm->getSuccessUrl());
}
catch (FormValidationException $ex) {
// Form cannot be validated
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
}
catch (\Exception $ex) {
// Any other error
$error_msg = $ex->getMessage();
}
$this->setupFormErrorContext("product attribute modification", $error_msg, $changeForm, $ex);
// At this point, the form has errors, and should be redisplayed.
return $this->render('attribute-edit', array('attribute_id' => $attribute_id));
}
/**
* Update product attribute position
*/
public function updatePositionAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.attributes.update")) return $response;
try {
$mode = $this->getRequest()->get('mode', null);
if ($mode == 'up')
$mode = AttributeUpdatePositionEvent::POSITION_UP;
else if ($mode == 'down')
$mode = AttributeUpdatePositionEvent::POSITION_DOWN;
else
$mode = AttributeUpdatePositionEvent::POSITION_ABSOLUTE;
$position = $this->getRequest()->get('position', null);
$event = new AttributeUpdatePositionEvent(
$this->getRequest()->get('attribute_id', null),
$mode,
$this->getRequest()->get('position', null)
);
$this->dispatch(TheliaEvents::ATTRIBUTE_UPDATE_POSITION, $event);
}
catch (\Exception $ex) {
// Any error
return $this->errorPage($ex);
}
$this->redirectToRoute('admin.configuration.attributes.default');
}
/**
* Delete a product attribute object
*
* @return Symfony\Component\HttpFoundation\Response the response
*/
public function deleteAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.product attributes.delete")) return $response;
// Get the product attribute id, and dispatch the delet request
$event = new AttributeDeleteEvent($this->getRequest()->get('attribute_id'));
$this->dispatch(TheliaEvents::ATTRIBUTE_DELETE, $event);
if ($event->hasAttribute())
$this->adminLogAppend(sprintf("Attribute %s (ID %s) deleted", $event->getAttribute()->getTitle(), $event->getAttribute()->getId()));
$this->redirectToRoute('admin.configuration.attributes.default');
}
/**
* Delete a product attribute value object
*
* @return Symfony\Component\HttpFoundation\Response the response
*/
public function deleteValueAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.product attribute-values.delete")) return $response;
// Get the product attribute id, and dispatch the delet request
$event = new AttributeValueDeleteEvent($this->getRequest()->get('value_id'));
$this->dispatch(TheliaEvents::ATTRIBUTE_VALUE_DELETE, $event);
if ($event->hasAttributeValue())
$this->adminLogAppend(sprintf("Attribute value %s (ID %s) deleted", $event->getAttributeValue()->getTitle(), $event->getAttributeValue()->getId()));
$this->redirectToRoute('admin.configuration.attributes.default');
}
}

View File

@@ -288,7 +288,7 @@ class ConfigController extends BaseAdminController
$this->dispatch(TheliaEvents::CONFIG_DELETE, $event);
if ($event->hasConfig())
$this->adminLogAppend(sprintf("Variable %s (ID %s) modified", $event->getConfig()->getName(), $event->getConfig()->getId()));
$this->adminLogAppend(sprintf("Variable %s (ID %s) deleted", $event->getConfig()->getName(), $event->getConfig()->getId()));
$this->redirectToRoute('admin.configuration.variables.default');
}

View File

@@ -25,219 +25,167 @@ namespace Thelia\Controller\Admin;
use Thelia\Core\Event\CurrencyDeleteEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Tools\URL;
use Thelia\Core\Event\CurrencyUpdateEvent;
use Thelia\Core\Event\CurrencyCreateEvent;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\CurrencyQuery;
use Thelia\Form\CurrencyModificationForm;
use Thelia\Form\CurrencyCreationForm;
use Thelia\Core\Event\CurrencyUpdatePositionEvent;
use Thelia\Core\Event\UpdatePositionEvent;
/**
* Manages currencies sent by mail
*
* @author Franck Allimant <franck@cqfdev.fr>
*/
class CurrencyController extends BaseAdminController
class CurrencyController extends AbstractCrudController
{
/**
* Render the currencies list, ensuring the sort order is set.
*
* @return Symfony\Component\HttpFoundation\Response the response
*/
protected function renderList()
{
// Find the current order
$order = $this->getRequest()->get(
'order',
$this->getSession()->get('admin.currency_order', 'manual')
public function __construct() {
parent::__construct(
'currency',
'manual',
'admin.configuration.currencies.view',
'admin.configuration.currencies.create',
'admin.configuration.currencies.update',
'admin.configuration.currencies.delete',
TheliaEvents::CURRENCY_CREATE,
TheliaEvents::CURRENCY_UPDATE,
TheliaEvents::CURRENCY_DELETE,
null, // No visibility toggle
TheliaEvents::CURRENCY_UPDATE_POSITION
);
}
protected function getCreationForm() {
return new CurrencyCreationForm($this->getRequest());
}
protected function getUpdateForm() {
return new CurrencyModificationForm($this->getRequest());
}
protected function getCreationEvent($formData) {
$createEvent = new CurrencyCreateEvent();
$createEvent
->setCurrencyName($formData['name'])
->setLocale($formData["locale"])
->setSymbol($formData['symbol'])
->setCode($formData['code'])
->setRate($formData['rate'])
;
return $createEvent;
}
protected function getUpdateEvent($formData) {
$changeEvent = new CurrencyUpdateEvent($formData['id']);
// Create and dispatch the change event
$changeEvent
->setCurrencyName($formData['name'])
->setLocale($formData["locale"])
->setSymbol($formData['symbol'])
->setCode($formData['code'])
->setRate($formData['rate'])
;
return $changeEvent;
}
protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
return new UpdatePositionEvent(
$this->getRequest()->get('currency_id', null),
$positionChangeMode,
$positionValue
);
}
protected function createToggleVisibilityEvent() {
return new ToggleVisibilityEvent($this->getRequest()->get('currency_id', null));
}
protected function getDeleteEvent() {
return new CurrencyDeleteEvent($this->getRequest()->get('currency_id'));
}
protected function eventContainsObject($event) {
return $event->hasCurrency();
}
protected function hydrateObjectForm($object) {
// Prepare the data that will hydrate the form
$data = array(
'id' => $object->getId(),
'name' => $object->getName(),
'locale' => $object->getLocale(),
'code' => $object->getCode(),
'symbol' => $object->getSymbol(),
'rate' => $object->getRate()
);
// Store the current sort order in session
$this->getSession()->set('admin.currency_order', $order);
return $this->render('currencies', array('order' => $order));
// Setup the object form
return new CurrencyModificationForm($this->getRequest(), "form", $data);
}
/**
* The default action is displaying the currencies list.
*
* @return Symfony\Component\HttpFoundation\Response the response
*/
public function defaultAction()
{
if (null !== $response = $this->checkAuth("admin.configuration.currencies.view")) return $response;
return $this->renderList();
protected function getObjectFromEvent($event) {
return $event->hasCurrency() ? $event->getCurrency() : null;
}
/**
* Create a new currency object
*
* @return Symfony\Component\HttpFoundation\Response the response
*/
public function createAction()
{
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.currencies.create")) return $response;
$error_msg = false;
// Create the Creation Form
$creationForm = new CurrencyCreationForm($this->getRequest());
try {
// Validate the form, create the CurrencyCreation event and dispatch it.
$form = $this->validateForm($creationForm, "POST");
$data = $form->getData();
$createEvent = new CurrencyCreateEvent();
$createEvent
->setCurrencyName($data['name'])
->setLocale($data["locale"])
->setSymbol($data['symbol'])
->setCode($data['code'])
->setRate($data['rate'])
;
$this->dispatch(TheliaEvents::CURRENCY_CREATE, $createEvent);
if (! $createEvent->hasCurrency()) throw new \LogicException($this->getTranslator()->trans("No currency was created."));
$createdObject = $createEvent->getCurrency();
// Log currency creation
$this->adminLogAppend(sprintf("Currency %s (ID %s) created", $createdObject->getName(), $createdObject->getId()));
// Substitute _ID_ in the URL with the ID of the created object
$successUrl = str_replace('_ID_', $createdObject->getId(), $creationForm->getSuccessUrl());
// Redirect to the success URL
$this->redirect($successUrl);
} catch (FormValidationException $ex) {
// Form cannot be validated
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
} catch (\Exception $ex) {
// Any other error
$error_msg = $ex->getMessage();
}
$this->setupFormErrorContext("currency creation", $error_msg, $creationForm, $ex);
// At this point, the form has error, and should be redisplayed.
return $this->renderList();
protected function getExistingObject() {
return CurrencyQuery::create()
->joinWithI18n($this->getCurrentEditionLocale())
->findOneById($this->getRequest()->get('currency_id'));
}
/**
* Load a currency object for modification, and display the edit template.
*
* @return Symfony\Component\HttpFoundation\Response the response
*/
public function changeAction()
{
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response;
protected function getObjectLabel($object) {
return $object->getName();
}
// Load the currency object
$currency = CurrencyQuery::create()
->joinWithI18n($this->getCurrentEditionLocale())
->findOneById($this->getRequest()->get('currency_id'));
protected function getObjectId($object) {
return $object->getId();
}
if ($currency != null) {
protected function renderListTemplate($currentOrder) {
return $this->render('currencies', array('order' => $currentOrder));
}
// Prepare the data that will hydrate the form
$data = array(
'id' => $currency->getId(),
'name' => $currency->getName(),
'locale' => $currency->getLocale(),
'code' => $currency->getCode(),
'symbol' => $currency->getSymbol(),
'rate' => $currency->getRate()
);
// Setup the object form
$changeForm = new CurrencyModificationForm($this->getRequest(), "form", $data);
// Pass it to the parser
$this->getParserContext()->addForm($changeForm);
}
// Render the edition template.
protected function renderEditionTemplate() {
return $this->render('currency-edit', array('currency_id' => $this->getRequest()->get('currency_id')));
}
protected function redirectToEditionTemplate() {
$this->redirectToRoute(
"admin.configuration.currencies.update",
array('currency_id' => $this->getRequest()->get('currency_id'))
);
}
protected function redirectToListTemplate() {
$this->redirectToRoute('admin.configuration.currencies.default');
}
/**
* Save changes on a modified currency object, and either go back to the currency list, or stay on the edition page.
*
* @return Symfony\Component\HttpFoundation\Response the response
* Update currencies rates
*/
public function saveChangeAction()
public function updateRatesAction()
{
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response;
$error_msg = false;
// Create the form from the request
$changeForm = new CurrencyModificationForm($this->getRequest());
// Get the currency ID
$currency_id = $this->getRequest()->get('currency_id');
try {
// Check the form against constraints violations
$form = $this->validateForm($changeForm, "POST");
// Get the form field values
$data = $form->getData();
$changeEvent = new CurrencyUpdateEvent($data['id']);
// Create and dispatch the change event
$changeEvent
->setCurrencyName($data['name'])
->setLocale($data["locale"])
->setSymbol($data['symbol'])
->setCode($data['code'])
->setRate($data['rate'])
;
$this->dispatch(TheliaEvents::CURRENCY_UPDATE, $changeEvent);
if (! $changeEvent->hasCurrency()) throw new \LogicException($this->getTranslator()->trans("No currency was updated."));
// Log currency modification
$changedObject = $changeEvent->getCurrency();
$this->adminLogAppend(sprintf("Currency %s (ID %s) modified", $changedObject->getName(), $changedObject->getId()));
// If we have to stay on the same page, do not redirect to the succesUrl,
// just redirect to the edit page again.
if ($this->getRequest()->get('save_mode') == 'stay') {
$this->redirectToRoute(
"admin.configuration.currencies.update",
array('currency_id' => $currency_id)
);
}
// Redirect to the success URL
$this->redirect($changeForm->getSuccessUrl());
} catch (FormValidationException $ex) {
// Form cannot be validated
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
$this->dispatch(TheliaEvents::CURRENCY_UPDATE_RATES);
} catch (\Exception $ex) {
// Any other error
$error_msg = $ex->getMessage();
// Any error
return $this->errorPage($ex);
}
$this->setupFormErrorContext("currency modification", $error_msg, $changeForm, $ex);
// At this point, the form has errors, and should be redisplayed.
return $this->render('currency-edit', array('currency_id' => $currency_id));
$this->redirectToListTemplate();
}
/**
@@ -260,80 +208,7 @@ class CurrencyController extends BaseAdminController
return $this->errorPage($ex);
}
$this->redirectToRoute('admin.configuration.currencies.default');
$this->redirectToListTemplate();
}
/**
* Update currencies rates
*/
public function updateRatesAction()
{
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response;
try {
$this->dispatch(TheliaEvents::CURRENCY_UPDATE_RATES);
} catch (\Exception $ex) {
// Any error
return $this->errorPage($ex);
}
$this->redirectToRoute('admin.configuration.currencies.default');
}
/**
* Update currencyposition
*/
public function updatePositionAction()
{
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response;
try {
$mode = $this->getRequest()->get('mode', null);
if ($mode == 'up')
$mode = CurrencyUpdatePositionEvent::POSITION_UP;
else if ($mode == 'down')
$mode = CurrencyUpdatePositionEvent::POSITION_DOWN;
else
$mode = CurrencyUpdatePositionEvent::POSITION_ABSOLUTE;
$position = $this->getRequest()->get('position', null);
$event = new CurrencyUpdatePositionEvent(
$this->getRequest()->get('currency_id', null),
$mode,
$this->getRequest()->get('position', null)
);
$this->dispatch(TheliaEvents::CURRENCY_UPDATE_POSITION, $event);
} catch (\Exception $ex) {
// Any error
return $this->errorPage($ex);
}
$this->redirectToRoute('admin.configuration.currencies.default');
}
/**
* Delete a currency object
*
* @return Symfony\Component\HttpFoundation\Response the response
*/
public function deleteAction()
{
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.currencies.delete")) return $response;
// Get the currency id, and dispatch the delet request
$event = new CurrencyDeleteEvent($this->getRequest()->get('currency_id'));
$this->dispatch(TheliaEvents::CURRENCY_DELETE, $event);
if ($event->hasCurrency())
$this->adminLogAppend(sprintf("Currency %s (ID %s) modified", $event->getCurrency()->getName(), $event->getCurrency()->getId()));
$this->redirectToRoute('admin.configuration.currencies.default');
}
}

View File

@@ -247,7 +247,7 @@ class MessageController extends BaseAdminController
$this->dispatch(TheliaEvents::MESSAGE_DELETE, $event);
if ($event->hasMessage())
$this->adminLogAppend(sprintf("Message %s (ID %s) modified", $event->getMessage()->getName(), $event->getMessage()->getId()));
$this->adminLogAppend(sprintf("Message %s (ID %s) deleted", $event->getMessage()->getName(), $event->getMessage()->getId()));
$this->redirectToRoute('admin.configuration.messages.default');
}

View File

@@ -1,28 +0,0 @@
<?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;
class CategoryUpdatePositionEvent extends BaseUpdatePositionEvent
{
}

View File

@@ -1,28 +0,0 @@
<?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;
class CurrencyUpdatePositionEvent extends BaseUpdatePositionEvent
{
}

View File

@@ -23,7 +23,7 @@
namespace Thelia\Core\Event;
class BaseToggleVisibilityEvent extends ActionEvent
class ToggleVisibilityEvent extends ActionEvent
{
protected $object_id;

View File

@@ -23,7 +23,7 @@
namespace Thelia\Core\Event;
class BaseUpdatePositionEvent extends ActionEvent
class UpdatePositionEvent extends ActionEvent
{
const POSITION_UP = 1;
const POSITION_DOWN = 2;

View File

@@ -66,7 +66,7 @@ class Attribute extends BaseI18nLoop
new Argument(
'order',
new TypeCollection(
new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse'))
new Type\EnumListType(array('id', 'id_reverse', 'alpha', 'alpha_reverse', 'manual', 'manual_reverse'))
),
'manual'
)
@@ -129,6 +129,12 @@ class Attribute extends BaseI18nLoop
foreach ($orders as $order) {
switch ($order) {
case "id":
$search->orderById(Criteria::ASC);
break;
case "id_reverse":
$search->orderById(Criteria::DESC);
break;
case "alpha":
$search->addAscendingOrderByColumn('i18n_TITLE');
break;

View File

@@ -79,7 +79,7 @@ class Category extends BaseI18nLoop
new Argument(
'order',
new TypeCollection(
new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse', 'visible', 'visible_reverse', 'random'))
new Type\EnumListType(array('id', 'id_reverse', 'alpha', 'alpha_reverse', 'manual', 'manual_reverse', 'visible', 'visible_reverse', 'random'))
),
'manual'
),
@@ -132,6 +132,12 @@ class Category extends BaseI18nLoop
foreach ($orders as $order) {
switch ($order) {
case "id":
$search->orderById(Criteria::ASC);
break;
case "id_reverse":
$search->orderById(Criteria::DESC);
break;
case "alpha":
$search->addAscendingOrderByColumn('i18n_TITLE');
break;

View File

@@ -3,7 +3,69 @@
namespace Thelia\Model;
use Thelia\Model\Base\Attribute as BaseAttribute;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\AttributeEvent;
class Attribute extends BaseAttribute {
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
/**
* {@inheritDoc}
*/
public function preInsert(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_CREATEATTRIBUTE, new AttributeEvent($this));
// Set the current position for the new object
$this->setPosition($this->getNextPosition());
return true;
}
/**
* {@inheritDoc}
*/
public function postInsert(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::AFTER_CREATEATTRIBUTE, new AttributeEvent($this));
}
/**
* {@inheritDoc}
*/
public function preUpdate(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_UPDATEATTRIBUTE, new AttributeEvent($this));
return true;
}
/**
* {@inheritDoc}
*/
public function postUpdate(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::AFTER_UPDATEATTRIBUTE, new AttributeEvent($this));
}
/**
* {@inheritDoc}
*/
public function preDelete(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_DELETEATTRIBUTE, new AttributeEvent($this));
return true;
}
/**
* {@inheritDoc}
*/
public function postDelete(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::AFTER_DELETEATTRIBUTE, new AttributeEvent($this));
}
}

View File

@@ -3,7 +3,85 @@
namespace Thelia\Model;
use Thelia\Model\Base\AttributeAv as BaseAttributeAv;
use Thelia\Core\Event\AttributeValueEvent;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Core\Event\TheliaEvents;
use Propel\Runtime\ActiveQuery\Criteria;
class AttributeAv extends BaseAttributeAv {
}
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
/**
* Get the position of the next inserted object
*/
public function getNextPosition($parent = null) {
$last = $this->createQuery()
->filterByAttributeId($this->getAttributeId())
->orderByPosition(Criteria::DESC)
->limit(1)
->findOne()
;
return $last != null ? $last->getPosition() + 1 : 1;
}
/**
* {@inheritDoc}
*/
public function preInsert(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_CREATEATTRIBUTE_VALUE, new AttributeValueEvent($this));
// Set the current position for the new object
$this->setPosition($this->getNextPosition());
return true;
}
/**
* {@inheritDoc}
*/
public function postInsert(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::AFTER_CREATEATTRIBUTE_VALUE, new AttributeValueEvent($this));
}
/**
* {@inheritDoc}
*/
public function preUpdate(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_UPDATEATTRIBUTE_VALUE, new AttributeValueEvent($this));
return true;
}
/**
* {@inheritDoc}
*/
public function postUpdate(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::AFTER_UPDATEATTRIBUTE_VALUE, new AttributeValueEvent($this));
}
/**
* {@inheritDoc}
*/
public function preDelete(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_DELETEATTRIBUTE_VALUE, new AttributeValueEvent($this));
return true;
}
/**
* {@inheritDoc}
*/
public function postDelete(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::AFTER_DELETEATTRIBUTE_VALUE, new AttributeValueEvent($this));
}
}

View File

@@ -67,6 +67,7 @@ trait PositionManagementTrait {
* Move up a object
*/
public function movePositionUp() {
echo "move up !";
$this->movePositionUpOrDown(true);
}