Merge branch 'master' of https://github.com/thelia/thelia into coupon

# By franck (6) and others
# Via franck (3) and others
* 'master' of https://github.com/thelia/thelia:
  Implemented "Remember Me" feature on admin. Started template management
  Added Templates events
  First version of installation wizard
  tax engine retriever
  allow address removal from front
  Insert pagination inside tfoot
  allow update customer address in front tempalte
  allow to create a new address
  allow to make an address as default on update action
  Finished attributes management
  Fixed action column alignment
  Fixed duplication parameter check regexp
  absoluteUrl prevetn duplicate parameters in generated URL
This commit is contained in:
gmorel
2013-09-16 10:01:34 +02:00
140 changed files with 18725 additions and 3379 deletions

View File

@@ -38,6 +38,7 @@ abstract class AbstractCrudController extends BaseAdminController
// List ordering
protected $defaultListOrder;
protected $orderRequestParameterName;
// Permissions
protected $viewPermissionIdentifier;
@@ -74,6 +75,7 @@ abstract class AbstractCrudController extends BaseAdminController
$objectName,
$defaultListOrder = null,
$orderRequestParameterName = null,
$viewPermissionIdentifier,
$createPermissionIdentifier,
@@ -89,8 +91,9 @@ abstract class AbstractCrudController extends BaseAdminController
$this->objectName = $objectName;
$this->defaultListOrder = $defaultListOrder;
$this->orderRequestParameterName = $orderRequestParameterName;
$this->viewPermissionIdentifier = $viewPermissionIdentifier;
$this->viewPermissionIdentifier = $viewPermissionIdentifier;
$this->createPermissionIdentifier = $createPermissionIdentifier;
$this->updatePermissionIdentifier = $updatePermissionIdentifier;
$this->deletePermissionIdentifier = $deletePermissionIdentifier;
@@ -194,36 +197,59 @@ abstract class AbstractCrudController extends BaseAdminController
protected abstract function redirectToListTemplate();
protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
protected function createUpdatePositionEvent($positionChangeMode, $positionValue)
{
throw new \LogicException ("Position Update is not supported for this object");
}
protected function createToggleVisibilityEvent() {
protected function createToggleVisibilityEvent()
{
throw new \LogicException ("Toggle Visibility is not supported for this object");
}
/**
* Put in this method post object creation processing if required.
*
* @param unknown $createEvent the create event
* @return Response a response, or null to continue normal processing
*/
protected function performAdditionalCreateAction($createEvent)
{
return null;
}
/**
* Put in this method post object update processing if required.
*
* @param unknown $updateEvent the update event
* @return Response a response, or null to continue normal processing
*/
protected function performAdditionalUpdateAction($updateeEvent)
{
return null;
}
/**
* Put in this method post object delete processing if required.
*
* @param unknown $deleteEvent the delete event
* @return Response a response, or null to continue normal processing
*/
protected function performAdditionalDeleteAction($deleteEvent)
{
return null;
}
/**
* 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;
protected function getCurrentListOrder($update_session = true)
{
return $this->getListOrderFromSession(
$this->objectName,
$this->orderRequestParameterName,
$this->defaultListOrder
);
}
/**
@@ -283,6 +309,8 @@ abstract class AbstractCrudController extends BaseAdminController
$this->adminLogAppend(sprintf("%s %s (ID %s) created", ucfirst($this->objectName), $this->getObjectLabel($createdObject), $this->getObjectId($createdObject)));
}
$this->performAdditionalCreateAction($createEvent);
// Substitute _ID_ in the URL with the ID of the created object
$successUrl = str_replace('_ID_', $this->getObjectId($createdObject), $creationForm->getSuccessUrl());
@@ -317,7 +345,7 @@ abstract class AbstractCrudController extends BaseAdminController
if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
// Load the object
$object = $this->getExistingObject($this->getRequest());
$object = $this->getExistingObject();
if ($object != null) {
@@ -368,6 +396,8 @@ abstract class AbstractCrudController extends BaseAdminController
$this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
}
$this->performAdditionalUpdateAction($changeEvent);
// 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') {
@@ -468,6 +498,11 @@ abstract class AbstractCrudController extends BaseAdminController
sprintf("%s %s (ID %s) deleted", ucfirst($this->objectName), $this->getObjectLabel($deletedObject), $this->getObjectId($deletedObject)));
}
$this->redirectToListTemplate();
$response = $this->performAdditionalDeleteAction($deleteEvent);
if ($response == null)
$this->redirectToListTemplate();
else
return $response;
}
}

View File

@@ -23,6 +23,10 @@
namespace Thelia\Controller\Admin;
use Thelia\Core\Security\Authentication\AdminTokenAuthenticator;
use Thelia\Model\ConfigQuery;
use Thelia\Core\Security\Exception\TokenAuthenticationException;
class AdminController extends BaseAdminController
{
public function indexAction()

View File

@@ -39,10 +39,12 @@ use Thelia\Core\Event\UpdatePositionEvent;
*/
class AttributeAvController extends AbstractCrudController
{
public function __construct() {
public function __construct()
{
parent::__construct(
'attribute',
'attributeav',
'manual',
'order',
'admin.configuration.attributes-av.view',
'admin.configuration.attributes-av.create',
@@ -57,15 +59,18 @@ class AttributeAvController extends AbstractCrudController
);
}
protected function getCreationForm() {
protected function getCreationForm()
{
return new AttributeAvCreationForm($this->getRequest());
}
protected function getUpdateForm() {
protected function getUpdateForm()
{
return new AttributeAvModificationForm($this->getRequest());
}
protected function getCreationEvent($formData) {
protected function getCreationEvent($formData)
{
$createEvent = new AttributeAvCreateEvent();
$createEvent
@@ -77,8 +82,8 @@ class AttributeAvController extends AbstractCrudController
return $createEvent;
}
protected function getUpdateEvent($formData) {
protected function getUpdateEvent($formData)
{
$changeEvent = new AttributeAvUpdateEvent($formData['id']);
// Create and dispatch the change event
@@ -93,8 +98,8 @@ class AttributeAvController extends AbstractCrudController
return $changeEvent;
}
protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
protected function createUpdatePositionEvent($positionChangeMode, $positionValue)
{
return new UpdatePositionEvent(
$this->getRequest()->get('attributeav_id', null),
$positionChangeMode,
@@ -102,16 +107,18 @@ class AttributeAvController extends AbstractCrudController
);
}
protected function getDeleteEvent() {
protected function getDeleteEvent()
{
return new AttributeAvDeleteEvent($this->getRequest()->get('attributeav_id'));
}
protected function eventContainsObject($event) {
protected function eventContainsObject($event)
{
return $event->hasAttributeAv();
}
protected function hydrateObjectForm($object) {
protected function hydrateObjectForm($object)
{
$data = array(
'id' => $object->getId(),
'locale' => $object->getLocale(),
@@ -125,32 +132,38 @@ class AttributeAvController extends AbstractCrudController
return new AttributeAvModificationForm($this->getRequest(), "form", $data);
}
protected function getObjectFromEvent($event) {
protected function getObjectFromEvent($event)
{
return $event->hasAttributeAv() ? $event->getAttributeAv() : null;
}
protected function getExistingObject() {
protected function getExistingObject()
{
return AttributeAvQuery::create()
->joinWithI18n($this->getCurrentEditionLocale())
->findOneById($this->getRequest()->get('attributeav_id'));
}
protected function getObjectLabel($object) {
protected function getObjectLabel($object)
{
return $object->getTitle();
}
protected function getObjectId($object) {
protected function getObjectId($object)
{
return $object->getId();
}
protected function getViewArguments() {
protected function getViewArguments()
{
return array(
'attribute_id' => $this->getRequest()->get('attribute_id'),
'order' => $this->getCurrentListOrder()
);
}
protected function renderListTemplate($currentOrder) {
protected function renderListTemplate($currentOrder)
{
// We always return to the attribute edition form
return $this->render(
'attribute-edit',
@@ -158,12 +171,14 @@ class AttributeAvController extends AbstractCrudController
);
}
protected function renderEditionTemplate() {
protected function renderEditionTemplate()
{
// We always return to the attribute edition form
return $this->render('attribute-edit', $this->getViewArguments());
}
protected function redirectToEditionTemplate() {
protected function redirectToEditionTemplate()
{
// We always return to the attribute edition form
$this->redirectToRoute(
"admin.configuration.attributes.update",
@@ -171,7 +186,8 @@ class AttributeAvController extends AbstractCrudController
);
}
protected function redirectToListTemplate() {
protected function redirectToListTemplate()
{
$this->redirectToRoute(
"admin.configuration.attributes.update",
$this->getViewArguments()

View File

@@ -31,6 +31,10 @@ use Thelia\Model\AttributeQuery;
use Thelia\Form\AttributeModificationForm;
use Thelia\Form\AttributeCreationForm;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Model\AttributeAv;
use Thelia\Model\AttributeAvQuery;
use Thelia\Core\Event\AttributeAvUpdateEvent;
use Thelia\Core\Event\AttributeEvent;
/**
* Manages attributes sent by mail
@@ -39,10 +43,12 @@ use Thelia\Core\Event\UpdatePositionEvent;
*/
class AttributeController extends AbstractCrudController
{
public function __construct() {
public function __construct()
{
parent::__construct(
'attribute',
'manual',
'order',
'admin.configuration.attributes.view',
'admin.configuration.attributes.create',
@@ -57,15 +63,18 @@ class AttributeController extends AbstractCrudController
);
}
protected function getCreationForm() {
protected function getCreationForm()
{
return new AttributeCreationForm($this->getRequest());
}
protected function getUpdateForm() {
protected function getUpdateForm()
{
return new AttributeModificationForm($this->getRequest());
}
protected function getCreationEvent($formData) {
protected function getCreationEvent($formData)
{
$createEvent = new AttributeCreateEvent();
$createEvent
@@ -77,8 +86,8 @@ class AttributeController extends AbstractCrudController
return $createEvent;
}
protected function getUpdateEvent($formData) {
protected function getUpdateEvent($formData)
{
$changeEvent = new AttributeUpdateEvent($formData['id']);
// Create and dispatch the change event
@@ -93,8 +102,33 @@ class AttributeController extends AbstractCrudController
return $changeEvent;
}
protected function createUpdatePositionEvent($positionChangeMode, $positionValue) {
/**
* Process the attributes values (fix it in future version to integrate it in the attribute form as a collection)
*
* @see \Thelia\Controller\Admin\AbstractCrudController::performAdditionalUpdateAction()
*/
protected function performAdditionalUpdateAction($updateEvent)
{
$attr_values = $this->getRequest()->get('attribute_values', null);
if ($attr_values !== null) {
foreach($attr_values as $id => $value) {
$event = new AttributeAvUpdateEvent($id);
$event->setTitle($value);
$event->setLocale($this->getCurrentEditionLocale());
$this->dispatch(TheliaEvents::ATTRIBUTE_AV_UPDATE, $event);
}
}
return null;
}
protected function createUpdatePositionEvent($positionChangeMode, $positionValue)
{
return new UpdatePositionEvent(
$this->getRequest()->get('attribute_id', null),
$positionChangeMode,
@@ -102,15 +136,18 @@ class AttributeController extends AbstractCrudController
);
}
protected function getDeleteEvent() {
protected function getDeleteEvent()
{
return new AttributeDeleteEvent($this->getRequest()->get('attribute_id'));
}
protected function eventContainsObject($event) {
protected function eventContainsObject($event)
{
return $event->hasAttribute();
}
protected function hydrateObjectForm($object) {
protected function hydrateObjectForm($object)
{
$data = array(
'id' => $object->getId(),
@@ -121,44 +158,132 @@ class AttributeController extends AbstractCrudController
'postscriptum' => $object->getPostscriptum()
);
// Setup attributes values
/*
* FIXME : doesn't work. "We get a This form should not contain extra fields." error
$attr_av_list = AttributeAvQuery::create()
->joinWithI18n($this->getCurrentEditionLocale())
->filterByAttributeId($object->getId())
->find();
$attr_array = array();
foreach($attr_av_list as $attr_av) {
$attr_array[$attr_av->getId()] = $attr_av->getTitle();
}
$data['attribute_values'] = $attr_array;
*/
// Setup the object form
return new AttributeModificationForm($this->getRequest(), "form", $data);
}
protected function getObjectFromEvent($event) {
protected function getObjectFromEvent($event)
{
return $event->hasAttribute() ? $event->getAttribute() : null;
}
protected function getExistingObject() {
protected function getExistingObject()
{
return AttributeQuery::create()
->joinWithI18n($this->getCurrentEditionLocale())
->findOneById($this->getRequest()->get('attribute_id'));
}
protected function getObjectLabel($object) {
protected function getObjectLabel($object)
{
return $object->getTitle();
}
protected function getObjectId($object) {
protected function getObjectId($object)
{
return $object->getId();
}
protected function renderListTemplate($currentOrder) {
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 renderEditionTemplate()
{
return $this->render(
'attribute-edit',
array(
'attribute_id' => $this->getRequest()->get('attribute_id'),
'attributeav_order' => $this->getAttributeAvListOrder()
)
);
}
protected function redirectToListTemplate() {
protected function redirectToEditionTemplate()
{
$this->redirectToRoute(
"admin.configuration.attributes.update",
array(
'attribute_id' => $this->getRequest()->get('attribute_id'),
'attributeav_order' => $this->getAttributeAvListOrder()
)
);
}
protected function redirectToListTemplate()
{
$this->redirectToRoute('admin.configuration.attributes.default');
}
/**
* Get the Attribute value list order.
*
* @return string the current list order
*/
protected function getAttributeAvListOrder()
{
return $this->getListOrderFromSession(
'attributeav',
'attributeav_order',
'manual'
);
}
/**
* Add or Remove from all product templates
*/
protected function addRemoveFromAllTemplates($eventType)
{
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.attributes.update")) return $response;
try {
if (null !== $object = $this->getExistingObject()) {
$event = new AttributeEvent($object);
$this->dispatch($eventType, $event);
}
}
catch (\Exception $ex) {
// Any error
return $this->errorPage($ex);
}
$this->redirectToListTemplate();
}
/**
* Remove from all product templates
*/
public function removeFromAllTemplates()
{
return $this->addRemoveFromAllTemplates(TheliaEvents::ATTRIBUTE_REMOVE_FROM_ALL_TEMPLATES);
}
/**
* Add to all product templates
*/
public function addToAllTemplates()
{
return $this->addRemoveFromAllTemplates(TheliaEvents::ATTRIBUTE_ADD_TO_ALL_TEMPLATES);
}
}

View File

@@ -40,6 +40,8 @@ use Thelia\Form\BaseForm;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Log\Tlog;
use Symfony\Component\Routing\Router;
use Thelia\Model\Admin;
use Thelia\Core\Security\Token\CookieTokenProvider;
class BaseAdminController extends BaseController
{
@@ -97,7 +99,7 @@ class BaseAdminController extends BaseController
protected function errorPage($message)
{
if ($message instanceof \Exception) {
$message = sprintf($this->getTranslator()->trans("Sorry, an error occured: %msg"), array('msg' => $message->getMessage()));
$message = $this->getTranslator()->trans("Sorry, an error occured: %msg", array('%msg' => $message->getMessage()));
}
return $this->render('general_error', array(
@@ -273,6 +275,75 @@ class BaseAdminController extends BaseController
return $this->getCurrentEditionLang()->getLocale();
}
/**
* Return the current list order identifier for a given object name,
* updating in using the current request.
*
* @param unknown $objectName the object name (e.g. 'attribute', 'message')
* @param unknown $requestParameterName the name of the request parameter that defines the list order
* @param unknown $defaultListOrder the default order to use, if none is defined
* @param string $updateSession if true, the session will be updated with the current order.
*
* @return String the current liste order.
*/
protected function getListOrderFromSession($objectName, $requestParameterName, $defaultListOrder, $updateSession = true) {
$order = $defaultListOrder;
$orderSessionIdentifier = sprintf("admin.%s.currentListOrder", $objectName);
// Find the current order
$order = $this->getRequest()->get(
$requestParameterName,
$this->getSession()->get($orderSessionIdentifier, $defaultListOrder)
);
if ($updateSession) $this->getSession()->set($orderSessionIdentifier, $order);
return $order;
}
/**
* Create the remember me cookie for the given user.
*/
protected function createAdminRememberMeCookie(Admin $user)
{
$ctp = new CookieTokenProvider();
$cookieName = ConfigQuery::read('admin_remember_me_cookie_name', 'armcn');
$cookieExpiration = ConfigQuery::read('admin_remember_me_cookie_expiration', 2592000 /* 1 month */);
$ctp->createCookie($user, $cookieName, $cookieExpiration);
}
/**
* Get the rememberme key from the cookie.
*
* @return string hte key found, or null if no key was found.
*/
protected function getRememberMeKeyFromCookie()
{
// Check if we can authenticate the user with a cookie-based token
$cookieName = ConfigQuery::read('admin_remember_me_cookie_name', 'armcn');
$ctp = new CookieTokenProvider();
return $ctp->getKeyFromCookie($this->getRequest(), $cookieName);
}
/** Clear the remember me cookie.
*
*/
protected function clearRememberMeCookie() {
$ctp = new CookieTokenProvider();
$cookieName = ConfigQuery::read('admin_remember_me_cookie_name', 'armcn');
$ctp->clearCookie($cookieName);
}
/**
* Render the given template, and returns the result as an Http Response.
*
@@ -314,7 +385,7 @@ class BaseAdminController extends BaseController
'edit_language_id' => $edition_language->getId(),
'edit_language_locale' => $edition_language->getLocale(),
'current_url' => htmlspecialchars($this->getRequest()->getUri())
'current_url' => $this->getRequest()->getUri()
));
// Update the current edition language in session

View File

@@ -43,6 +43,7 @@ class ConfigController extends AbstractCrudController
parent::__construct(
'variable',
'name',
'order',
'admin.configuration.variables.view',
'admin.configuration.variables.create',

View File

@@ -43,6 +43,7 @@ class CurrencyController extends AbstractCrudController
parent::__construct(
'currency',
'manual',
'order',
'admin.configuration.currencies.view',
'admin.configuration.currencies.create',

View File

@@ -37,10 +37,12 @@ use Thelia\Form\MessageCreationForm;
*/
class MessageController extends AbstractCrudController
{
public function __construct() {
public function __construct()
{
parent::__construct(
'message',
null,
null, // no sort order change
null, // no sort order change
'admin.configuration.messages.view',
'admin.configuration.messages.create',
@@ -55,15 +57,18 @@ class MessageController extends AbstractCrudController
);
}
protected function getCreationForm() {
protected function getCreationForm()
{
return new MessageCreationForm($this->getRequest());
}
protected function getUpdateForm() {
protected function getUpdateForm()
{
return new MessageModificationForm($this->getRequest());
}
protected function getCreationEvent($formData) {
protected function getCreationEvent($formData)
{
$createEvent = new MessageCreateEvent();
$createEvent
@@ -76,7 +81,8 @@ class MessageController extends AbstractCrudController
return $createEvent;
}
protected function getUpdateEvent($formData) {
protected function getUpdateEvent($formData)
{
$changeEvent = new MessageUpdateEvent($formData['id']);
// Create and dispatch the change event
@@ -93,16 +99,18 @@ class MessageController extends AbstractCrudController
return $changeEvent;
}
protected function getDeleteEvent() {
protected function getDeleteEvent()
{
return new MessageDeleteEvent($this->getRequest()->get('message_id'));
}
protected function eventContainsObject($event) {
protected function eventContainsObject($event)
{
return $event->hasMessage();
}
protected function hydrateObjectForm($object) {
protected function hydrateObjectForm($object)
{
// Prepare the data that will hydrate the form
$data = array(
'id' => $object->getId(),
@@ -119,40 +127,48 @@ class MessageController extends AbstractCrudController
return new MessageModificationForm($this->getRequest(), "form", $data);
}
protected function getObjectFromEvent($event) {
protected function getObjectFromEvent($event)
{
return $event->hasMessage() ? $event->getMessage() : null;
}
protected function getExistingObject() {
protected function getExistingObject()
{
return MessageQuery::create()
->joinWithI18n($this->getCurrentEditionLocale())
->findOneById($this->getRequest()->get('message_id'));
}
protected function getObjectLabel($object) {
protected function getObjectLabel($object)
{
return $object->getName();
}
protected function getObjectId($object) {
protected function getObjectId($object)
{
return $object->getId();
}
protected function renderListTemplate($currentOrder) {
protected function renderListTemplate($currentOrder)
{
return $this->render('messages');
}
protected function renderEditionTemplate() {
protected function renderEditionTemplate()
{
return $this->render('message-edit', array('message_id' => $this->getRequest()->get('message_id')));
}
protected function redirectToEditionTemplate() {
protected function redirectToEditionTemplate()
{
$this->redirectToRoute(
"admin.configuration.messages.update",
array('message_id' => $this->getRequest()->get('message_id'))
);
}
protected function redirectToListTemplate() {
protected function redirectToListTemplate()
{
$this->redirectToRoute('admin.configuration.messages.default');
}
}

View File

@@ -30,11 +30,44 @@ use Thelia\Core\Security\Exception\AuthenticationException;
use Thelia\Tools\URL;
use Thelia\Tools\Redirect;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Security\Authentication\AdminTokenAuthenticator;
use Thelia\Core\Security\UserProvider\TokenProvider;
use Symfony\Component\HttpFoundation\Cookie;
use Thelia\Core\Security\UserProvider\CookieTokenProvider;
use Thelia\Core\Security\Exception\TokenAuthenticationException;
class SessionController extends BaseAdminController
{
public function showLoginAction()
{
// Check if we can authenticate the user with a cookie-based token
if (null !== $key = $this->getRememberMeKeyFromCookie()) {
// Create the authenticator
$authenticator = new AdminTokenAuthenticator($key);
try {
// If have found a user, store it in the security context
$user = $authenticator->getAuthentifiedUser();
$this->getSecurityContext()->setAdminUser($user);
$this->adminLogAppend("Successful token authentication");
// Update the cookie
$cookie = $this->createAdminRememberMeCookie($user);
// Render the home page
return $this->render("home");
}
catch (TokenAuthenticationException $ex) {
$this->adminLogAppend("Token based authentication failed.");
// Clear the cookie
$this->clearRememberMeCookie();
}
}
return $this->render("login");
}
@@ -44,6 +77,9 @@ class SessionController extends BaseAdminController
$this->getSecurityContext()->clearAdminUser();
// Clear the remember me cookie, if any
$this->clearRememberMeCookie();
// Go back to login page.
$this->redirectToRoute('admin.login');
}
@@ -68,10 +104,19 @@ class SessionController extends BaseAdminController
// Log authentication success
AdminLog::append("Authentication successful", $request, $user);
/**
* FIXME: we have tou find a way to send cookie
*/
if (intval($adminLoginForm->getForm()->get('remember_me')->getData()) > 0) {
// If a remember me field if present and set in the form, create
// the cookie thant store "remember me" information
$this->createAdminRememberMeCookie($user);
}
$this->dispatch(TheliaEvents::ADMIN_LOGIN);
// Redirect to the success URL
return Redirect::exec($adminLoginForm->getSuccessUrl());
// Redirect to the success URL, passing the cookie if one exists.
$this->redirect($adminLoginForm->getSuccessUrl());
} catch (FormValidationException $ex) {

View File

@@ -0,0 +1,196 @@
<?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\TemplateDeleteEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\TemplateUpdateEvent;
use Thelia\Core\Event\TemplateCreateEvent;
use Thelia\Model\TemplateQuery;
use Thelia\Form\TemplateModificationForm;
use Thelia\Form\TemplateCreationForm;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Model\TemplateAv;
use Thelia\Model\TemplateAvQuery;
use Thelia\Core\Event\TemplateAvUpdateEvent;
use Thelia\Core\Event\TemplateEvent;
/**
* Manages templates sent by mail
*
* @author Franck Allimant <franck@cqfdev.fr>
*/
class TemplateController extends AbstractCrudController
{
public function __construct()
{
parent::__construct(
'template',
null,
null,
'admin.configuration.templates.view',
'admin.configuration.templates.create',
'admin.configuration.templates.update',
'admin.configuration.templates.delete',
TheliaEvents::TEMPLATE_CREATE,
TheliaEvents::TEMPLATE_UPDATE,
TheliaEvents::TEMPLATE_DELETE,
null, // No visibility toggle
null // No position update
);
}
protected function getCreationForm()
{
return new TemplateCreationForm($this->getRequest());
}
protected function getUpdateForm()
{
return new TemplateModificationForm($this->getRequest());
}
protected function getCreationEvent($formData)
{
$createEvent = new TemplateCreateEvent();
$createEvent
->setTemplateName($formData['name'])
->setLocale($formData["locale"])
;
return $createEvent;
}
protected function getUpdateEvent($formData)
{
$changeEvent = new TemplateUpdateEvent($formData['id']);
// Create and dispatch the change event
$changeEvent
->setLocale($formData["locale"])
->setTemplateName($formData['name'])
;
// Add feature and attributes list
return $changeEvent;
}
protected function getDeleteEvent()
{
return new TemplateDeleteEvent($this->getRequest()->get('template_id'));
}
protected function eventContainsObject($event)
{
return $event->hasTemplate();
}
protected function hydrateObjectForm($object)
{
$data = array(
'id' => $object->getId(),
'locale' => $object->getLocale(),
'name' => $object->getName()
);
// Setup the object form
return new TemplateModificationForm($this->getRequest(), "form", $data);
}
protected function getObjectFromEvent($event)
{
return $event->hasTemplate() ? $event->getTemplate() : null;
}
protected function getExistingObject()
{
return TemplateQuery::create()
->joinWithI18n($this->getCurrentEditionLocale())
->findOneById($this->getRequest()->get('template_id'));
}
protected function getObjectLabel($object)
{
return $object->getName();
}
protected function getObjectId($object)
{
return $object->getId();
}
protected function renderListTemplate($currentOrder)
{
return $this->render('templates', array('order' => $currentOrder));
}
protected function renderEditionTemplate()
{
return $this->render(
'template-edit',
array(
'template_id' => $this->getRequest()->get('template_id'),
)
);
}
protected function redirectToEditionTemplate()
{
$this->redirectToRoute(
"admin.configuration.templates.update",
array(
'template_id' => $this->getRequest()->get('template_id'),
)
);
}
protected function redirectToListTemplate()
{
$this->redirectToRoute('admin.configuration.templates.default');
}
// Process delete failure, which may occurs if template is in use.
protected function performAdditionalDeleteAction($deleteEvent)
{
if ($deleteEvent->getProductCount() > 0) {
$this->getParserContext()->setGeneralError(
$this->getTranslator()->trans(
"This template is in use in some of your products, and cannot be deleted. Delete it from all your products and try again."
)
);
return $this->renderList();
}
// Normal delete processing
return null;
}
}