Conflicts:
	core/lib/Thelia/Controller/BaseController.php
This commit is contained in:
franck
2013-09-03 19:03:27 +02:00
39 changed files with 854 additions and 183 deletions

View File

@@ -34,6 +34,8 @@ use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\CurrencyChangeEvent;
use Thelia\Core\Event\CurrencyCreateEvent;
use Thelia\Core\Event\CurrencyDeleteEvent;
use Thelia\Model\Map\CurrencyTableMap;
use Thelia\Model\ConfigQuery;
class Currency extends BaseAction implements EventSubscriberInterface
{
@@ -53,7 +55,7 @@ class Currency extends BaseAction implements EventSubscriberInterface
->setName($event->getCurrencyName())
->setSymbol($event->getSymbol())
->setRate($event->getRate())
->setCode($event->getCode())
->setCode(strtoupper($event->getCode()))
->save()
;
@@ -79,7 +81,7 @@ class Currency extends BaseAction implements EventSubscriberInterface
->setName($event->getCurrencyName())
->setSymbol($event->getSymbol())
->setRate($event->getRate())
->setCode($event->getCode())
->setCode(strtoupper($event->getCode()))
->save();
@@ -87,6 +89,32 @@ class Currency extends BaseAction implements EventSubscriberInterface
}
}
/**
* Set the default currency
*
* @param CurrencyChangeEvent $event
*/
public function setDefault(CurrencyChangeEvent $event)
{
$search = CurrencyQuery::create();
if (null !== $currency = CurrencyQuery::create()->findOneById($event->getCurrencyId())) {
if ($currency->getByDefault() != $event->getIsDefault()) {
// Reset default status
CurrencyQuery::create()->filterByByDefault(true)->update(array('ByDefault' => false));
$currency
->setByDefault($event->getIsDefault())
->save()
;
}
$event->setCurrency($currency);
}
}
/**
* Delete a currencyuration entry
*
@@ -106,6 +134,29 @@ class Currency extends BaseAction implements EventSubscriberInterface
}
}
public function updateRates() {
$rates_url = ConfigQuery::read('currency_rate_update_url', 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml');
$rate_data = file_get_contents($rates_url);
if ($rate_data && $sxe = new \SimpleXMLElement($rate_data)) {
foreach ($sxe->Cube[0]->Cube[0]->Cube as $last)
{
$code = strtoupper($last["currency"]);
$rate = floatval($last['rate']);
if (null !== $currency = CurrencyQuery::create()->findOneByCode($code)) {
$currency->setRate($rate)->save();
}
}
}
else {
throw new \RuntimeException(sprintf("Failed to get currency rates data from URL %s", $url));
}
}
/**
* {@inheritDoc}
*/
@@ -115,6 +166,9 @@ class Currency extends BaseAction implements EventSubscriberInterface
TheliaEvents::CURRENCY_CREATE => array("create", 128),
TheliaEvents::CURRENCY_MODIFY => array("modify", 128),
TheliaEvents::CURRENCY_DELETE => array("delete", 128),
TheliaEvents::CURRENCY_SET_DEFAULT => array("setDefault", 128),
TheliaEvents::CURRENCY_UPDATE_RATES => array("updateRates", 128),
);
}
}

View File

@@ -101,6 +101,14 @@
<default key="_controller">Thelia\Controller\Admin\CurrencyController::saveChangeAction</default>
</route>
<route id="admin.configuration.currencies.set-default" path="/admin/configuration/currencies/set-default">
<default key="_controller">Thelia\Controller\Admin\CurrencyController::setDefaultAction</default>
</route>
<route id="admin.configuration.currencies.update-rates" path="/admin/configuration/currencies/update-rates">
<default key="_controller">Thelia\Controller\Admin\CurrencyController::updateRatesAction</default>
</route>
<route id="admin.configuration.currencies.delete" path="/admin/configuration/currencies/delete">
<default key="_controller">Thelia\Controller\Admin\CurrencyController::deleteAction</default>
</route>

View File

@@ -40,4 +40,8 @@
<default key="_controller">Thelia\Controller\Front\CartController::changeItem</default>
<default key="_view">cart</default>
</route>
<route id="url-rewriting.check" path="/{rewritten_url}" methods="GET">
<default key="_controller">Thelia\Controller\Front\UrlRewritingController::check</default>
</route>
</routes>

View File

@@ -150,6 +150,27 @@ class BaseAdminController extends BaseController
return $this->container->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
}
/**
* Return the route path defined for the givent route ID
*
* @param string $routeId a route ID, as defines in Config/Resources/routing/admin.xml
*
* @see \Thelia\Controller\BaseController::getRouteFromRouter()
*/
protected function getRoute($routeId) {
return $this->getRouteFromRouter('router.admin', $routeId);
}
/**
* Redirect to à route ID related URL
*
* @param unknown $routeId the route ID, as found in Config/Resources/routing/admin.xml
* @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));
}
/**
* Get the current edition lang ID, checking if a change was requested in the current request
*/

View File

