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

# By Manuel Raynaud (18) and others
# Via franck (9) and others
* 'master' of https://github.com/thelia/thelia: (39 commits)
  Working :
  Working :
  Working :
  Working :
  Fixed minor visual glitches
  Working : Resize countries flag + Add bootstrap-switch
  fix test suite
  clear asset cache in cache:cler command
  Added a 'development mode' to assetic smarty plugin
  rewriting router
  use good Request object
  Added Tools\URL test case, and a test case superclass for initializing Tools\URL
  remove unused UrlWritin controller
  create router for rewriting matching
  customer substitutions
  fix typo in front id
  Working : For attributes on labels
  Working : For attributes on labels
  add label_attr attribute to form smarty plugin
  start refactorin rewriting routing
  ...

Conflicts:
	core/lib/Thelia/Config/Resources/routing/front.xml
	templates/admin/default/assets/less/thelia/bootstrap-editable.less
	templates/admin/default/categories.html
This commit is contained in:
gmorel
2013-09-06 19:36:52 +02:00
118 changed files with 4702 additions and 1831 deletions

View File

@@ -85,10 +85,16 @@ class BaseAdminController extends BaseController
/**
* Return a general error page
*
* @param mixed $message a message string, or an exception instance
*
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function errorPage($message)
{
if ($message instanceof \Exception) {
$message = sprintf("Sorry, an error occured: %s", $message->getMessage());
}
return $this->render('general_error', array(
"error_message" => $message)
);
@@ -168,24 +174,31 @@ class BaseAdminController extends BaseController
* @param unknown $urlParameters the URL parametrs, as a var/value pair array
*/
public function redirectToRoute($routeId, $urlParameters = array()) {
$this->redirect(URL::absoluteUrl($this->getRoute($routeId), $urlParameters));
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId), $urlParameters));
}
/**
* Get the current edition lang ID, checking if a change was requested in the current request
* Get the current edition lang ID, checking if a change was requested in the current request.
*/
protected function getCurrentEditionLangId() {
return $this->getRequest()->get(
'edit_language_id',
$this->getSession()->getAdminEditionLangId()
);
protected function getCurrentEditionLang() {
// Return the new language if a change is required.
if (null !== $edit_language_id = $this->getRequest()->get('edit_language_id', null)) {
if (null !== $edit_language = LangQuery::create()->findOneById($edit_language_id)) {
return $edit_language;
}
}
// Otherwise return the lang stored in session.
return $this->getSession()->getAdminEditionLang();
}
/**
* A simple helper to get the current edition locale, from the session edition language ID
* A simple helper to get the current edition locale.
*/
protected function getCurrentEditionLocale() {
return LangQuery::create()->findOneById($this->getCurrentEditionLangId())->getLocale();
return $this->getCurrentEditionLang()->getLocale();
}
/**
@@ -217,23 +230,14 @@ class BaseAdminController extends BaseController
$session = $this->getSession();
$edition_language = $this->getCurrentEditionLangId();
// Current back-office (not edition) language
$current_lang = LangQuery::create()->findOneById($session->getLangId());
// Find the current edit language ID
$edition_language = LangQuery::create()->findOneById($this->getCurrentEditionLangId());
$edition_language = $this->getCurrentEditionLang();
// Prepare common template variables
$args = array_merge($args, array(
'locale' => $session->getLocale(),
'lang_code' => $session->getLang(),
'lang_id' => $session->getLangId(),
'datetime_format' => $current_lang->getDateTimeFormat(),
'date_format' => $current_lang->getDateFormat(),
'time_format' => $current_lang->getTimeFormat(),
'locale' => $session->getLang()->getLocale(),
'lang_code' => $session->getLang()->getCode(),
'lang_id' => $session->getLang()->getId(),
'edit_language_id' => $edition_language->getId(),
'edit_language_locale' => $edition_language->getLocale(),
@@ -242,7 +246,7 @@ class BaseAdminController extends BaseController
));
// Update the current edition language in session
$this->getSession()->setAdminEditionLangId($edition_language->getId());
$this->getSession()->setAdminEditionLang($edition_language);
// Render the template.
try {
@@ -253,7 +257,7 @@ class BaseAdminController extends BaseController
catch (AuthenticationException $ex) {
// User is not authenticated, and templates requires authentication -> redirect to login page
// We user login_tpl as a path, not a template.
Redirect::exec(URL::absoluteUrl($ex->getLoginTemplate()));
Redirect::exec(URL::getInstance()->absoluteUrl($ex->getLoginTemplate()));
}
catch (AuthorizationException $ex) {
// User is not allowed to perform the required action. Return the error page instead of the requested page.

View File

@@ -26,7 +26,7 @@ namespace Thelia\Controller\Admin;
use Thelia\Core\Event\ConfigDeleteEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Tools\URL;
use Thelia\Core\Event\ConfigChangeEvent;
use Thelia\Core\Event\ConfigUpdateEvent;
use Thelia\Core\Event\ConfigCreateEvent;
use Thelia\Log\Tlog;
use Thelia\Form\Exception\FormValidationException;
@@ -154,7 +154,7 @@ class ConfigController extends BaseAdminController
public function changeAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.variables.change")) return $response;
if (null !== $response = $this->checkAuth("admin.configuration.variables.update")) return $response;
// Load the config object
$config = ConfigQuery::create()
@@ -196,7 +196,7 @@ class ConfigController extends BaseAdminController
public function saveChangeAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.variables.change")) return $response;
if (null !== $response = $this->checkAuth("admin.configuration.variables.update")) return $response;
$message = false;
@@ -214,7 +214,7 @@ class ConfigController extends BaseAdminController
// Get the form field values
$data = $form->getData();
$changeEvent = new ConfigChangeEvent($data['id']);
$changeEvent = new ConfigUpdateEvent($data['id']);
// Create and dispatch the change event
$changeEvent
@@ -284,13 +284,13 @@ class ConfigController extends BaseAdminController
public function changeValuesAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.variables.change")) return $response;
if (null !== $response = $this->checkAuth("admin.configuration.variables.update")) return $response;
$variables = $this->getRequest()->get('variable', array());
// Process all changed variables
foreach($variables as $id => $value) {
$event = new ConfigChangeEvent($id);
$event = new ConfigUpdateEvent($id);
$event->setValue($value);
$this->dispatch(TheliaEvents::CONFIG_SETVALUE, $event);

View File

@@ -26,7 +26,7 @@ namespace Thelia\Controller\Admin;
use Thelia\Core\Event\CurrencyDeleteEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Tools\URL;
use Thelia\Core\Event\CurrencyChangeEvent;
use Thelia\Core\Event\CurrencyUpdateEvent;
use Thelia\Core\Event\CurrencyCreateEvent;
use Thelia\Log\Tlog;
use Thelia\Form\Exception\FormValidationException;
@@ -34,6 +34,7 @@ use Thelia\Core\Security\Exception\AuthorizationException;
use Thelia\Model\CurrencyQuery;
use Thelia\Form\CurrencyModificationForm;
use Thelia\Form\CurrencyCreationForm;
use Thelia\Core\Event\CurrencyUpdatePositionEvent;
/**
* Manages currencies sent by mail
@@ -124,7 +125,7 @@ class CurrencyController extends BaseAdminController
}
catch (\Exception $ex) {
// Any other error
$error_msg = sprintf("Sorry, an error occured: %s", $ex->getMessage());
$error_msg = $ex;
}
if ($error_msg !== false) {
@@ -153,7 +154,7 @@ class CurrencyController extends BaseAdminController
public function changeAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response;
if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response;
// Load the currency object
$currency = CurrencyQuery::create()
@@ -191,7 +192,7 @@ class CurrencyController extends BaseAdminController
public function saveChangeAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response;
if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response;
$error_msg = false;
@@ -209,7 +210,7 @@ class CurrencyController extends BaseAdminController
// Get the form field values
$data = $form->getData();
$changeEvent = new CurrencyChangeEvent($data['id']);
$changeEvent = new CurrencyUpdateEvent($data['id']);
// Create and dispatch the change event
$changeEvent
@@ -231,7 +232,7 @@ class CurrencyController extends BaseAdminController
// just redirect to the edit page again.
if ($this->getRequest()->get('save_mode') == 'stay') {
$this->redirectToRoute(
"admin.configuration.currencies.change",
"admin.configuration.currencies.update",
array('currency_id' => $currency_id)
);
}
@@ -245,7 +246,7 @@ class CurrencyController extends BaseAdminController
}
catch (\Exception $ex) {
// Any other error
$error_msg = sprintf("Sorry, an error occured: %s", $ex->getMessage());
$error_msg = $ex;
}
if ($error_msg !== false) {
@@ -271,9 +272,9 @@ class CurrencyController extends BaseAdminController
*/
public function setDefaultAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response;
if (null !== $response = $this->checkAuth("admin.configuration.currencies.update")) return $response;
$changeEvent = new CurrencyChangeEvent($this->getRequest()->get('currency_id', 0));
$changeEvent = new CurrencyUpdateEvent($this->getRequest()->get('currency_id', 0));
// Create and dispatch the change event
$changeEvent->setIsDefault(true);
@@ -283,7 +284,7 @@ class CurrencyController extends BaseAdminController
}
catch (\Exception $ex) {
// Any error
return $this->errorPage(sprintf("Sorry, an error occured: %s", $ex->getMessage()));
return $this->errorPage($ex);
}
$this->redirectToRoute('admin.configuration.currencies.default');
@@ -294,19 +295,55 @@ class CurrencyController extends BaseAdminController
*/
public function updateRatesAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response;
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(sprintf("Sorry, an error occured: %s", $ex->getMessage()));
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
*

