Merge branches 'coupon' and 'master' of https://github.com/thelia/thelia into coupon
* 'coupon' of https://github.com/thelia/thelia: # By Manuel Raynaud (10) and others # Via Manuel Raynaud (3) and others * 'master' of https://github.com/thelia/thelia: (27 commits) AttributesAv management update cart model Using "update" instead of "change" Finished admin controllers refactoriing Created AbstractCrudController, and refactored existing controllers Continuer attributes management Change script file declaration order for bootstrap-editable fix Delete form on the orders view translate error message - Creation of order-edit view valid customer removal pse ref in faker pse ref loop tests test product loop limit update customer general info fix tests product loop test remove not needed flag in customer part change method to retrieve data in customer create process ...
This commit is contained in:
473
core/lib/Thelia/Controller/Admin/AbstractCrudController.php
Normal file
473
core/lib/Thelia/Controller/Admin/AbstractCrudController.php
Normal file
@@ -0,0 +1,473 @@
|
||||
<?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\Controller\Admin;
|
||||
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\Event\ToggleVisibilityEvent;
|
||||
|
||||
/**
|
||||
* An abstract CRUD controller for Thelia ADMIN, to manage basic CRUD operations on a givent object.
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
abstract class AbstractCrudController extends BaseAdminController
|
||||
{
|
||||
protected $objectName;
|
||||
|
||||
// List ordering
|
||||
protected $defaultListOrder;
|
||||
|
||||
// Permissions
|
||||
protected $viewPermissionIdentifier;
|
||||
protected $createPermissionIdentifier;
|
||||
protected $updatePermissionIdentifier;
|
||||
protected $deletePermissionIdentifier;
|
||||
|
||||
// Events
|
||||
protected $createEventIdentifier;
|
||||
protected $updateEventIdentifier;
|
||||
protected $deleteEventIdentifier;
|
||||
protected $visibilityToggleEventIdentifier;
|
||||
protected $changePositionEventIdentifier;
|
||||
|
||||
|
||||
/**
|
||||
* @param string $objectName the lower case object name. Example. "message"
|
||||
*
|
||||
* @param string $defaultListOrder the default object list order, or null if list is not sortable. Example: manual
|
||||
*
|
||||
* @param string $viewPermissionIdentifier the 'view' permission identifier. Example: "admin.configuration.message.view"
|
||||
* @param string $createPermissionIdentifier the 'create' permission identifier. Example: "admin.configuration.message.create"
|
||||
* @param string $updatePermissionIdentifier the 'update' permission identifier. Example: "admin.configuration.message.update"
|
||||
* @param string $deletePermissionIdentifier the 'delete' permission identifier. Example: "admin.configuration.message.delete"
|
||||
*
|
||||
* @param string $createEventIdentifier the dispatched create TheliaEvent identifier. Example: TheliaEvents::MESSAGE_CREATE
|
||||
* @param string $updateEventIdentifier the dispatched update TheliaEvent identifier. Example: TheliaEvents::MESSAGE_UPDATE
|
||||
* @param string $deleteEventIdentifier the dispatched delete TheliaEvent identifier. Example: TheliaEvents::MESSAGE_DELETE
|
||||
*
|
||||
* @param string $visibilityToggleEventIdentifier the dispatched visibility toggle TheliaEvent identifier, or null if the object has no visible options. Example: TheliaEvents::MESSAGE_TOGGLE_VISIBILITY
|
||||
* @param string $changePositionEventIdentifier the dispatched position change TheliaEvent identifier, or null if the object has no position. Example: TheliaEvents::MESSAGE_UPDATE_POSITION
|
||||
*/
|
||||
public function __construct(
|
||||
$objectName,
|
||||
|
||||
$defaultListOrder = null,
|
||||
|
||||
$viewPermissionIdentifier,
|
||||
$createPermissionIdentifier,
|
||||
$updatePermissionIdentifier,
|
||||
$deletePermissionIdentifier,
|
||||
|
||||
$createEventIdentifier,
|
||||
$updateEventIdentifier,
|
||||
$deleteEventIdentifier,
|
||||
$visibilityToggleEventIdentifier = null,
|
||||
$changePositionEventIdentifier = null
|
||||
) {
|
||||
$this->objectName = $objectName;
|
||||
|
||||
$this->defaultListOrder = $defaultListOrder;
|
||||
|
||||
$this->viewPermissionIdentifier = $viewPermissionIdentifier;
|
||||
$this->createPermissionIdentifier = $createPermissionIdentifier;
|
||||
$this->updatePermissionIdentifier = $updatePermissionIdentifier;
|
||||
$this->deletePermissionIdentifier = $deletePermissionIdentifier;
|
||||
|
||||
$this->createEventIdentifier = $createEventIdentifier;
|
||||
$this->updateEventIdentifier = $updateEventIdentifier;
|
||||
$this->deleteEventIdentifier = $deleteEventIdentifier;
|
||||
$this->visibilityToggleEventIdentifier = $visibilityToggleEventIdentifier;
|
||||
$this->changePositionEventIdentifier = $changePositionEventIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the creation form for this object
|
||||
*/
|
||||
protected abstract function getCreationForm();
|
||||
|
||||
/**
|
||||
* Return the update form for this object
|
||||
*/
|
||||
protected abstract function getUpdateForm();
|
||||
|
||||
/**
|
||||
* Hydrate the update form for this object, before passing it to the update template
|
||||
*
|
||||
* @param unknown $object
|
||||
*/
|
||||
protected abstract function hydrateObjectForm($object);
|
||||
|
||||
/**
|
||||
* Creates the creation event with the provided form data
|
||||
*
|
||||
* @param unknown $formData
|
||||
*/
|
||||
protected abstract function getCreationEvent($formData);
|
||||
|
||||
/**
|
||||
* Creates the update event with the provided form data
|
||||
*
|
||||
* @param unknown $formData
|
||||
*/
|
||||
protected abstract function getUpdateEvent($formData);
|
||||
|
||||
/**
|
||||
* Creates the delete event with the provided form data
|
||||
*/
|
||||
protected abstract function getDeleteEvent();
|
||||
|
||||
/**
|
||||
* Return true if the event contains the object, e.g. the action has updated the object in the event.
|
||||
*
|
||||
* @param unknown $event
|
||||
*/
|
||||
protected abstract function eventContainsObject($event);
|
||||
|
||||
/**
|
||||
* Get the created object from an event.
|
||||
*
|
||||
* @param unknown $createEvent
|
||||
*/
|
||||
protected abstract function getObjectFromEvent($event);
|
||||
|
||||
/**
|
||||
* Load an existing object from the database
|
||||
*/
|
||||
protected abstract function getExistingObject();
|
||||
|
||||
/**
|
||||
* Returns the object label form the object event (name, title, etc.)
|
||||
*
|
||||
* @param unknown $object
|
||||
*/
|
||||
protected abstract function getObjectLabel($object);
|
||||
|
||||
/**
|
||||
* Returns the object ID from the object
|
||||
*
|
||||
* @param unknown $object
|
||||
*/
|
||||
protected abstract function getObjectId($object);
|
||||
|
||||
/**
|
||||
* Render the main list template
|
||||
*
|
||||
* @param unknown $currentOrder, if any, null otherwise.
|
||||
*/
|
||||
protected abstract function renderListTemplate($currentOrder);
|
||||
|
||||
/**
|
||||
* Render the edition template
|
||||
*/
|
||||
protected abstract function renderEditionTemplate();
|
||||
|
||||
/**
|
||||
* Redirect to the edition template
|
||||
*/
|
||||
protected abstract function redirectToEditionTemplate();
|
||||
|
||||
/**
|
||||
* Redirect to the list template
|
||||
*/
|
||||
protected abstract function redirectToListTemplate();
|
||||
|
||||
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
|
||||
throw new \LogicException ("Position Update is not supported for this object");
|
||||
}
|
||||
|
||||
protected function createToggleVisibilityEvent() {
|
||||
|
||||
throw new \LogicException ("Toggle Visibility is not supported for this object");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current list order identifier, updating it in the same time.
|
||||
*/
|
||||
protected function getCurrentListOrder($update_session = true) {
|
||||
|
||||
$order = null;
|
||||
|
||||
if ($this->defaultListOrder) {
|
||||
|
||||
$orderSessionIdentifier = sprintf("admin.%s.currentListOrder", $this->objectName);
|
||||
|
||||
// Find the current order
|
||||
$order = $this->getRequest()->get(
|
||||
'order',
|
||||
$this->getSession()->get($orderSessionIdentifier, $this->defaultListOrder)
|
||||
);
|
||||
|
||||
if ($update_session) $this->getSession()->set($orderSessionIdentifier, $order);
|
||||
}
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the object list, ensuring the sort order is set.
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
protected function renderList()
|
||||
{
|
||||
return $this->renderListTemplate($this->getCurrentListOrder());
|
||||
}
|
||||
|
||||
/**
|
||||
* The default action is displaying the list.
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function defaultAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth($this->viewPermissionIdentifier)) return $response;
|
||||
|
||||
return $this->renderList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new object
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->createPermissionIdentifier)) return $response;
|
||||
|
||||
$error_msg = false;
|
||||
|
||||
// Create the Creation Form
|
||||
$creationForm = $this->getCreationForm($this->getRequest());
|
||||
|
||||
try {
|
||||
|
||||
// Validate the form, create the event and dispatch it.
|
||||
$form = $this->validateForm($creationForm, "POST");
|
||||
|
||||
$data = $form->getData();
|
||||
|
||||
$createEvent = $this->getCreationEvent($data);
|
||||
|
||||
$this->dispatch($this->createEventIdentifier, $createEvent);
|
||||
|
||||
if (! $this->eventContainsObject($createEvent))
|
||||
throw new \LogicException(
|
||||
$this->getTranslator()->trans("No %obj was created.", array('%obj', $this->objectName)));
|
||||
|
||||
if (null !== $createdObject = $this->getObjectFromEvent($createEvent)) {
|
||||
// Log object creation
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) created", ucfirst($this->objectName), $this->getObjectLabel($createdObject), $this->getObjectId($createdObject)));
|
||||
}
|
||||
|
||||
// Substitute _ID_ in the URL with the ID of the created object
|
||||
$successUrl = str_replace('_ID_', $this->getObjectId($createdObject), $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(
|
||||
$this->getTranslator()->trans("%obj creation", array('%obj' => $this->objectName)), $error_msg, $creationForm, $ex);
|
||||
|
||||
// At this point, the form has error, and should be redisplayed.
|
||||
return $this->renderList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a object for modification, and display the edit template.
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function updateAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
|
||||
|
||||
// Load the object
|
||||
$object = $this->getExistingObject($this->getRequest());
|
||||
|
||||
if ($object != null) {
|
||||
|
||||
// Hydrate the form abd pass it to the parser
|
||||
$changeForm = $this->hydrateObjectForm($object);
|
||||
|
||||
// Pass it to the parser
|
||||
$this->getParserContext()->addForm($changeForm);
|
||||
}
|
||||
|
||||
// Render the edition template.
|
||||
return $this->renderEditionTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save changes on a modified object, and either go back to the object list, or stay on the edition page.
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function processUpdateAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
|
||||
|
||||
$error_msg = false;
|
||||
|
||||
// Create the form from the request
|
||||
$changeForm = $this->getUpdateForm($this->getRequest());
|
||||
|
||||
try {
|
||||
|
||||
// Check the form against constraints violations
|
||||
$form = $this->validateForm($changeForm, "POST");
|
||||
|
||||
// Get the form field values
|
||||
$data = $form->getData();
|
||||
|
||||
$changeEvent = $this->getUpdateEvent($data);
|
||||
|
||||
$this->dispatch($this->updateEventIdentifier, $changeEvent);
|
||||
|
||||
if (! $this->eventContainsObject($changeEvent))
|
||||
throw new \LogicException(
|
||||
$this->getTranslator()->trans("No %obj was updated.", array('%obj', $this->objectName)));
|
||||
|
||||
// Log object modification
|
||||
if (null !== $changedObject = $this->getObjectFromEvent($changeEvent)) {
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
}
|
||||
|
||||
// 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->redirectToEditionTemplate($this->getRequest());
|
||||
}
|
||||
|
||||
// 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(
|
||||
$this->getTranslator()->trans("%obj modification", array('%obj' => $this->objectName)), $error_msg, $changeForm, $ex);
|
||||
|
||||
// At this point, the form has errors, and should be redisplayed.
|
||||
return $this->renderEditionTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update object position (only for objects whichsupport that)
|
||||
*/
|
||||
public function updatePositionAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
|
||||
|
||||
try {
|
||||
$mode = $this->getRequest()->get('mode', null);
|
||||
|
||||
if ($mode == 'up')
|
||||
$mode = UpdatePositionEvent::POSITION_UP;
|
||||
else if ($mode == 'down')
|
||||
$mode = UpdatePositionEvent::POSITION_DOWN;
|
||||
else
|
||||
$mode = UpdatePositionEvent::POSITION_ABSOLUTE;
|
||||
|
||||
$position = $this->getRequest()->get('position', null);
|
||||
|
||||
$event = $this->createUpdatePositionEvent($mode, $position);
|
||||
|
||||
$this->dispatch($this->changePositionEventIdentifier, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
|
||||
$this->redirectToListTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Online status toggle (only for object which support it)
|
||||
*/
|
||||
public function setToggleVisibilityAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
|
||||
|
||||
$changeEvent = $this->createToggleVisibilityEvent($this->getRequest());
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent->setIsDefault(true);
|
||||
|
||||
try {
|
||||
$this->dispatch($this->visibilityToggleEventIdentifier, $changeEvent);
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
|
||||
$this->redirectToRoute('admin.categories.default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an object
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function deleteAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->deletePermissionIdentifier)) return $response;
|
||||
|
||||
// Get the currency id, and dispatch the delet request
|
||||
$deleteEvent = $this->getDeleteEvent();
|
||||
|
||||
$this->dispatch($this->deleteEventIdentifier, $deleteEvent);
|
||||
|
||||
if (null !== $deletedObject = $this->getObjectFromEvent($deleteEvent)) {
|
||||
$this->adminLogAppend(
|
||||
sprintf("%s %s (ID %s) deleted", ucfirst($this->objectName), $this->getObjectLabel($deletedObject), $this->getObjectId($deletedObject)));
|
||||
}
|
||||
|
||||
$this->redirectToListTemplate();
|
||||
}
|
||||
}
|
||||
180
core/lib/Thelia/Controller/Admin/AttributeAvController.php
Normal file
180
core/lib/Thelia/Controller/Admin/AttributeAvController.php
Normal file
@@ -0,0 +1,180 @@
|
||||
<?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\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\AttributeAvDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\AttributeAvUpdateEvent;
|
||||
use Thelia\Core\Event\AttributeAvCreateEvent;
|
||||
use Thelia\Model\AttributeAvQuery;
|
||||
use Thelia\Form\AttributeAvModificationForm;
|
||||
use Thelia\Form\AttributeAvCreationForm;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
|
||||
/**
|
||||
* Manages attributes-av sent by mail
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class AttributeAvController extends AbstractCrudController
|
||||
{
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
'attribute',
|
||||
'manual',
|
||||
|
||||
'admin.configuration.attributes-av.view',
|
||||
'admin.configuration.attributes-av.create',
|
||||
'admin.configuration.attributes-av.update',
|
||||
'admin.configuration.attributes-av.delete',
|
||||
|
||||
TheliaEvents::ATTRIBUTE_AV_CREATE,
|
||||
TheliaEvents::ATTRIBUTE_AV_UPDATE,
|
||||
TheliaEvents::ATTRIBUTE_AV_DELETE,
|
||||
null, // No visibility toggle
|
||||
TheliaEvents::ATTRIBUTE_AV_UPDATE_POSITION
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCreationForm() {
|
||||
return new AttributeAvCreationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getUpdateForm() {
|
||||
return new AttributeAvModificationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getCreationEvent($formData) {
|
||||
$createEvent = new AttributeAvCreateEvent();
|
||||
|
||||
$createEvent
|
||||
->setAttributeId($formData['attribute_id'])
|
||||
->setTitle($formData['title'])
|
||||
->setLocale($formData["locale"])
|
||||
;
|
||||
|
||||
return $createEvent;
|
||||
}
|
||||
|
||||
protected function getUpdateEvent($formData) {
|
||||
|
||||
$changeEvent = new AttributeAvUpdateEvent($formData['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent
|
||||
->setLocale($formData["locale"])
|
||||
->setTitle($formData['title'])
|
||||
->setChapo($formData['chapo'])
|
||||
->setDescription($formData['description'])
|
||||
->setPostscriptum($formData['postscriptum'])
|
||||
;
|
||||
|
||||
return $changeEvent;
|
||||
}
|
||||
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
|
||||
|
||||
return new UpdatePositionEvent(
|
||||
$this->getRequest()->get('attributeav_id', null),
|
||||
$positionChangeMode,
|
||||
$positionValue
|
||||
);
|
||||
}
|
||||
|
||||
protected function getDeleteEvent() {
|
||||
return new AttributeAvDeleteEvent($this->getRequest()->get('attributeav_id'));
|
||||
}
|
||||
|
||||
protected function eventContainsObject($event) {
|
||||
return $event->hasAttributeAv();
|
||||
}
|
||||
|
||||
protected function hydrateObjectForm($object) {
|
||||
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
'locale' => $object->getLocale(),
|
||||
'title' => $object->getTitle(),
|
||||
'chapo' => $object->getChapo(),
|
||||
'description' => $object->getDescription(),
|
||||
'postscriptum' => $object->getPostscriptum()
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
return new AttributeAvModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
protected function getObjectFromEvent($event) {
|
||||
return $event->hasAttributeAv() ? $event->getAttributeAv() : null;
|
||||
}
|
||||
|
||||
protected function getExistingObject() {
|
||||
return AttributeAvQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('attributeav_id'));
|
||||
}
|
||||
|
||||
protected function getObjectLabel($object) {
|
||||
return $object->getTitle();
|
||||
}
|
||||
|
||||
protected function getObjectId($object) {
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
protected function getViewArguments() {
|
||||
return array(
|
||||
'attribute_id' => $this->getRequest()->get('attribute_id'),
|
||||
'order' => $this->getCurrentListOrder()
|
||||
);
|
||||
}
|
||||
|
||||
protected function renderListTemplate($currentOrder) {
|
||||
// We always return to the attribute edition form
|
||||
return $this->render(
|
||||
'attribute-edit',
|
||||
$this->getViewArguments()
|
||||
);
|
||||
}
|
||||
|
||||
protected function renderEditionTemplate() {
|
||||
// We always return to the attribute edition form
|
||||
return $this->render('attribute-edit', $this->getViewArguments());
|
||||
}
|
||||
|
||||
protected function redirectToEditionTemplate() {
|
||||
// We always return to the attribute edition form
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.attributes.update",
|
||||
$this->getViewArguments()
|
||||
);
|
||||
}
|
||||
|
||||
protected function redirectToListTemplate() {
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.attributes.update",
|
||||
$this->getViewArguments()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -23,27 +23,142 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\AttributeDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\AttributeUpdateEvent;
|
||||
use Thelia\Core\Event\AttributeCreateEvent;
|
||||
use Thelia\Model\AttributeQuery;
|
||||
use Thelia\Form\AttributeModificationForm;
|
||||
use Thelia\Form\AttributeCreationForm;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
|
||||
/**
|
||||
* Manages messages sent by mail
|
||||
* Manages attributes sent by mail
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class AttributeController extends BaseAdminController
|
||||
class AttributeController extends AbstractCrudController
|
||||
{
|
||||
/**
|
||||
* The default action is displaying the 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->render('product-attributes');
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
'attribute',
|
||||
'manual',
|
||||
|
||||
'admin.configuration.attributes.view',
|
||||
'admin.configuration.attributes.create',
|
||||
'admin.configuration.attributes.update',
|
||||
'admin.configuration.attributes.delete',
|
||||
|
||||
TheliaEvents::ATTRIBUTE_CREATE,
|
||||
TheliaEvents::ATTRIBUTE_UPDATE,
|
||||
TheliaEvents::ATTRIBUTE_DELETE,
|
||||
null, // No visibility toggle
|
||||
TheliaEvents::ATTRIBUTE_UPDATE_POSITION
|
||||
);
|
||||
}
|
||||
|
||||
public function updateAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.attributes.update")) return $response;
|
||||
return $this->render('product-attributes-edit');
|
||||
protected function getCreationForm() {
|
||||
return new AttributeCreationForm($this->getRequest());
|
||||
}
|
||||
}
|
||||
|
||||
protected function getUpdateForm() {
|
||||
return new AttributeModificationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getCreationEvent($formData) {
|
||||
$createEvent = new AttributeCreateEvent();
|
||||
|
||||
$createEvent
|
||||
->setTitle($formData['title'])
|
||||
->setLocale($formData["locale"])
|
||||
->setAddToAllTemplates($formData['add_to_all'])
|
||||
;
|
||||
|
||||
return $createEvent;
|
||||
}
|
||||
|
||||
protected function getUpdateEvent($formData) {
|
||||
|
||||
$changeEvent = new AttributeUpdateEvent($formData['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent
|
||||
->setLocale($formData["locale"])
|
||||
->setTitle($formData['title'])
|
||||
->setChapo($formData['chapo'])
|
||||
->setDescription($formData['description'])
|
||||
->setPostscriptum($formData['postscriptum'])
|
||||
;
|
||||
|
||||
return $changeEvent;
|
||||
}
|
||||
|
||||
protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
|
||||
|
||||
return new UpdatePositionEvent(
|
||||
$this->getRequest()->get('attribute_id', null),
|
||||
$positionChangeMode,
|
||||
$positionValue
|
||||
);
|
||||
}
|
||||
|
||||
protected function getDeleteEvent() {
|
||||
return new AttributeDeleteEvent($this->getRequest()->get('attribute_id'));
|
||||
}
|
||||
|
||||
protected function eventContainsObject($event) {
|
||||
return $event->hasAttribute();
|
||||
}
|
||||
|
||||
protected function hydrateObjectForm($object) {
|
||||
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
'locale' => $object->getLocale(),
|
||||
'title' => $object->getTitle(),
|
||||
'chapo' => $object->getChapo(),
|
||||
'description' => $object->getDescription(),
|
||||
'postscriptum' => $object->getPostscriptum()
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
return new AttributeModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
protected function getObjectFromEvent($event) {
|
||||
return $event->hasAttribute() ? $event->getAttribute() : null;
|
||||
}
|
||||
|
||||
protected function getExistingObject() {
|
||||
return AttributeQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('attribute_id'));
|
||||
}
|
||||
|
||||
protected function getObjectLabel($object) {
|
||||
return $object->getTitle();
|
||||
}
|
||||
|
||||
protected function getObjectId($object) {
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
protected function renderListTemplate($currentOrder) {
|
||||
return $this->render('attributes', array('order' => $currentOrder));
|
||||
}
|
||||
|
||||
protected function renderEditionTemplate() {
|
||||
return $this->render('attribute-edit', array('attribute_id' => $this->getRequest()->get('attribute_id')));
|
||||
}
|
||||
|
||||
protected function redirectToEditionTemplate() {
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.attributes.update",
|
||||
array('attribute_id' => $this->getRequest()->get('attribute_id'))
|
||||
);
|
||||
}
|
||||
|
||||
protected function redirectToListTemplate() {
|
||||
$this->redirectToRoute('admin.configuration.attributes.default');
|
||||
}
|
||||
}
|
||||
@@ -25,228 +25,144 @@ namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\ConfigDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Core\Event\ConfigUpdateEvent;
|
||||
use Thelia\Core\Event\ConfigCreateEvent;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Form\ConfigModificationForm;
|
||||
use Thelia\Form\ConfigCreationForm;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
|
||||
/**
|
||||
* Manages Thelmia system variables, aka Config objects.
|
||||
* Manages variables sent by mail
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class ConfigController extends BaseAdminController
|
||||
class ConfigController 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.variables_order', 'name')
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
'variable',
|
||||
'name',
|
||||
|
||||
'admin.configuration.variables.view',
|
||||
'admin.configuration.variables.create',
|
||||
'admin.configuration.variables.update',
|
||||
'admin.configuration.variables.delete',
|
||||
|
||||
TheliaEvents::CONFIG_CREATE,
|
||||
TheliaEvents::CONFIG_UPDATE,
|
||||
TheliaEvents::CONFIG_DELETE,
|
||||
null, // No visibility toggle
|
||||
null // no position change
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCreationForm() {
|
||||
return new ConfigCreationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getUpdateForm() {
|
||||
return new ConfigModificationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getCreationEvent($data) {
|
||||
$createEvent = new ConfigCreateEvent();
|
||||
|
||||
$createEvent
|
||||
->setEventName($data['name'])
|
||||
->setValue($data['value'])
|
||||
->setLocale($data["locale"])
|
||||
->setTitle($data['title'])
|
||||
->setHidden($data['hidden'])
|
||||
->setSecured($data['secured'])
|
||||
;
|
||||
|
||||
|
||||
return $createEvent;
|
||||
}
|
||||
|
||||
protected function getUpdateEvent($data) {
|
||||
$changeEvent = new ConfigUpdateEvent($data['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent
|
||||
->setEventName($data['name'])
|
||||
->setValue($data['value'])
|
||||
->setHidden($data['hidden'])
|
||||
->setSecured($data['secured'])
|
||||
->setLocale($data["locale"])
|
||||
->setTitle($data['title'])
|
||||
->setChapo($data['chapo'])
|
||||
->setDescription($data['description'])
|
||||
->setPostscriptum($data['postscriptum'])
|
||||
;
|
||||
|
||||
return $changeEvent;
|
||||
}
|
||||
|
||||
protected function getDeleteEvent() {
|
||||
return new ConfigDeleteEvent($this->getRequest()->get('variable_id'));
|
||||
}
|
||||
|
||||
protected function eventContainsObject($event) {
|
||||
return $event->hasConfig();
|
||||
}
|
||||
|
||||
protected function hydrateObjectForm($object) {
|
||||
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
'name' => $object->getName(),
|
||||
'value' => $object->getValue(),
|
||||
'hidden' => $object->getHidden(),
|
||||
'secured' => $object->getSecured(),
|
||||
'locale' => $object->getLocale(),
|
||||
'title' => $object->getTitle(),
|
||||
'chapo' => $object->getChapo(),
|
||||
'description' => $object->getDescription(),
|
||||
'postscriptum' => $object->getPostscriptum()
|
||||
);
|
||||
|
||||
// Store the current sort order in session
|
||||
$this->getSession()->set('admin.variables_order', $order);
|
||||
|
||||
return $this->render('variables', array('order' => $order));
|
||||
// Setup the object form
|
||||
return new ConfigModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* The default action is displaying the variables list.
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function defaultAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.variables.view")) return $response;
|
||||
return $this->renderList();
|
||||
protected function getObjectFromEvent($event) {
|
||||
return $event->hasConfig() ? $event->getConfig() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new config object
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.variables.create")) return $response;
|
||||
|
||||
$message = false;
|
||||
|
||||
// Create the Creation Form
|
||||
$creationForm = new ConfigCreationForm($this->getRequest());
|
||||
|
||||
try {
|
||||
|
||||
// Validate the form, create the ConfigCreation event and dispatch it.
|
||||
$form = $this->validateForm($creationForm, "POST");
|
||||
|
||||
$data = $form->getData();
|
||||
|
||||
$createEvent = new ConfigCreateEvent();
|
||||
|
||||
$createEvent
|
||||
->setEventName($data['name'])
|
||||
->setValue($data['value'])
|
||||
->setLocale($data["locale"])
|
||||
->setTitle($data['title'])
|
||||
->setHidden($data['hidden'])
|
||||
->setSecured($data['secured'])
|
||||
;
|
||||
|
||||
$this->dispatch(TheliaEvents::CONFIG_CREATE, $createEvent);
|
||||
|
||||
if (! $createEvent->hasConfig()) throw new \LogicException($this->getTranslator()->trans("No variable was created."));
|
||||
|
||||
$createdObject = $createEvent->getConfig();
|
||||
|
||||
// Log config creation
|
||||
$this->adminLogAppend(sprintf("Variable %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
|
||||
$message = $this->createStandardFormValidationErrorMessage($ex);
|
||||
} catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$message = $ex->getMessage();
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext("variable creation", $message, $creationForm, $ex);
|
||||
|
||||
// At this point, the form has error, and should be redisplayed.
|
||||
return $this->renderList();
|
||||
protected function getExistingObject() {
|
||||
return ConfigQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('variable_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a config 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.variables.update")) return $response;
|
||||
protected function getObjectLabel($object) {
|
||||
return $object->getName();
|
||||
}
|
||||
|
||||
// Load the config object
|
||||
$config = ConfigQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('variable_id'));
|
||||
protected function getObjectId($object) {
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
if ($config != null) {
|
||||
protected function renderListTemplate($currentOrder) {
|
||||
return $this->render('variables', array('order' => $currentOrder));
|
||||
}
|
||||
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = array(
|
||||
'id' => $config->getId(),
|
||||
'name' => $config->getName(),
|
||||
'value' => $config->getValue(),
|
||||
'hidden' => $config->getHidden(),
|
||||
'secured' => $config->getSecured(),
|
||||
'locale' => $config->getLocale(),
|
||||
'title' => $config->getTitle(),
|
||||
'chapo' => $config->getChapo(),
|
||||
'description' => $config->getDescription(),
|
||||
'postscriptum' => $config->getPostscriptum()
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
$changeForm = new ConfigModificationForm($this->getRequest(), "form", $data);
|
||||
|
||||
// Pass it to the parser
|
||||
$this->getParserContext()->addForm($changeForm);
|
||||
}
|
||||
|
||||
// Render the edition template.
|
||||
protected function renderEditionTemplate() {
|
||||
return $this->render('variable-edit', array('variable_id' => $this->getRequest()->get('variable_id')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save changes on a modified config object, and either go back to the variable 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.variables.update")) return $response;
|
||||
protected function redirectToEditionTemplate() {
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.variables.update",
|
||||
array('variable_id' => $this->getRequest()->get('variable_id'))
|
||||
);
|
||||
}
|
||||
|
||||
$message = false;
|
||||
|
||||
// Create the form from the request
|
||||
$changeForm = new ConfigModificationForm($this->getRequest());
|
||||
|
||||
// Get the variable ID
|
||||
$variable_id = $this->getRequest()->get('variable_id');
|
||||
|
||||
try {
|
||||
|
||||
// Check the form against constraints violations
|
||||
$form = $this->validateForm($changeForm, "POST");
|
||||
|
||||
// Get the form field values
|
||||
$data = $form->getData();
|
||||
|
||||
$changeEvent = new ConfigUpdateEvent($data['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent
|
||||
->setEventName($data['name'])
|
||||
->setValue($data['value'])
|
||||
->setHidden($data['hidden'])
|
||||
->setSecured($data['secured'])
|
||||
->setLocale($data["locale"])
|
||||
->setTitle($data['title'])
|
||||
->setChapo($data['chapo'])
|
||||
->setDescription($data['description'])
|
||||
->setPostscriptum($data['postscriptum'])
|
||||
;
|
||||
|
||||
$this->dispatch(TheliaEvents::CONFIG_UPDATE, $changeEvent);
|
||||
|
||||
if (! $changeEvent->hasConfig()) throw new \LogicException($this->getTranslator()->trans("No variable was updated."));
|
||||
|
||||
// Log config modification
|
||||
$changedObject = $changeEvent->getConfig();
|
||||
|
||||
$this->adminLogAppend(sprintf("Variable %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.variables.update",
|
||||
array('variable_id' => $variable_id)
|
||||
);
|
||||
}
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirect($changeForm->getSuccessUrl());
|
||||
} catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$message = $this->createStandardFormValidationErrorMessage($ex);
|
||||
} catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$message = $ex->getMessage();
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext("variable edition", $message, $changeForm, $ex);
|
||||
|
||||
// At this point, the form has errors, and should be redisplayed.
|
||||
return $this->render('variable-edit', array('variable_id' => $variable_id));
|
||||
protected function redirectToListTemplate() {
|
||||
$this->redirectToRoute('admin.configuration.variables.default');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,25 +187,4 @@ class ConfigController extends BaseAdminController
|
||||
|
||||
$this->redirectToRoute('admin.configuration.variables.default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a config object
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function deleteAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.variables.delete")) return $response;
|
||||
|
||||
// Get the config id, and dispatch the delet request
|
||||
$event = new ConfigDeleteEvent($this->getRequest()->get('variable_id'));
|
||||
|
||||
$this->dispatch(TheliaEvents::CONFIG_DELETE, $event);
|
||||
|
||||
if ($event->hasConfig())
|
||||
$this->adminLogAppend(sprintf("Variable %s (ID %s) modified", $event->getConfig()->getName(), $event->getConfig()->getId()));
|
||||
|
||||
$this->redirectToRoute('admin.configuration.variables.default');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,219 +25,162 @@ 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 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 +203,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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,15 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Symfony\Component\Form\Form;
|
||||
use Thelia\Core\Event\CustomerCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\CustomerEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Form\CustomerModification;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
/**
|
||||
* Class CustomerController
|
||||
@@ -32,15 +41,141 @@ class CustomerController extends BaseAdminController
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.customers.view")) return $response;
|
||||
if (null !== $response = $this->checkAuth("admin.customer.view")) return $response;
|
||||
return $this->render("customers", array("display_customer" => 20));
|
||||
}
|
||||
|
||||
public function viewAction($customer_id)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.customer.view")) return $response;
|
||||
|
||||
return $this->render("customer-edit", array(
|
||||
"customer_id" => $customer_id
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* update customer action
|
||||
*
|
||||
* @param $customer_id
|
||||
* @return mixed|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function updateAction($customer_id)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.customer.update")) return $response;
|
||||
|
||||
$message = false;
|
||||
|
||||
$customerModification = new CustomerModification($this->getRequest());
|
||||
|
||||
try {
|
||||
$customer = CustomerQuery::create()->findPk($customer_id);
|
||||
|
||||
if(null === $customer) {
|
||||
throw new \InvalidArgumentException(sprintf("%d customer id does not exists", $customer_id));
|
||||
}
|
||||
|
||||
$form = $this->validateForm($customerModification);
|
||||
|
||||
$event = $this->createEventInstance($form->getData());
|
||||
$event->setCustomer($customer);
|
||||
|
||||
$this->dispatch(TheliaEvents::CUSTOMER_UPDATEACCOUNT, $event);
|
||||
|
||||
$customerUpdated = $event->getCustomer();
|
||||
|
||||
$this->adminLogAppend(sprintf("Customer with Ref %s (ID %d) modified", $customerUpdated->getRef() , $customerUpdated->getId()));
|
||||
|
||||
if($this->getRequest()->get("save_mode") == "close") {
|
||||
$this->redirectToRoute("admin.customers");
|
||||
} else {
|
||||
$this->redirectSuccess($customerModification);
|
||||
}
|
||||
|
||||
} catch (FormValidationException $e) {
|
||||
$message = sprintf("Please check your input: %s", $e->getMessage());
|
||||
} catch (PropelException $e) {
|
||||
$message = $e->getMessage();
|
||||
} catch (\Exception $e) {
|
||||
$message = sprintf("Sorry, an error occured: %s", $e->getMessage()." ".$e->getFile());
|
||||
}
|
||||
|
||||
if ($message !== false) {
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during customer login process : %s.", $message));
|
||||
|
||||
$customerModification->setErrorMessage($message);
|
||||
|
||||
$this->getParserContext()
|
||||
->addForm($customerModification)
|
||||
->setGeneralError($message)
|
||||
;
|
||||
}
|
||||
|
||||
return $this->render("customer-edit", array(
|
||||
"customer_id" => $customer_id
|
||||
));
|
||||
}
|
||||
|
||||
public function deleteAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.customer.delete")) return $response;
|
||||
|
||||
$message = null;
|
||||
|
||||
try {
|
||||
$customer_id = $this->getRequest()->get("customer_id");
|
||||
$customer = CustomerQuery::create()->findPk($customer_id);
|
||||
|
||||
if(null === $customer) {
|
||||
throw new \InvalidArgumentException(Translator::getInstance("The customer you want to delete does not exists"));
|
||||
}
|
||||
|
||||
$event = new CustomerEvent($customer);
|
||||
|
||||
$this->dispatch(TheliaEvents::CUSTOMER_DELETEACCOUNT, $event);
|
||||
} catch(\Exception $e) {
|
||||
$message = $e->getMessage();
|
||||
}
|
||||
|
||||
$params = array(
|
||||
"customer_page" => $this->getRequest()->get("customer_page", 1)
|
||||
);
|
||||
|
||||
if ($message) {
|
||||
$params["delete_error_message"] = $message;
|
||||
}
|
||||
|
||||
$this->redirectToRoute("admin.customers", $params);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return CustomerCreateOrUpdateEvent
|
||||
*/
|
||||
private function createEventInstance($data)
|
||||
{
|
||||
$customerCreateEvent = new CustomerCreateOrUpdateEvent(
|
||||
$data["title"],
|
||||
$data["firstname"],
|
||||
$data["lastname"],
|
||||
$data["address1"],
|
||||
$data["address2"],
|
||||
$data["address3"],
|
||||
$data["phone"],
|
||||
$data["cellphone"],
|
||||
$data["zipcode"],
|
||||
$data["city"],
|
||||
$data["country"],
|
||||
isset($data["email"])?$data["email"]:null,
|
||||
isset($data["password"]) ? $data["password"]:null,
|
||||
$this->getRequest()->getSession()->getLang()->getId(),
|
||||
isset($data["reseller"])?$data["reseller"]:null,
|
||||
isset($data["sponsor"])?$data["sponsor"]:null,
|
||||
isset($data["discount"])?$data["discount"]:null,
|
||||
isset($data["company"])?$data["company"]:null
|
||||
);
|
||||
|
||||
return $customerCreateEvent;
|
||||
}
|
||||
}
|
||||
@@ -24,11 +24,8 @@
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Event\MessageDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Core\Event\MessageUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;use Thelia\Core\Event\MessageUpdateEvent;
|
||||
use Thelia\Core\Event\MessageCreateEvent;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Model\MessageQuery;
|
||||
use Thelia\Form\MessageModificationForm;
|
||||
use Thelia\Form\MessageCreationForm;
|
||||
@@ -38,217 +35,124 @@ use Thelia\Form\MessageCreationForm;
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class MessageController extends BaseAdminController
|
||||
class MessageController extends AbstractCrudController
|
||||
{
|
||||
/**
|
||||
* Render the messages list
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
protected function renderList()
|
||||
{
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
'message',
|
||||
null,
|
||||
|
||||
'admin.configuration.messages.view',
|
||||
'admin.configuration.messages.create',
|
||||
'admin.configuration.messages.update',
|
||||
'admin.configuration.messages.delete',
|
||||
|
||||
TheliaEvents::MESSAGE_CREATE,
|
||||
TheliaEvents::MESSAGE_UPDATE,
|
||||
TheliaEvents::MESSAGE_DELETE,
|
||||
null, // No visibility toggle
|
||||
null // No position update
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCreationForm() {
|
||||
return new MessageCreationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getUpdateForm() {
|
||||
return new MessageModificationForm($this->getRequest());
|
||||
}
|
||||
|
||||
protected function getCreationEvent($formData) {
|
||||
$createEvent = new MessageCreateEvent();
|
||||
|
||||
$createEvent
|
||||
->setMessageName($formData['name'])
|
||||
->setLocale($formData["locale"])
|
||||
->setTitle($formData['title'])
|
||||
->setSecured($formData['secured'])
|
||||
;
|
||||
|
||||
return $createEvent;
|
||||
}
|
||||
|
||||
protected function getUpdateEvent($formData) {
|
||||
$changeEvent = new MessageUpdateEvent($formData['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent
|
||||
->setMessageName($formData['name'])
|
||||
->setSecured($formData['secured'])
|
||||
->setLocale($formData["locale"])
|
||||
->setTitle($formData['title'])
|
||||
->setSubject($formData['subject'])
|
||||
->setHtmlMessage($formData['html_message'])
|
||||
->setTextMessage($formData['text_message'])
|
||||
;
|
||||
|
||||
return $changeEvent;
|
||||
}
|
||||
|
||||
protected function getDeleteEvent() {
|
||||
return new MessageDeleteEvent($this->getRequest()->get('message_id'));
|
||||
}
|
||||
|
||||
protected function eventContainsObject($event) {
|
||||
return $event->hasMessage();
|
||||
}
|
||||
|
||||
protected function hydrateObjectForm($object) {
|
||||
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
'name' => $object->getName(),
|
||||
'secured' => $object->getSecured(),
|
||||
'locale' => $object->getLocale(),
|
||||
'title' => $object->getTitle(),
|
||||
'subject' => $object->getSubject(),
|
||||
'html_message' => $object->getHtmlMessage(),
|
||||
'text_message' => $object->getTextMessage()
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
return new MessageModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
protected function getObjectFromEvent($event) {
|
||||
return $event->hasMessage() ? $event->getMessage() : null;
|
||||
}
|
||||
|
||||
protected function getExistingObject() {
|
||||
return MessageQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('message_id'));
|
||||
}
|
||||
|
||||
protected function getObjectLabel($object) {
|
||||
return $object->getName();
|
||||
}
|
||||
|
||||
protected function getObjectId($object) {
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
protected function renderListTemplate($currentOrder) {
|
||||
return $this->render('messages');
|
||||
}
|
||||
|
||||
/**
|
||||
* The default action is displaying the messages list.
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function defaultAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.messages.view")) return $response;
|
||||
return $this->renderList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new message object
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.messages.create")) return $response;
|
||||
|
||||
$message = false;
|
||||
|
||||
// Create the creation Form
|
||||
$creationForm = new MessageCreationForm($this->getRequest());
|
||||
|
||||
try {
|
||||
|
||||
// Validate the form, create the MessageCreation event and dispatch it.
|
||||
$form = $this->validateForm($creationForm, "POST");
|
||||
|
||||
$data = $form->getData();
|
||||
|
||||
$createEvent = new MessageCreateEvent();
|
||||
|
||||
$createEvent
|
||||
->setMessageName($data['name'])
|
||||
->setLocale($data["locale"])
|
||||
->setTitle($data['title'])
|
||||
->setSecured($data['secured'])
|
||||
;
|
||||
|
||||
$this->dispatch(TheliaEvents::MESSAGE_CREATE, $createEvent);
|
||||
|
||||
if (! $createEvent->hasMessage()) throw new \LogicException($this->getTranslator()->trans("No message was created."));
|
||||
|
||||
$createdObject = $createEvent->getMessage();
|
||||
|
||||
$this->adminLogAppend(sprintf("Message %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
|
||||
$message = $this->createStandardFormValidationErrorMessage($ex);
|
||||
} catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$message = $ex->getMessage();
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext("message modification", $message, $creationForm, $ex);
|
||||
|
||||
// At this point, the form has error, and should be redisplayed.
|
||||
return $this->render('messages');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a message 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.messages.update")) return $response;
|
||||
|
||||
// Load the message object
|
||||
$message = MessageQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->findOneById($this->getRequest()->get('message_id'));
|
||||
|
||||
if ($message != null) {
|
||||
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = array(
|
||||
'id' => $message->getId(),
|
||||
'name' => $message->getName(),
|
||||
'secured' => $message->getSecured(),
|
||||
'locale' => $message->getLocale(),
|
||||
'title' => $message->getTitle(),
|
||||
'subject' => $message->getSubject(),
|
||||
'html_message' => $message->getHtmlMessage(),
|
||||
'text_message' => $message->getTextMessage()
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
$changeForm = new MessageModificationForm($this->getRequest(), "form", $data);
|
||||
|
||||
// Pass it to the parser
|
||||
$this->getParserContext()->addForm($changeForm);
|
||||
}
|
||||
|
||||
// Render the edition template.
|
||||
protected function renderEditionTemplate() {
|
||||
return $this->render('message-edit', array('message_id' => $this->getRequest()->get('message_id')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save changes on a modified message object, and either go back to the message 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.messages.update")) return $response;
|
||||
|
||||
$message = false;
|
||||
|
||||
// Create the form from the request
|
||||
$changeForm = new MessageModificationForm($this->getRequest());
|
||||
|
||||
// Get the message ID
|
||||
$message_id = $this->getRequest()->get('message_id');
|
||||
|
||||
try {
|
||||
|
||||
// Check the form against constraints violations
|
||||
$form = $this->validateForm($changeForm, "POST");
|
||||
|
||||
// Get the form field values
|
||||
$data = $form->getData();
|
||||
|
||||
$changeEvent = new MessageUpdateEvent($data['id']);
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent
|
||||
->setMessageName($data['name'])
|
||||
->setSecured($data['secured'])
|
||||
->setLocale($data["locale"])
|
||||
->setTitle($data['title'])
|
||||
->setSubject($data['subject'])
|
||||
->setHtmlMessage($data['html_message'])
|
||||
->setTextMessage($data['text_message'])
|
||||
;
|
||||
|
||||
$this->dispatch(TheliaEvents::MESSAGE_UPDATE, $changeEvent);
|
||||
|
||||
if (! $changeEvent->hasMessage()) throw new \LogicException($this->getTranslator()->trans("No message was updated."));
|
||||
|
||||
$changedObject = $changeEvent->getMessage();
|
||||
|
||||
$this->adminLogAppend(sprintf("Variable %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.messages.update",
|
||||
array('message_id' => $message_id)
|
||||
);
|
||||
}
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirect($changeForm->getSuccessUrl());
|
||||
} catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$message = $this->createStandardFormValidationErrorMessage($ex);
|
||||
} catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$message = $ex->getMessage();
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext("message modification", $message, $changeForm, $ex);
|
||||
|
||||
// At this point, the form has errors, and should be redisplayed.
|
||||
return $this->render('message-edit', array('message_id' => $message_id));
|
||||
protected function redirectToEditionTemplate() {
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.messages.update",
|
||||
array('message_id' => $this->getRequest()->get('message_id'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a message object
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
*/
|
||||
public function deleteAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.messages.delete")) return $response;
|
||||
|
||||
// Get the message id, and dispatch the delet request
|
||||
$event = new MessageDeleteEvent($this->getRequest()->get('message_id'));
|
||||
|
||||
$this->dispatch(TheliaEvents::MESSAGE_DELETE, $event);
|
||||
|
||||
if ($event->hasMessage())
|
||||
$this->adminLogAppend(sprintf("Message %s (ID %s) modified", $event->getMessage()->getName(), $event->getMessage()->getId()));
|
||||
|
||||
protected function redirectToListTemplate() {
|
||||
$this->redirectToRoute('admin.configuration.messages.default');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,4 +36,12 @@ class OrderController extends BaseAdminController
|
||||
return $this->render("orders", array("display_order" => 20));
|
||||
}
|
||||
|
||||
public function viewAction($order_id)
|
||||
{
|
||||
|
||||
return $this->render("order-edit", array(
|
||||
"order_id" => $order_id
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -278,7 +278,8 @@ class CustomerController extends BaseFrontController
|
||||
$this->getRequest()->getSession()->getLang()->getId(),
|
||||
isset($data["reseller"])?$data["reseller"]:null,
|
||||
isset($data["sponsor"])?$data["sponsor"]:null,
|
||||
isset($data["discount"])?$data["discount"]:null
|
||||
isset($data["discount"])?$data["discount"]:null,
|
||||
isset($data["company"])?$data["company"]:null
|
||||
);
|
||||
|
||||
return $customerCreateEvent;
|
||||
|
||||
Reference in New Issue
Block a user