@@ -239,10 +239,11 @@ class ConfigController extends BaseAdminController
// 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->redirect(URL::absoluteUrl(
"admin/configuration/variables/change",
$this->redirectToRoute(
"admin.configuration.variables.change",
array('variable_id' => $variable_id)
));
);
}
// Redirect to the success URL
@@ -295,7 +296,7 @@ class ConfigController extends BaseAdminController
$this->dispatch(TheliaEvents::CONFIG_SETVALUE, $event);
}
$this->redirect(URL::absoluteUrl('/admin/configuration/variables'));
$this->redirectToRoute('admin.configuration.variables.default');
}
/**
@@ -313,6 +314,6 @@ class ConfigController extends BaseAdminController
$this->dispatch(TheliaEvents::CONFIG_DELETE, $event);
$this->redirect(URL::absoluteUrl('/admin/configuration/variables'));
$this->redirectToRoute('admin.configuration.variables.default');
}
}

View File

@@ -83,7 +83,7 @@ class CurrencyController extends BaseAdminController
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.currencies.create")) return $response;
$currency = false;
$error_msg = false;
// Create the Creation Form
$creationForm = new CurrencyCreationForm($this->getRequest());
@@ -120,24 +120,28 @@ class CurrencyController extends BaseAdminController
}
catch (FormValidationException $ex) {
// Form cannot be validated
$currency = sprintf("Please check your input: %s", $ex->getCurrency());
$error_msg = sprintf("Please check your input: %s", $ex->getMessage());
}
catch (\Exception $ex) {
// Any other error
$currency = sprintf("Sorry, an error occured: %s", $ex->getCurrency());
$error_msg = sprintf("Sorry, an error occured: %s", $ex->getMessage());
var_dump($ex);
exit;
}
if ($currency !== false) {
if ($error_msg !== false) {
// An error has been detected: log it
Tlog::getInstance()->error(sprintf("Error during currency creation process : %s. Exception was %s", $currency, $ex->getCurrency()));
Tlog::getInstance()->error(sprintf("Error during currency creation process : %s. Exception was %s", $error_msg, $ex->getMessage()));
// Mark the form as errored
$creationForm->setErrorCurrency($currency);
$creationForm->setErrorMessage($error_msg);
// Pass it to the parser, along with the error currency
$this->getParserContext()
->addForm($creationForm)
->setGeneralError($currency)
->setGeneralError($error_msg)
;
}
@@ -169,7 +173,7 @@ class CurrencyController extends BaseAdminController
'locale' => $currency->getLocale(),
'code' => $currency->getCode(),
'symbol' => $currency->getSymbol(),
'rate' => $currency->getSubject()
'rate' => $currency->getRate()
);
// Setup the object form
@@ -193,7 +197,7 @@ class CurrencyController extends BaseAdminController
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response;
$currency = false;
$error_msg = false;
// Create the form from the request
$changeForm = new CurrencyModificationForm($this->getRequest());
@@ -230,10 +234,10 @@ class CurrencyController extends BaseAdminController
// 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->redirect(URL::absoluteUrl(
"admin/configuration/currencies/change",
$this->redirectToRoute(
"admin.configuration.currencies.change",
array('currency_id' => $currency_id)
));
);
}
// Redirect to the success URL
@@ -241,24 +245,24 @@ class CurrencyController extends BaseAdminController
}
catch (FormValidationException $ex) {
// Invalid data entered
$currency = sprintf("Please check your input: %s", $ex->getCurrency());
$error_msg = sprintf("Please check your input: %s", $ex->getMessage());
}
catch (\Exception $ex) {
// Any other error
$currency = sprintf("Sorry, an error occured: %s", $ex->getCurrency());
$error_msg = sprintf("Sorry, an error occured: %s", $ex->getMessage());
}
if ($currency !== false) {
if ($error_msg !== false) {
// Log error currency
Tlog::getInstance()->error(sprintf("Error during currency modification process : %s. Exception was %s", $currency, $ex->getCurrency()));
Tlog::getInstance()->error(sprintf("Error during currency modification process : %s. Exception was %s", $error_msg, $ex->getMessage()));
// Mark the form as errored
$changeForm->setErrorCurrency($currency);
$changeForm->setErrorMessage($error_msg);
// Pas the form and the error to the parser
$this->getParserContext()
->addForm($changeForm)
->setGeneralError($currency)
->setGeneralError($error_msg)
;
}
@@ -266,6 +270,47 @@ class CurrencyController extends BaseAdminController
return $this->render('currency-edit', array('currency_id' => $currency_id));
}
/**
* Sets the default currency
*/
public function setDefaultAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response;
$changeEvent = new CurrencyChangeEvent($this->getRequest()->get('currency_id', 0));
// Create and dispatch the change event
$changeEvent->setIsDefault(true);
try {
$this->dispatch(TheliaEvents::CURRENCY_SET_DEFAULT, $changeEvent);
}
catch (\Exception $ex) {
// Any error
return $this->errorPage(sprintf("Sorry, an error occured: %s", $ex->getMessage()));
}
$this->redirectToRoute('admin.configuration.currencies.default');
}
/**
* Update currencies rates
*/
public function updateRatesAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) 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()));
}
$this->redirectToRoute('admin.configuration.currencies.default');
}
/**
* Delete a currency object
*
@@ -281,6 +326,6 @@ class CurrencyController extends BaseAdminController
$this->dispatch(TheliaEvents::CURRENCY_DELETE, $event);
$this->redirect(URL::adminViewUrl('currencies'));
$this->redirectToRoute('admin.configuration.currencies.default');
}
}

View File

@@ -214,10 +214,10 @@ class MessageController extends BaseAdminController
// 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->redirect(URL::absoluteUrl(
"admin/configuration/messages/change",
$this->redirectToRoute(
"admin.configuration.messages.change",
array('message_id' => $message_id)
));
);
}
// Redirect to the success URL

View File

@@ -46,7 +46,7 @@ class SessionController extends BaseAdminController
$this->getSecurityContext()->clearAdminUser();
// Go back to login page.
return Redirect::exec(URL::absoluteUrl('/admin/login')); // FIXME - should be a parameter
$this->redirectToRoute('admin.login');
}
public function checkLoginAction()

View File

@@ -37,6 +37,7 @@ use Thelia\Form\Exception\FormValidationException;
use Symfony\Component\EventDispatcher\Event;
use Thelia\Core\Event\DefaultActionEvent;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
*
@@ -178,9 +179,9 @@ class BaseController extends ContainerAware
*
* @param string $url
*/
public function redirect($url)
public function redirect($url, $status = 302)
{
Redirect::exec($url);
Redirect::exec($url, $status);
}
/**
@@ -217,4 +218,13 @@ class BaseController extends ContainerAware
return $route->getPath();
}
/**
* Return a 404 error
*
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function pageNotFound()
{
}
}

View File

@@ -26,4 +26,24 @@ use Thelia\Controller\BaseController;
class BaseFrontController extends BaseController
{
/**
* Return the route path defined for the givent route ID
*
* @param string $routeId a route ID, as defines in Config/Resources/routing/front.xml
*
* @see \Thelia\Controller\BaseController::getRouteFromRouter()
*/
protected function getRoute($routeId) {
return $this->getRouteFromRouter('router.front', $routeId);
}
/**
* Redirect to à route ID related URL
*
* @param unknown $routeId the route ID, as found in Config/Resources/routing/admin.xml
* @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));
}
}

View File

@@ -23,6 +23,9 @@
namespace Thelia\Controller\Front;
use Symfony\Component\HttpFoundation\Request;
use Thelia\Model\ConfigQuery;
use Thelia\Tools\Redirect;
use Thelia\Tools\URL;
/**
*
@@ -43,6 +46,16 @@ class DefaultController extends BaseFrontController
*/
public function noAction(Request $request)
{
if(ConfigQuery::isRewritingEnable()) {
/* Does the query GET parameters match a rewritten URL ? */
$rewrittenUrl = URL::init()->retrieveCurrent($request);
if($rewrittenUrl->rewrittenUrl !== null) {
/* 301 redirection to rewritten URL */
$this->redirect($rewrittenUrl->rewrittenUrl, 301);
}
}
if (! $view = $request->query->get('view')) {
$view = "index";
if ($request->request->has('view')) {

View File

@@ -0,0 +1,81 @@
<?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\Front;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Exception\UrlRewritingException;
use Thelia\Model\ConfigQuery;
use Thelia\Tools\URL;
class UrlRewritingController extends BaseFrontController
{
public function check(Request $request, $rewritten_url)
{
if(ConfigQuery::isRewritingEnable()) {
try {
$rewrittenUrlData = URL::init()->resolve($rewritten_url);
} catch(UrlRewritingException $e) {
switch($e->getCode()) {
case UrlRewritingException::URL_NOT_FOUND :
return $this->pageNotFound();
break;
default:
throw $e;
}
}
/* is the URL redirected ? */
if(null !== $rewrittenUrlData->redirectedToUrl) {
$this->redirect($rewrittenUrlData->redirectedToUrl, 301);
}
/* define GET arguments in request */
if(null !== $rewrittenUrlData->view) {
$request->query->set('view', $rewrittenUrlData->view);
if(null !== $rewrittenUrlData->viewId) {
$request->query->set($rewrittenUrlData->view . '_id', $rewrittenUrlData->viewId);
}
}
if(null !== $rewrittenUrlData->locale) {
$request->query->set('locale', $rewrittenUrlData->locale);
}
foreach($rewrittenUrlData->otherParameters as $parameter => $value) {
$request->query->set($parameter, $value);
}
}
if (! $view = $request->query->get('view')) {
$view = "index";
if ($request->request->has('view')) {
$view = $request->request->get('view');
}
}
$request->attributes->set('_view', $view);
}
}

View File

@@ -27,6 +27,7 @@ use Thelia\Model\Currency;
class CurrencyChangeEvent extends CurrencyCreateEvent
{
protected $currency_id;
protected $is_default;
public function __construct($currency_id)
{
@@ -44,4 +45,16 @@ class CurrencyChangeEvent extends CurrencyCreateEvent
return $this;
}
public function getIsDefault()
{
return $this->is_default;
}
public function setIsDefault($is_default)
{
$this->is_default = $is_default;
return $this;
}
}

View File

@@ -65,6 +65,8 @@ class CurrencyCreateEvent extends CurrencyEvent
public function setSymbol($symbol)
{
$this->symbol = $symbol;
return $this;
}
public function getCode()

View File

@@ -214,6 +214,8 @@ final class TheliaEvents
const CURRENCY_CREATE = "action.createCurrency";
const CURRENCY_MODIFY = "action.changeCurrency";
const CURRENCY_DELETE = "action.deleteCurrency";
const CURRENCY_SET_DEFAULT = "action.setDefaultCurrency";
const CURRENCY_UPDATE_RATES = "action.updateCurrencyRates";
const BEFORE_CREATECURRENCY = "action.before_createCurrency";
const AFTER_CREATECURRENCY = "action.after_createCurrency";

View File

@@ -114,22 +114,24 @@ class Address extends BaseLoop
foreach ($addresses as $address) {
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $address->getId());
$loopResultRow->set("NAME", $address->getName());
$loopResultRow->set("CUSTOMER", $address->getCustomerId());
$loopResultRow->set("TITLE", $address->getTitleId());
$loopResultRow->set("COMPANY", $address->getCompany());
$loopResultRow->set("FIRSTNAME", $address->getFirstname());
$loopResultRow->set("LASTNAME", $address->getLastname());
$loopResultRow->set("ADDRESS1", $address->getAddress1());
$loopResultRow->set("ADDRESS2", $address->getAddress2());
$loopResultRow->set("ADDRESS3", $address->getAddress3());
$loopResultRow->set("ZIPCODE", $address->getZipcode());
$loopResultRow->set("CITY", $address->getCity());
$loopResultRow->set("COUNTRY", $address->getCountryId());
$loopResultRow->set("PHONE", $address->getPhone());
$loopResultRow->set("CELLPHONE", $address->getCellphone());
$loopResultRow->set("DEFAULT", $address->getIsDefault());
$loopResultRow
->set("ID", $address->getId())
->set("NAME", $address->getName())
->set("CUSTOMER", $address->getCustomerId())
->set("TITLE", $address->getTitleId())
->set("COMPANY", $address->getCompany())
->set("FIRSTNAME", $address->getFirstname())
->set("LASTNAME", $address->getLastname())
->set("ADDRESS1", $address->getAddress1())
->set("ADDRESS2", $address->getAddress2())
->set("ADDRESS3", $address->getAddress3())
->set("ZIPCODE", $address->getZipcode())
->set("CITY", $address->getCity())
->set("COUNTRY", $address->getCountryId())
->set("PHONE", $address->getPhone())
->set("CELLPHONE", $address->getCellphone())
->set("DEFAULT", $address->getIsDefault())
;
$loopResult->addRow($loopResultRow);
}

View File

@@ -107,8 +107,6 @@ class CategoryTree extends BaseI18nLoop
$visible = $this->getVisible();
$exclude = $this->getExclude();
//echo "exclude=".print_r($exclude);
$loopResult = new LoopResult();
$this->buildCategoryTree($id, $visible, 0, $depth, $exclude, $loopResult);

View File

@@ -164,8 +164,12 @@ class Config extends BaseI18nLoop
->set("POSTSCRIPTUM" , $result->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("HIDDEN" , $result->getHidden())
->set("SECURED" , $result->getSecured())
->set("CREATE_DATE" , $result->getCreatedAt())
->set("UPDATE_DATE" , $result->getUpdatedAt())
->set("VERSION" , $result->getVersion())
->set("VERSION_DATE" , $result->getVersionCreatedAt())
->set("VERSION_AUTHOR" , $result->getVersionCreatedBy())
;
$loopResult->addRow($loopResultRow);

View File

@@ -177,7 +177,11 @@ class Currency extends BaseI18nLoop
->set("SYMBOL" , $currency->getSymbol())
->set("RATE" , $currency->getRate())
->set("POSITION" , $currency->getPosition())
->set("IS_DEFAULT" , $currency->getByDefault());
->set("IS_DEFAULT" , $currency->getByDefault())
->set("CREATE_DATE" , $currency->getCreatedAt())
->set("UPDATE_DATE" , $currency->getUpdatedAt())
;
$loopResult->addRow($loopResultRow);
}

View File

@@ -519,6 +519,12 @@ class Product extends BaseI18nLoop
->set("IS_PROMO", $product->getVirtualColumn('main_product_is_promo'))
->set("IS_NEW", $product->getVirtualColumn('main_product_is_new'))
->set("POSITION", $product->getPosition())
->set("CREATE_DATE", $category->getCreatedAt())
->set("UPDATE_DATE", $category->getUpdatedAt())
->set("VERSION", $category->getVersion())
->set("VERSION_DATE", $category->getVersionCreatedAt())
->set("VERSION_AUTHOR", $category->getVersionCreatedBy())
;
$loopResult->addRow($loopResultRow);

View File

@@ -169,7 +169,9 @@ class UrlGenerator extends AbstractSmartyPlugin
protected function getCurrentUrl()
{
return URL::retrieveCurrent($this->request);
$retriever = URL::init()->retrieveCurrent($this->request);
return $retriever->rewrittenUrl === null ? $retriever->url : $retriever->rewrittenUrl ;
}
protected function getReturnToUrl()

View File

@@ -0,0 +1,42 @@
<?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\Exception;
use Thelia\Log\Tlog;
class UrlRewritingException extends \Exception
{
const UNKNOWN_EXCEPTION = 0;
const URL_NOT_FOUND = 404;
const RESOLVER_NULL_SEARCH = 800;
public function __construct($message, $code = null, $previous = null) {
if($code === null) {
$code = self::UNKNOWN_EXCEPTION;
}
parent::__construct($message, $code, $previous);
}
}

View File

@@ -40,8 +40,8 @@ class CurrencyCreationForm extends BaseForm
}
$this->formBuilder
->add("name" , "text" , array("constraints" => array($name_constraints)))
->add("locale" , "text" , array())
->add("name" , "text" , array("constraints" => $name_constraints))
->add("locale" , "text" , array("constraints" => array(new NotBlank())))
->add("symbol" , "text" , array("constraints" => array(new NotBlank())))
->add("rate" , "text" , array("constraints" => array(new NotBlank())))
->add("code" , "text" , array("constraints" => array(new NotBlank())))

View File

@@ -22,7 +22,7 @@ class Category extends BaseCategory
public function getUrl($locale)
{
return URL::retrieve('category', $this->getId(), $locale);
return URL::init()->retrieve('category', $this->getId(), $locale);
}
/**

View File

@@ -9,6 +9,6 @@ class Content extends BaseContent
{
public function getUrl($locale)
{
return URL::retrieve('content', $this->getId(), $locale);
return URL::init()->retrieve('content', $this->getId(), $locale);
}
}

View File

@@ -17,7 +17,7 @@ class Folder extends BaseFolder
public function getUrl($locale)
{
return URL::retrieve('folder', $this->getId(), $locale);
return URL::init()->retrieve('folder', $this->getId(), $locale);
}
/**

View File

@@ -9,6 +9,6 @@ class Product extends BaseProduct
{
public function getUrl($locale)
{
return URL::retrieve('product', $this->getId(), $locale);
return URL::init()->retrieve('product', $this->getId(), $locale);
}
}

View File

@@ -2,8 +2,10 @@
namespace Thelia\Model;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Thelia\Model\Base\RewritingUrlQuery as BaseRewritingUrlQuery;
use Thelia\Model\Map\RewritingUrlTableMap;
/**
* Skeleton subclass for performing query and update operations on the 'rewriting_url' table.
@@ -15,6 +17,96 @@ use Thelia\Model\Base\RewritingUrlQuery as BaseRewritingUrlQuery;
* long as it does not already exist in the output directory.
*
*/
class RewritingUrlQuery extends BaseRewritingUrlQuery {
class RewritingUrlQuery extends BaseRewritingUrlQuery
{
/**
* @param $rewrittenUrl
*
* @return array|mixed|\Propel\Runtime\Collection\ObjectCollection
*/
public function getResolverSearch($rewrittenUrl)
{
$redirectedJoin = new Join();
$redirectedJoin->addExplicitCondition(RewritingUrlTableMap::TABLE_NAME, 'REDIRECTED', 'ru', RewritingUrlTableMap::TABLE_NAME, 'ID', 'is_redirected');
$redirectedJoin->setJoinType(Criteria::LEFT_JOIN);
$search = RewritingArgumentQuery::create()
->joinRewritingUrl('ru', Criteria::RIGHT_JOIN)
->addJoinObject($redirectedJoin)
->where('`ru`.URL = ?', $rewrittenUrl, \PDO::PARAM_STR)
->withColumn('`ru`.URL', 'ru_url')
->withColumn('`ru`.VIEW', 'ru_view')
->withColumn('`ru`.VIEW_LOCALE', 'ru_locale')
->withColumn('`ru`.VIEW_ID', 'ru_viewId')
->withColumn('`is_redirected`.URL', 'ru_redirected_to_url')
->find();
return $search;
}
/**
* @param $view
* @param $viewId
* @param $viewLocale
*
* @return null|RewritingUrl
*/
public function getViewUrlQuery($view, $viewLocale, $viewId)
{
return RewritingUrlQuery::create()
->joinRewritingArgument('ra', Criteria::LEFT_JOIN)
->where('ISNULL(`ra`.REWRITING_URL_ID)')
->filterByView($view)
->filterByViewLocale($viewLocale)
->filterByViewId($viewId)
->filterByRedirected(null)
->orderByUpdatedAt(Criteria::DESC)
->findOne();
}
/**
* @param $view
* @param $viewLocale
* @param $viewId
* @param $viewOtherParameters
*
* @return null|RewritingUrl
*/
public function getSpecificUrlQuery($view, $viewLocale, $viewId, $viewOtherParameters)
{
$urlQuery = RewritingUrlQuery::create()
->joinRewritingArgument('ra', Criteria::LEFT_JOIN)
->withColumn('`ra`.REWRITING_URL_ID', 'ra_REWRITING_URL_ID')
->filterByView($view)
->filterByViewLocale($viewLocale)
->filterByViewId($viewId)
->filterByRedirected(null)
->orderByUpdatedAt(Criteria::DESC);
$otherParametersCount = count($viewOtherParameters);
if($otherParametersCount > 0) {
$parameterConditions = array();
foreach($viewOtherParameters as $parameter => $value) {
$conditionName = 'other_parameter_condition_' . count($parameterConditions);
$urlQuery->condition('parameter_condition', '`ra`.PARAMETER= ?', $parameter, \PDO::PARAM_STR)
->condition('value_condition', '`ra`.VALUE = ?', $value, \PDO::PARAM_STR)
->combine(array('parameter_condition', 'value_condition'), Criteria::LOGICAL_AND, $conditionName);
$parameterConditions[] = $conditionName;
}
$urlQuery->where($parameterConditions, Criteria::LOGICAL_OR);
$urlQuery->groupBy(RewritingUrlTableMap::ID);
$urlQuery->condition('count_condition_1', 'COUNT(' . RewritingUrlTableMap::ID . ') = ?', $otherParametersCount, \PDO::PARAM_INT) // ensure we got all the asked parameters (provided by the query)
->condition('count_condition_2', 'COUNT(' . RewritingUrlTableMap::ID . ') = (SELECT COUNT(*) FROM rewriting_argument WHERE rewriting_argument.REWRITING_URL_ID = ra_REWRITING_URL_ID)'); // ensure we don't miss any parameters (needed to match the rewritten url)
$urlQuery->having(array('count_condition_1', 'count_condition_2'), Criteria::LOGICAL_AND);
} else {
$urlQuery->where('ISNULL(`ra`.REWRITING_URL_ID)');
}
return $urlQuery->findOne();
}
} // RewritingUrlQuery

View File

@@ -22,6 +22,13 @@
/*************************************************************************************/
namespace Thelia\Rewriting;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Thelia\Exception\RewritingUrlException;
use Thelia\Exception\UrlRewritingException;
use Thelia\Model\RewritingUrlQuery;
use Thelia\Model\Map\RewritingUrlTableMap;
/**
* Class RewritingResolver
* @package Thelia\Rewriting
@@ -31,5 +38,58 @@ namespace Thelia\Rewriting;
*/
class RewritingResolver
{
protected $search = null;
protected $rewritingUrlQuery = null;
public $view;
public $viewId;
public $locale;
public $otherParameters;
public $redirectedToUrl;
public function __construct($url = null)
{
$this->rewritingUrlQuery = new RewritingUrlQuery();
if($url !== null) {
$this->load($url);
}
}
public function load($rewrittenUrl)
{
$this->search = $this->rewritingUrlQuery->getResolverSearch($rewrittenUrl);
if($this->search->count() == 0) {
throw new UrlRewritingException('URL NOT FOUND', UrlRewritingException::URL_NOT_FOUND);
}
$this->view = $this->search->getFirst()->getVirtualColumn('ru_view');
$this->viewId = $this->search->getFirst()->getVirtualColumn('ru_viewId');
$this->locale = $this->search->getFirst()->getVirtualColumn('ru_locale');
$this->redirectedToUrl = $this->search->getFirst()->getVirtualColumn('ru_redirected_to_url');
$this->otherParameters = $this->getOtherParameters();
}
protected function getOtherParameters()
{
if($this->search === null) {
throw new UrlRewritingException('RESOLVER NULL SEARCH', UrlRewritingException::RESOLVER_NULL_SEARCH);
}
$otherParameters = array();
foreach($this->search as $result) {
$parameter = $result->getParameter();
$value = $result->getValue();
if(null !== $parameter) {
$otherParameters[$parameter] = $value;
}
}
return $otherParameters;
}
}

View File

@@ -23,8 +23,9 @@
namespace Thelia\Rewriting;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Model\Base\RewritingUrlQuery;
use Thelia\Model\RewritingUrlQuery;
use Thelia\Model\Map\RewritingUrlTableMap;
use Thelia\Tools\URL;
/**
* Class RewritingRetriever
@@ -35,38 +36,40 @@ use Thelia\Model\Map\RewritingUrlTableMap;
*/
class RewritingRetriever
{
/**
* @param $view
* @param $viewLocale
* @param $viewId
*
* @return null|$url
*/
public function getViewUrl($view, $viewLocale, $viewId)
{
$url = $this->getViewUrlQuery($view, $viewId, $viewLocale);
protected $search = null;
protected $rewritingUrlQuery = null;
return $url === null ? null : $url->getUrl();
public $url;
public $rewrittenUrl;
public function __construct($view = null, $viewLocale = null, $viewId = null)
{
$this->rewritingUrlQuery = new RewritingUrlQuery();
if($view !== null && $viewLocale !== null) {
$this->load($view, $viewLocale, $viewId);
}
}
/**
* @param $view
* @param $viewId
* @param $viewLocale
*
* @return null|RewritingUrl
* @param null $viewId
*/
protected function getViewUrlQuery($view, $viewId, $viewLocale)
public function loadViewUrl($view, $viewLocale, $viewId = null)
{
return RewritingUrlQuery::create()
->joinRewritingArgument('ra', Criteria::LEFT_JOIN)
->where('ISNULL(`ra`.REWRITING_URL_ID)')
->filterByView($view)
->filterByViewLocale($viewLocale)
->filterByViewId($viewId)
->filterByRedirected(null)
->orderByUpdatedAt(Criteria::DESC)
->findOne();
$this->search = $this->rewritingUrlQuery->getViewUrlQuery($view, $viewLocale, $viewId);
$allParametersWithoutView = array();
$allParametersWithoutView['locale'] = $viewLocale;
if(null !== $viewId) {
$allParametersWithoutView[$view . '_id'] = $viewId;
}
$this->url = URL::viewUrl($view, $allParametersWithoutView);
if($this->search !== null) {
$this->rewrittenUrl = $this->search->getUrl();
}
}
/**
@@ -74,46 +77,25 @@ class RewritingRetriever
* @param $viewLocale
* @param null $viewId
* @param array $viewOtherParameters
*
* @return null|$url
*/
public function getSpecificUrl($view, $viewLocale, $viewId = null, $viewOtherParameters = array())
public function loadSpecificUrl($view, $viewLocale, $viewId = null, $viewOtherParameters = array())
{
$urlQuery = RewritingUrlQuery::create()
->joinRewritingArgument('ra', Criteria::LEFT_JOIN)
->withColumn('`ra`.REWRITING_URL_ID', 'ra_REWRITING_URL_ID')
->filterByView($view)
->filterByViewLocale($viewLocale)
->filterByViewId($viewId)
->filterByRedirected(null)
->orderByUpdatedAt(Criteria::DESC);
$otherParametersCount = count($viewOtherParameters);
if($otherParametersCount > 0) {
$parameterConditions = array();
foreach($viewOtherParameters as $parameter => $value) {
$conditionName = 'other_parameter_condition_' . count($parameterConditions);
$urlQuery->condition('parameter_condition', '`ra`.PARAMETER= ?', $parameter, \PDO::PARAM_STR)
->condition('value_condition', '`ra`.VALUE = ?', $value, \PDO::PARAM_STR)
->combine(array('parameter_condition', 'value_condition'), Criteria::LOGICAL_AND, $conditionName);
$parameterConditions[] = $conditionName;
if(empty($viewOtherParameters)) {
$this->loadViewUrl($view, $viewLocale, $viewId);
return;
}
$urlQuery->where($parameterConditions, Criteria::LOGICAL_OR);
$this->search = $this->rewritingUrlQuery->getSpecificUrlQuery($view, $viewLocale, $viewId, $viewOtherParameters);
$urlQuery->groupBy(RewritingUrlTableMap::ID);
$urlQuery->condition('count_condition_1', 'COUNT(' . RewritingUrlTableMap::ID . ') = ?', $otherParametersCount, \PDO::PARAM_INT) // ensure we got all the asked parameters (provided by the query)
->condition('count_condition_2', 'COUNT(' . RewritingUrlTableMap::ID . ') = (SELECT COUNT(*) FROM rewriting_argument WHERE rewriting_argument.REWRITING_URL_ID = ra_REWRITING_URL_ID)'); // ensure we don't miss any parameters (needed to match the rewritten url)
$urlQuery->having(array('count_condition_1', 'count_condition_2'), Criteria::LOGICAL_AND);
} else {
$urlQuery->where('ISNULL(`ra`.REWRITING_URL_ID)');
$allParametersWithoutView = $viewOtherParameters;
$allParametersWithoutView['locale'] = $viewLocale;
if(null !== $viewId) {
$allParametersWithoutView[$view . '_id'] = $viewId;
}
$url = $urlQuery->findOne();
return $url === null ? null : $url->getUrl();
$this->url = URL::viewUrl($view, $allParametersWithoutView);
if($this->search !== null) {
$this->rewrittenUrl = $this->search->getUrl();
}
}
}

View File

@@ -0,0 +1,119 @@
<?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\Tests\Rewriting;
use Thelia\Model\RewritingArgument;
use Thelia\Rewriting\RewritingResolver;
use Propel\Runtime\Collection\ObjectCollection;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class RewritingResolverTest extends \PHPUnit_Framework_TestCase
{
protected function getMethod($name)
{
$class = new \ReflectionClass('\Thelia\Rewriting\RewritingResolver');
$method = $class->getMethod($name);
$method->setAccessible(true);
return $method;
}
protected function getProperty($name)
{
$class = new \ReflectionClass('\Thelia\Rewriting\RewritingResolver');
$property = $class->getProperty($name);
$property->setAccessible(true);
return $property;
}
public function testGetOtherParameters()
{
$rewritingArguments = array(
array('Parameter' => 'foo0', 'Value' => 'bar0'),
array('Parameter' => 'foo1', 'Value' => 'bar1'),
array('Parameter' => 'foo2', 'Value' => 'bar2'),
);
$searchResult = new ObjectCollection();
$searchResult->setModel('\Thelia\Model\RewritingArgument');
$searchResult->fromArray($rewritingArguments);
$resolver = new RewritingResolver();
$search = $this->getProperty('search');
$search->setValue($resolver, $searchResult);
$method = $this->getMethod('getOtherParameters');
$actual = $method->invoke($resolver);
$expected = array(
'foo0' => 'bar0',
'foo1' => 'bar1',
'foo2' => 'bar2',
);
$this->assertEquals($expected, $actual);
}
public function testLoad()
{
$collection = new ObjectCollection();
$collection->setModel('\Thelia\Model\RewritingArgument');
for($i=0; $i<3; $i++) {
$ra = new RewritingArgument();
$ra->setParameter('foo' . $i);
$ra->setValue('bar' . $i);
$ra->setVirtualColumn('ru_view', 'view');
$ra->setVirtualColumn('ru_viewId', 'viewId');
$ra->setVirtualColumn('ru_locale', 'locale');
$ra->setVirtualColumn('ru_redirected_to_url', null);
$collection->append($ra);
}
$resolverQuery = $this->getMock('\Thelia\Model\RewritingUrlQuery', array('getResolverSearch'));
$resolverQuery->expects($this->any())
->method('getResolverSearch')
->with('foo.html')
->will($this->returnValue($collection));
$resolver = new RewritingResolver();
$rewritingUrlQuery = $this->getProperty('rewritingUrlQuery');
$rewritingUrlQuery->setValue($resolver, $resolverQuery);
$resolver->load('foo.html');
$this->assertEquals('view', $resolver->view);
$this->assertEquals('viewId', $resolver->viewId);
$this->assertEquals('locale', $resolver->locale);
$this->assertEquals(array('foo0' => 'bar0', 'foo1' => 'bar1', 'foo2' => 'bar2'), $resolver->otherParameters);
}
}

View File

@@ -23,7 +23,9 @@
namespace Thelia\Tests\Rewriting;
use Thelia\Model\RewritingUrl;
use Thelia\Rewriting\RewritingRetriever;
use Thelia\Tools\URL;
/**
*
@@ -32,13 +34,65 @@ use Thelia\Rewriting\RewritingRetriever;
*/
class RewritingRetrieverTest extends \PHPUnit_Framework_TestCase
{
public function testGetViewUrl()
protected function getMethod($name)
{
$class = new \ReflectionClass('\Thelia\Rewriting\RewritingRetriever');
$method = $class->getMethod($name);
$method->setAccessible(true);
return $method;
}
public function testGetSpecificUrl()
protected function getProperty($name)
{
$class = new \ReflectionClass('\Thelia\Rewriting\RewritingRetriever');
$property = $class->getProperty($name);
$property->setAccessible(true);
return $property;
}
public function testLoadViewUrl()
{
$searchResult = new RewritingUrl();
$searchResult->setUrl('foo.html');
$retrieverQuery = $this->getMock('\Thelia\Model\RewritingUrlQuery', array('getViewUrlQuery'));
$retrieverQuery->expects($this->any())
->method('getViewUrlQuery')
->with('view', 'fr_FR', 1)
->will($this->returnValue($searchResult));
$retriever = new RewritingRetriever();
$rewritingUrlQuery = $this->getProperty('rewritingUrlQuery');
$rewritingUrlQuery->setValue($retriever, $retrieverQuery);
$retriever->loadViewUrl('view', 'fr_FR', 1);
$this->assertEquals('foo.html', $retriever->rewrittenUrl);
$this->assertEquals(URL::viewUrl('view', array('locale' => 'fr_FR', 'view_id' => 1)), $retriever->url);
}
public function testLoadSpecificUrl()
{
$searchResult = new RewritingUrl();
$searchResult->setUrl('foo.html');
$retrieverQuery = $this->getMock('\Thelia\Model\RewritingUrlQuery', array('getSpecificUrlQuery'));
$retrieverQuery->expects($this->any())
->method('getSpecificUrlQuery')
->with('view', 'fr_FR', 1, array('foo0' => 'bar0', 'foo1' => 'bar1'))
->will($this->returnValue($searchResult));
$retriever = new RewritingRetriever();
$rewritingUrlQuery = $this->getProperty('rewritingUrlQuery');
$rewritingUrlQuery->setValue($retriever, $retrieverQuery);
$retriever->loadSpecificUrl('view', 'fr_FR', 1, array('foo0' => 'bar0', 'foo1' => 'bar1'));
$this->assertEquals('foo.html', $retriever->rewrittenUrl);
$this->assertEquals(URL::viewUrl('view', array('foo0' => 'bar0', 'foo1' => 'bar1', 'locale' => 'fr_FR', 'view_id' => 1)), $retriever->url);
}
}

View File

@@ -25,18 +25,33 @@ namespace Thelia\Tools;
use Symfony\Component\HttpFoundation\Request;
use Thelia\Model\ConfigQuery;
use Thelia\Rewriting\RewritingResolver;
use Thelia\Rewriting\RewritingRetriever;
class URL
{
protected $resolver = null;
protected $retriever = null;
const PATH_TO_FILE = true;
const WITH_INDEX_PAGE = false;
public function __construct()
{
$this->retriever = new RewritingRetriever();
$this->resolver = new RewritingResolver();
}
public static function getIndexPage()
{
return ConfigQuery::read('base_url', '/') . "index_dev.php"; // FIXME !
}
public static function init()
{
return new URL();
}
/**
* Returns the Absolute URL for a given path relative to web root. By default,
* the index.php (or index_dev.php) script name is added to the URL, use
@@ -103,7 +118,7 @@ class URL
*/
public static function viewUrl($viewName, array $parameters = array())
{
$path = sprintf("%s?view=%s", self::getIndexPage(), $viewName);
$path = sprintf("?view=%s", $viewName);
return self::absoluteUrl($path, $parameters);
}
@@ -115,18 +130,17 @@ class URL
*
* @return null|string
*/
public static function retrieve($view, $viewId, $viewLocale)
public function retrieve($view, $viewId, $viewLocale)
{
$rewrittenUrl = null;
if(ConfigQuery::isRewritingEnable()) {
$retriever = new RewritingRetriever();
$rewrittenUrl = $retriever->getViewUrl($view, $viewLocale, $viewId);
$rewrittenUrl = $this->retriever->loadViewUrl($view, $viewLocale, $viewId);
}
return $rewrittenUrl === null ? self::viewUrl($view, array($view . '_id' => $viewId, 'locale' => $viewLocale)) : $rewrittenUrl;
}
public static function retrieveCurrent(Request $request)
public function retrieveCurrent(Request $request)
{
$rewrittenUrl = null;
if(ConfigQuery::isRewritingEnable()) {
@@ -134,12 +148,10 @@ class URL
$viewLocale = $request->query->get('locale', null);
$viewId = $view === null ? null : $request->query->get($view . '_id', null);
$allParameters = $request->query->all();
$allParametersWithoutView = $allParameters;
$allOtherParameters = $request->query->all();
if($view !== null) {
unset($allParametersWithoutView['view']);
unset($allOtherParameters['view']);
}
$allOtherParameters = $allParametersWithoutView;
if($viewLocale !== null) {
unset($allOtherParameters['locale']);
}
@@ -147,10 +159,15 @@ class URL
unset($allOtherParameters[$view . '_id']);
}
$retriever = new RewritingRetriever();
$rewrittenUrl = $retriever->getSpecificUrl($view, $viewLocale, $viewId, $allOtherParameters);
$this->retriever->loadSpecificUrl($view, $viewLocale, $viewId, $allOtherParameters);
}
return $rewrittenUrl === null ? self::viewUrl($view, $allParametersWithoutView) : $rewrittenUrl;
return $this->retriever;
}
public function resolve($url)
{
$this->resolver->load($url);
return $this->resolver;
}
}

View File

@@ -6,14 +6,15 @@ INSERT INTO `lang`(`id`,`title`,`code`,`locale`,`url`,`by_default`,`created_at`,
INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updated_at`) VALUES
('session_config.default', '1', 1, 1, NOW(), NOW()),
('verifyStock', '1', 1, 0, NOW(), NOW()),
('default_lang_without_translation', '1', 1, 0, NOW(), NOW()),
('rewriting_enable', '0', 1, 0, NOW(), NOW()),
('imagine_graphic_driver', 'gd', 1, 0, NOW(), NOW()),
('default_images_quality_percent', '75', 1, 0, NOW(), NOW()),
('original_image_delivery_mode', 'symlink', 1, 0, NOW(), NOW()),
('images_library_path', 'local/media/images', 1, 0, NOW(), NOW()),
('image_cache_dir_from_web_root', 'cache/images', 1, 0, NOW(), NOW());
('verifyStock', '1', 0, 0, NOW(), NOW()),
('default_lang_without_translation', '1', 0, 0, NOW(), NOW()),
('rewriting_enable', '0', 0, 0, NOW(), NOW()),
('imagine_graphic_driver', 'gd', 0, 0, NOW(), NOW()),
('default_images_quality_percent', '75', 0, 0, NOW(), NOW()),
('original_image_delivery_mode', 'symlink', 0, 0, NOW(), NOW()),
('images_library_path', 'local/media/images', 0, 0, NOW(), NOW()),
('image_cache_dir_from_web_root', 'cache/images', 0, 0, NOW(), NOW()),
('currency_rate_update_url', 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml', 0, 0, NOW(), NOW());
INSERT INTO `module` (`code`, `type`, `activate`, `position`, `created_at`, `updated_at`) VALUES ('test', '1', '1', '1', NOW(), NOW());

View File

@@ -26,7 +26,7 @@
<div class="row-fluid">
<div class="span12">
<form action="{url path='/admin/configuration/currencies/change-values'}" method="post">
<form action="{url path='/admin/configuration/currencies/update-rates'}" method="post">
<div class="general-block-decorator">
<table class="table table-striped table-condensed table-left-aligned">
<caption>
@@ -35,6 +35,7 @@
<a class="btn btn-primary action-btn" title="{intl l='Add a new currency'}" href="#add_currency_dialog" data-toggle="modal">
<i class="icon-plus-sign icon-white"></i>
</a>
<button class="btn btn-info action-btn" title="{intl l='Update rates'}">{intl l='Update rates'} <i class="icon icon-white icon-globe"></i></button>
{/loop}
</caption>
@@ -117,7 +118,6 @@
{loop name="currencies" type="currency" backend_context="1" lang=$lang_id order=$order}
<tr>
<td>{$ID}</td>
<td>
@@ -133,7 +133,7 @@
<td class="text-center">{$SYMBOL}</td>
<td class="text-right">{$RATE|string_format:"%.4f"}</td>
<td class="text-right">{format_number number="$RATE" decimals="4"}</td>
<td class="text-center">
{admin_position_block
@@ -146,7 +146,9 @@
}
</td>
<td class="text-center"><input type="radio" name="default[{$ID}]" value="1" {if $IS_DEFAULT}checked="checked"{/if}/></td>
<td class="text-center">
<input class="change-default" type="radio" name="is_default" value="{$ID}" {if $IS_DEFAULT}checked="checked"{/if}/>
</td>
{module_include location='currencies_table_row'}
@@ -208,7 +210,7 @@
<div class="modal-body">
{if #form_error}<div class="alert alert-block alert-error" id="add_currency_dialog_error">#form_error_currency</div>{/if}
{if $form_error}<div class="alert alert-block alert-error" id="add_currency_dialog_error">{$form_error_message}</div>{/if}
<div class="control-group">
@@ -246,7 +248,7 @@
</label>
<div class="controls">
{form_field form=$form field='symbol'}
{form_field form=$form field='code'}
<span {if $error}class="error"{/if}>
<input type="text" required="required" name="{$name}" value="{$value}" title="{intl l='ISO 4217 code'}" placeholder="{intl l='Code'}">
</span>
@@ -278,11 +280,11 @@
</label>
<div class="controls">
{form_field form=$form field='symbol'}
{form_field form=$form field='rate'}
<span {if $error}class="error"{/if}>
<input type="text" required="required" name="{$name}" value="{$value}" title="{intl l='Currency rate'}" placeholder="{intl l='Rate'}">
</span>
<div class="help-block">{intl l="Currency rate, in Euro"}</div>
<div class="help-block">{intl l="The rate from Euro (Price in Euro * rate = Price in this currency)"}</div>
{/form_field}
</div>
</div>
@@ -380,6 +382,18 @@
}
});
{* Change default status *}
$('.change-default').click(function(ev) {
var url = "{url path='/admin/configuration/currencies/set-default' currency_id='__ID__'}";
// Perform ID subtitutions
url = url.replace('__ID__', $(this).val());
// Reload the page
location.href = url;
});
});
</script>
{/block}

View File

@@ -123,7 +123,7 @@
<div class="control-group">
<lablel>&nbsp;</lablel>
<div class="controls">
<p>{intl l='Category created on %date_create. Last modification: %date_change' date_create=$CREATE_DATE->format($datetime_format) date_change=$UPDATE_DATE->format($datetime_format)}</p>
<p>{intl l='Category created on %date_create. Last modification: %date_change' date_create="{format_date date=$CREATE_DATE}" date_change="{format_date date=$UPDATE_DATE}"}}</p>
</div>
</div>
</div>

View File

@@ -144,7 +144,7 @@
<div class="control-group">
<div class="controls">
<p>{intl l='Message created on %date_create. Last modification: %date_change' df=$datetime_format date_create=$CREATE_DATE->format($datetime_format) date_change=$UPDATE_DATE->format($datetime_format)}</p>
<p>{intl l='Message created on %date_create. Last modification: %date_change' date_create="{format_date date=$CREATE_DATE}" date_change="{format_date date=$UPDATE_DATE}"}}</p>
</div>
</div>
</fieldset>

View File

@@ -108,7 +108,7 @@
<div class="control-group">
<div class="controls">
<p>{intl l='Variable created on %date_create. Last modification: %date_change' df=$datetime_format date_create=$CREATE_DATE->format($datetime_format) date_change=$UPDATE_DATE->format($datetime_format)}</p>
<p>{intl l='Variable created on %date_create. Last modification: %date_change' date_create="{format_date date=$CREATE_DATE}" date_change="{format_date date=$UPDATE_DATE}"}</p>
</div>
</div>