View File

@@ -26,7 +26,7 @@ namespace Thelia\Controller\Admin;
use Thelia\Core\Event\MessageDeleteEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Tools\URL;
use Thelia\Core\Event\MessageChangeEvent;
use Thelia\Core\Event\MessageUpdateEvent;
use Thelia\Core\Event\MessageCreateEvent;
use Thelia\Log\Tlog;
use Thelia\Form\Exception\FormValidationException;
@@ -133,7 +133,7 @@ class MessageController extends BaseAdminController
public function changeAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.messages.change")) return $response;
if (null !== $response = $this->checkAuth("admin.configuration.messages.update")) return $response;
// Load the message object
$message = MessageQuery::create()
@@ -173,7 +173,7 @@ class MessageController extends BaseAdminController
public function saveChangeAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.messages.change")) return $response;
if (null !== $response = $this->checkAuth("admin.configuration.messages.update")) return $response;
$message = false;
@@ -191,7 +191,7 @@ class MessageController extends BaseAdminController
// Get the form field values
$data = $form->getData();
$changeEvent = new MessageChangeEvent($data['id']);
$changeEvent = new MessageUpdateEvent($data['id']);
// Create and dispatch the change event
$changeEvent
@@ -215,7 +215,7 @@ class MessageController extends BaseAdminController
// just redirect to the edit page again.
if ($this->getRequest()->get('save_mode') == 'stay') {
$this->redirectToRoute(
"admin.configuration.messages.change",
"admin.configuration.messages.update",
array('message_id' => $message_id)
);
}
@@ -265,6 +265,6 @@ class MessageController extends BaseAdminController
$this->dispatch(TheliaEvents::MESSAGE_DELETE, $event);
$this->redirect(URL::adminViewUrl('messages'));
$this->redirect(URL::getInstance()->adminViewUrl('messages'));
}
}