Merge branch 'master' of github.com:thelia/thelia

Conflicts:
	core/lib/Thelia/Config/Resources/routing/front.xml
This commit is contained in:
Manuel Raynaud
2013-09-04 17:57:41 +02:00
162 changed files with 10966 additions and 10282 deletions

View File

@@ -143,7 +143,7 @@ class Cart extends BaseAction implements EventSubscriberInterface
return array(
"action.addArticle" => array("addItem", 128),
"action.deleteArticle" => array("deleteItem", 128),
"action.changeArticle" => array("changeItem", 128),
"action.updateArticle" => array("changeItem", 128),
);
}

View File

@@ -248,9 +248,9 @@ class Category extends BaseAction implements EventSubscriberInterface
TheliaEvents::CATEGORY_TOGGLE_VISIBILITY => array("toggleVisibility", 128),
TheliaEvents::CATEGORY_CHANGE_POSITION => array("changePosition", 128),
"action.changeCategoryPositionU" => array("changePositionUp", 128),
"action.changeCategoryPositionDown" => array("changePositionDown", 128),
"action.changeCategoryPosition" => array("changePosition", 128),
"action.updateCategoryPositionU" => array("changePositionUp", 128),
"action.updateCategoryPositionDown" => array("changePositionDown", 128),
"action.updateCategoryPosition" => array("changePosition", 128),
);
}
}

View File

@@ -31,7 +31,7 @@ use Thelia\Model\Config as ConfigModel;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\ConfigChangeEvent;
use Thelia\Core\Event\ConfigUpdateEvent;
use Thelia\Core\Event\ConfigCreateEvent;
use Thelia\Core\Event\ConfigDeleteEvent;
@@ -65,9 +65,9 @@ class Config extends BaseAction implements EventSubscriberInterface
/**
* Change a configuration entry value
*
* @param ConfigChangeEvent $event
* @param ConfigUpdateEvent $event
*/
public function setValue(ConfigChangeEvent $event)
public function setValue(ConfigUpdateEvent $event)
{
$search = ConfigQuery::create();
@@ -90,9 +90,9 @@ class Config extends BaseAction implements EventSubscriberInterface
/**
* Change a configuration entry
*
* @param ConfigChangeEvent $event
* @param ConfigUpdateEvent $event
*/
public function modify(ConfigChangeEvent $event)
public function modify(ConfigUpdateEvent $event)
{
$search = ConfigQuery::create();

View File

@@ -31,11 +31,11 @@ use Thelia\Model\Currency as CurrencyModel;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\CurrencyChangeEvent;
use Thelia\Core\Event\CurrencyUpdateEvent;
use Thelia\Core\Event\CurrencyCreateEvent;
use Thelia\Core\Event\CurrencyDeleteEvent;
use Thelia\Model\Map\CurrencyTableMap;
use Thelia\Model\ConfigQuery;
use Thelia\Core\Event\CurrencyUpdatePositionEvent;
class Currency extends BaseAction implements EventSubscriberInterface
{
@@ -67,9 +67,9 @@ class Currency extends BaseAction implements EventSubscriberInterface
/**
* Change a currency
*
* @param CurrencyChangeEvent $event
* @param CurrencyUpdateEvent $event
*/
public function update(CurrencyChangeEvent $event)
public function update(CurrencyUpdateEvent $event)
{
$search = CurrencyQuery::create();
@@ -93,9 +93,9 @@ class Currency extends BaseAction implements EventSubscriberInterface
/**
* Set the default currency
*
* @param CurrencyChangeEvent $event
* @param CurrencyUpdateEvent $event
*/
public function setDefault(CurrencyChangeEvent $event)
public function setDefault(CurrencyUpdateEvent $event)
{
$search = CurrencyQuery::create();
@@ -158,18 +158,34 @@ class Currency extends BaseAction implements EventSubscriberInterface
}
}
/**
* Changes position, selecting absolute ou relative change.
*
* @param CategoryChangePositionEvent $event
*/
public function updatePosition(CurrencyUpdatePositionEvent $event)
{
if (null !== $category = CurrencyQuery::create()->findOneById($event->getObjectId())) {
if ($event->getMode() == BaseChangePositionEvent::POSITION_ABSOLUTE)
return $category->changeAbsolutePosition($event->getPosition());
else
return $this->exchangePosition($event->getMode());
}
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return array(
TheliaEvents::CURRENCY_CREATE => array("create", 128),
TheliaEvents::CURRENCY_UPDATE => array("update", 128),
TheliaEvents::CURRENCY_DELETE => array("delete", 128),
TheliaEvents::CURRENCY_SET_DEFAULT => array("setDefault", 128),
TheliaEvents::CURRENCY_UPDATE_RATES => array("updateRates", 128),
TheliaEvents::CURRENCY_CREATE => array("create", 128),
TheliaEvents::CURRENCY_UPDATE => array("update", 128),
TheliaEvents::CURRENCY_DELETE => array("delete", 128),
TheliaEvents::CURRENCY_SET_DEFAULT => array("setDefault", 128),
TheliaEvents::CURRENCY_UPDATE_RATES => array("updateRates", 128),
TheliaEvents::CURRENCY_UPDATE_POSITION => array("updatePosition", 128)
);
}
}

View File

@@ -269,8 +269,8 @@ class Image extends BaseAction implements EventSubscriberInterface
$event->setCacheFilepath($cacheFilePath);
$event->setCacheOriginalFilepath($originalImagePathInCache);
$event->setFileUrl(URL::absoluteUrl($processed_image_url, null, URL::PATH_TO_FILE));
$event->setOriginalFileUrl(URL::absoluteUrl($original_image_url, null, URL::PATH_TO_FILE));
$event->setFileUrl(URL::getInstance()->absoluteUrl($processed_image_url, null, URL::PATH_TO_FILE));
$event->setOriginalFileUrl(URL::getInstance()->absoluteUrl($original_image_url, null, URL::PATH_TO_FILE));
}
/**
@@ -382,7 +382,7 @@ class Image extends BaseAction implements EventSubscriberInterface
{
$path = $this->getCachePathFromWebRoot($subdir);
return URL::absoluteUrl(sprintf("%s/%s", $path, $safe_filename), null, URL::PATH_TO_FILE);
return URL::getInstance()->absoluteUrl(sprintf("%s/%s", $path, $safe_filename), null, URL::PATH_TO_FILE);
}
/**
@@ -494,4 +494,4 @@ class Image extends BaseAction implements EventSubscriberInterface
TheliaEvents::IMAGE_CLEAR_CACHE => array("clearCache", 128),
);
}
}
}

View File

@@ -31,7 +31,7 @@ use Thelia\Model\Message as MessageModel;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\MessageChangeEvent;
use Thelia\Core\Event\MessageUpdateEvent;
use Thelia\Core\Event\MessageCreateEvent;
use Thelia\Core\Event\MessageDeleteEvent;
@@ -65,9 +65,9 @@ class Message extends BaseAction implements EventSubscriberInterface
/**
* Change a message
*
* @param MessageChangeEvent $event
* @param MessageUpdateEvent $event
*/
public function modify(MessageChangeEvent $event)
public function modify(MessageUpdateEvent $event)
{
$search = MessageQuery::create();

View File

@@ -27,6 +27,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\KernelEvents;
use Thelia\Model\ConfigQuery;
@@ -40,7 +41,7 @@ class PageNotFound extends BaseAction implements EventSubscriberInterface
{
public function display404(GetResponseForExceptionEvent $event)
{
if(is_a($event->getException(), 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException')) {
if($event->getException() instanceof NotFoundHttpException) {
$parser = $this->container->get("thelia.parser");

View File

@@ -75,6 +75,13 @@
<services>
<!-- URL maganement -->
<service id="thelia.url.manager" class="Thelia\Tools\URL">
<argument type="service" id="service_container" />
<argument >%kernel.environment%</argument>
</service>
<service id="event_dispatcher" class="Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher">
<argument type="service" id="service_container" />
</service>

View File

@@ -41,7 +41,7 @@
<default key="_controller">Thelia\Controller\Admin\ConfigController::defaultAction</default>
</route>
<route id="admin.configuration.variables.change-values" path="/admin/configuration/variables/change-values">
<route id="admin.configuration.variables.update-values" path="/admin/configuration/variables/update-values">
<default key="_controller">Thelia\Controller\Admin\ConfigController::changeValuesAction</default>
</route>
@@ -49,7 +49,7 @@
<default key="_controller">Thelia\Controller\Admin\ConfigController::createAction</default>
</route>
<route id="admin.configuration.variables.change" path="/admin/configuration/variables/change">
<route id="admin.configuration.variables.update" path="/admin/configuration/variables/update">
<default key="_controller">Thelia\Controller\Admin\ConfigController::changeAction</default>
</route>
@@ -71,7 +71,7 @@
<default key="_controller">Thelia\Controller\Admin\MessageController::createAction</default>
</route>
<route id="admin.configuration.messages.change" path="/admin/configuration/messages/change">
<route id="admin.configuration.messages.update" path="/admin/configuration/messages/update">
<default key="_controller">Thelia\Controller\Admin\MessageController::changeAction</default>
</route>
@@ -93,7 +93,7 @@
<default key="_controller">Thelia\Controller\Admin\CurrencyController::createAction</default>
</route>
<route id="admin.configuration.currencies.change" path="/admin/configuration/currencies/change">
<route id="admin.configuration.currencies.update" path="/admin/configuration/currencies/update">
<default key="_controller">Thelia\Controller\Admin\CurrencyController::changeAction</default>
</route>
@@ -113,6 +113,10 @@
<default key="_controller">Thelia\Controller\Admin\CurrencyController::deleteAction</default>
</route>
<route id="admin.configuration.currencies.delete" path="/admin/configuration/currencies/update-position">
<default key="_controller">Thelia\Controller\Admin\CurrencyController::updatePositionAction</default>
</route>
<!-- The default route, to display a template -->
<route id="admin.processTemplate" path="/admin/{template}">

View File

@@ -50,7 +50,7 @@
<default key="_view">cart</default>
</route>
<route id="cart.change.process" path="/cart/delete/{cart_item}">
<route id="cart.update.process" path="/cart/delete/{cart_item}">
<default key="_controller">Thelia\Controller\Front\CartController::deleteItem</default>
<default key="_view">cart</default>
</route>
@@ -60,7 +60,13 @@
<default key="_view">cart</default>
</route>
<!-- <route id="url-rewriting.check" path="/{rewritten_url}" methods="GET">
<!-- Empêche l'accès àl'admin, genre: http://localhost/thelia2/index_dev.php/admin/login amène sur l'accueuil de la boutique
<route id="url-rewriting.check" path="/{rewritten_url}" methods="GET">
<default key="_controller">Thelia\Controller\Front\UrlRewritingController::check</default>
</route>-->
<requirement key="rewritten_url">.*</requirement>
</route>
-->
</routes>

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
@@ -241,7 +241,7 @@ class ConfigController extends BaseAdminController
if ($this->getRequest()->get('save_mode') == 'stay') {
$this->redirectToRoute(
"admin.configuration.variables.change",
"admin.configuration.variables.update",
array('variable_id' => $variable_id)
);
}
@@ -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,50 @@ 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 {
$id = $this->getRequest()->get('currency_id', 0);
$mode = $this->getRequest()->get('mode', null);
$position = $this->getRequest()->get('position', null);
$event = new CurrencyUpdatePositionEvent();
$event
->setObjectId($this->getRequest()->get('currency_id', 0))
->setPosition($this->getRequest()->get('position', 0))
->setMode($mode)
;
$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'));
}
}

View File

@@ -49,7 +49,7 @@ class AddressController extends BaseFrontController
public function createAction()
{
if ($this->getSecurityContext()->hasCustomerUser() === false) {
$this->redirect(URL::getIndexPage());
$this->redirect(URL::getInstance()->getIndexPage());
}
$addressCreate = new AddressCreateForm($this->getRequest());

View File

@@ -45,6 +45,6 @@ class BaseFrontController 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));
}
}

View File

@@ -202,7 +202,7 @@ class CustomerController extends BaseFrontController
}
// Redirect to home page
$this->redirect(URL::getIndexPage());
$this->redirect(URL::getInstance()->getIndexPage());
}
/**

View File

@@ -49,7 +49,7 @@ class DefaultController extends BaseFrontController
if(ConfigQuery::isRewritingEnable()) {
/* Does the query GET parameters match a rewritten URL ? */
$rewrittenUrl = URL::init()->retrieveCurrent($request);
$rewrittenUrl = URL::getInstance()->retrieveCurrent();
if($rewrittenUrl->rewrittenUrl !== null) {
/* 301 redirection to rewritten URL */
$this->redirect($rewrittenUrl->rewrittenUrl, 301);

View File

@@ -33,7 +33,7 @@ class UrlRewritingController extends BaseFrontController
{
if(ConfigQuery::isRewritingEnable()) {
try {
$rewrittenUrlData = URL::init()->resolve($rewritten_url);
$rewrittenUrlData = URL::getInstance()->resolve($rewritten_url);
} catch(UrlRewritingException $e) {
switch($e->getCode()) {
case UrlRewritingException::URL_NOT_FOUND :

View File

@@ -22,64 +22,7 @@
/*************************************************************************************/
namespace Thelia\Core\Event;
use Thelia\Model\Category;
class CategoryChangePositionEvent extends ActionEvent
class CurrencyUpdatePositionEvent extends BaseUpdatePositionEvent
{
const POSITION_UP = 1;
const POSITION_DOWN = 2;
const POSITION_ABSOLUTE = 3;
protected $category_id;
protected $mode;
protected $position;
protected $category;
public function __construct($category_id, $mode, $position = null)
{
$this->category_id = $category_id;
$this->mode = $mode;
$this->position = $position;
}
public function getMode()
{
return $this->mode;
}
public function setMode($mode)
{
$this->mode = $mode;
}
public function getPosition()
{
return $this->position;
}
public function setPosition($position)
{
$this->position = $position;
}
public function getCategory()
{
return $this->category;
}
public function setCategory($category)
{
$this->category = $category;
}
public function getCategoryId()
{
return $this->category_id;
}
public function setCategoryId($category_id)
{
$this->category_id = $category_id;
}
}
}

View File

@@ -25,7 +25,7 @@ namespace Thelia\Core\Event;
use Thelia\Model\Category;
class CategoryCreateEvent extends ActionEvent
class CategoryUpdateEvent extends ActionEvent
{
protected $category_id;
protected $locale;

View File

@@ -25,7 +25,7 @@ namespace Thelia\Core\Event;
use Thelia\Model\Config;
class ConfigChangeEvent extends ConfigCreateEvent
class ConfigUpdateEvent extends ConfigCreateEvent
{
protected $config_id;

View File

@@ -24,7 +24,7 @@
namespace Thelia\Core\Event;
use Thelia\Model\Currency;
class CurrencyChangeEvent extends CurrencyCreateEvent
class CurrencyUpdateEvent extends CurrencyCreateEvent
{
protected $currency_id;
protected $is_default;

View File

@@ -25,7 +25,7 @@ namespace Thelia\Core\Event;
use Thelia\Model\Message;
class MessageChangeEvent extends MessageCreateEvent
class MessageUpdateEvent extends MessageCreateEvent
{
protected $message_id;

View File

@@ -136,7 +136,7 @@ final class TheliaEvents
/**
* Change category position
*/
const CATEGORY_CHANGE_POSITION = "action.changeCategoryPosition";
const CATEGORY_CHANGE_POSITION = "action.updateCategoryPosition";
/**
* Sent just after a successful insert of a new category in the database.
@@ -232,12 +232,12 @@ final class TheliaEvents
// -- Currencies management ---------------------------------------------
const CURRENCY_CREATE = "action.createCurrency";
const CURRENCY_UPDATE = "action.updateCurrency";
const CURRENCY_DELETE = "action.deleteCurrency";
const CURRENCY_SET_DEFAULT = "action.setDefaultCurrency";
const CURRENCY_UPDATE_RATES = "action.updateCurrencyRates";
const CURRENCY_CREATE = "action.createCurrency";
const CURRENCY_UPDATE = "action.updateCurrency";
const CURRENCY_DELETE = "action.deleteCurrency";
const CURRENCY_SET_DEFAULT = "action.setDefaultCurrency";
const CURRENCY_UPDATE_RATES = "action.updateCurrencyRates";
const CURRENCY_UPDATE_POSITION = "action.updateCurrencyPosition";
const BEFORE_CREATECURRENCY = "action.before_createCurrency";
const AFTER_CREATECURRENCY = "action.after_createCurrency";

View File

@@ -86,7 +86,7 @@ class ViewListener implements EventSubscriberInterface
} catch (AuthenticationException $ex) {
// Redirect to the login template
Redirect::exec(URL::viewUrl($ex->getLoginTemplate()));
Redirect::exec($this->container->get('thelia.url.manager')->viewUrl($ex->getLoginTemplate()));
}
}

View File

@@ -41,55 +41,29 @@ use Thelia\Model\Lang;
*/
class Session extends BaseSession
{
// -- Language ------------------------------------------------------------
public function getLocale()
{
return $this->get("locale", "en_US");
}
public function setLocale($locale)
{
$this->set("locale", $locale);
return $this;
}
/**
* @return \Thelia\Model\Lang|null
*/
public function getLang()
{
return $this->get("lang");
return $this->get("thelia.current.lang", Lang::getDefaultLanguage());
}
public function setLang(Lang $lang)
{
$this->set("lang", $lang);
$this->set("thelia.current.lang", $lang);
return $this;
}
public function getLangId()
public function getAdminEditionLang()
{
return $this->get("lang_id", Lang::getDefaultLanguage()->getId());
return $this->get('thelia.admin.edition.lang', Lang::getDefaultLanguage());
}
public function setLangId($langId)
public function setAdminEditionLang($langId)
{
$this->set("lang_id", $langId);
return $this;
}
public function getAdminEditionLangId()
{
return $this->get('admin.edition_language', Lang::getDefaultLanguage()->getId());
}
public function setAdminEditionLangId($langId)
{
$this->set('admin.edition_language', $langId);
$this->set('thelia.admin.edition.lang', $langId);
return $this;
}
@@ -98,43 +72,43 @@ class Session extends BaseSession
public function setCustomerUser(UserInterface $user)
{
$this->set('customer_user', $user);
$this->set('thelia.customer_user', $user);
return $this;
}
public function getCustomerUser()
{
return $this->get('customer_user');
return $this->get('thelia.customer_user');
}
public function clearCustomerUser()
{
return $this->remove('customer_user');
return $this->remove('thelia.customer_user');
}
// -- Admin user -----------------------------------------------------------
public function setAdminUser(UserInterface $user)
{
$this->set('admin_user', $user);
$this->set('thelia.admin_user', $user);
return $this;
}
public function getAdminUser()
{
return $this->get('admin_user');
return $this->get('thelia.admin_user');
}
public function clearAdminUser()
{
return $this->remove('admin_user');
return $this->remove('thelia.admin_user');
}
// -- Return page ----------------------------------------------------------
public function setReturnToUrl($url)
{
$this->set('return_to_url', $url);
$this->set('thelia.return_to_url', $url);
return $this;
}
@@ -144,7 +118,7 @@ class Session extends BaseSession
*/
public function getReturnToUrl()
{
return $this->get('return_to_url', URL::getIndexPage());
return $this->get('thelia.return_to_url', URL::getInstance()->getIndexPage());
}
// -- Cart ------------------------------------------------------------------
@@ -156,7 +130,7 @@ class Session extends BaseSession
*/
public function getCart()
{
$cart_id = $this->get("cart_id");
$cart_id = $this->get("thelia.cart_id");
$cart = null;
if ($cart_id) {
$cart = CartQuery::create()->findPk($cart_id);
@@ -193,7 +167,7 @@ class Session extends BaseSession
*/
public function setCart($cart_id)
{
$this->set("cart_id", $cart_id);
$this->set("thelia.cart_id", $cart_id);
return $this;
}
}
}

View File

@@ -69,7 +69,7 @@ abstract class BaseI18nLoop extends BaseLoop
$this->getBackend_context(),
$this->getLang(),
$search,
$this->request->getSession()->getLocale(),
$this->request->getSession()->getLang()->getLocale(),
$columns,
$foreignTable,
$foreignKey,

View File

@@ -54,6 +54,10 @@ abstract class BaseLoop
protected $args;
public $countable = true;
public $timestampable = false;
public $versionable = false;
/**
* Create a new Loop
*
@@ -235,31 +239,6 @@ abstract class BaseLoop
}
}
/**
* Setup ModelCriteria for proper i18n processing
*
* @param ModelCriteria $search the Propel Criteria to configure
* @param array $columns the i18n columns
* @param string $foreignTable the specified table (default to criteria table)
* @param string $foreignKey the foreign key in this table (default to criteria table)
*
* @return mixed the locale
*/
protected function configureI18nProcessing(ModelCriteria $search, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID', $forceReturn = false) {
/* manage translations */
return ModelCriteriaTools::getI18n(
$this->getBackend_context(),
$this->getLang(),
$search,
$this->request->getSession()->getLocale(),
$columns,
$foreignTable,
$foreignKey,
$forceReturn
);
}
/**
*
* this function have to be implement in your own loop class.

View File

@@ -23,6 +23,8 @@
namespace Thelia\Core\Template\Element;
use Propel\Runtime\Collection\ObjectCollection;
use Propel\Runtime\Util\PropelModelPager;
use Thelia\Core\Template\Element\LoopResultRow;
class LoopResult implements \Iterator
@@ -30,9 +32,14 @@ class LoopResult implements \Iterator
private $position;
protected $collection = array();
public function __construct()
public $modelCollection = null;
public function __construct($modelCollection = null)
{
$this->position = 0;
if($modelCollection instanceof ObjectCollection || $modelCollection instanceof PropelModelPager) {
$this->modelCollection = $modelCollection;
}
}
public function isEmpty()

View File

@@ -23,10 +23,37 @@
namespace Thelia\Core\Template\Element;
use Propel\Runtime\ActiveRecord\ActiveRecordInterface;
class LoopResultRow
{
protected $substitution = array();
public $model = null;
public $loopResult;
public $versionable = false;
public $timestampable = false;
public $countable = false;
public function __construct($loopResult = null, $model = null, $versionable = false, $timestampable = false, $countable = true)
{
if($model instanceof ActiveRecordInterface) {
$this->model = $model;
$this->versionable = $versionable;
$this->timestampable = $timestampable;
}
if($loopResult instanceof LoopResult) {
$this->loopResult = $loopResult;
$this->countable = $countable;
}
$this->assignDefaultOutputs();
}
public function set($key, $value)
{
$this->substitution[$key] = $value === null ? '' : $value;
@@ -49,4 +76,38 @@ class LoopResultRow
return array_keys($this->substitution);
}
protected function getTimestampOutputs()
{
return array(
array('CREATE_DATE', 'getCreatedAt'),
array('UPDATE_DATE', 'getUpdatedAt'),
);
}
protected function getVersionOutputs()
{
return array(
array('VERSION', 'getVersion'),
array('VERSION_DATE', 'getVersionCreatedAt'),
array('VERSION_AUTHOR', 'getVersionCreatedBy'),
);
}
protected function assignDefaultOutputs()
{
if(true === $this->versionable) {
foreach($this->getVersionOutputs() as $output) {
$this->set($output[0], $this->model->$output[1]());
}
}
if(true === $this->timestampable) {
foreach($this->getTimestampOutputs() as $output) {
$this->set($output[0], $this->model->$output[1]());
}
}
if(true === $this->countable) {
$this->set('LOOP_COUNT', 1 + $this->loopResult->getCount());
$this->set('LOOP_TOTAL', $this->loopResult->modelCollection->count());
}
}
}

View File

@@ -24,6 +24,7 @@
namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Collection\ObjectCollection;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
@@ -46,6 +47,8 @@ use Thelia\Type;
*/
class Address extends BaseLoop
{
public $timestampable = true;
/**
* @return ArgumentCollection
*/
@@ -109,10 +112,10 @@ class Address extends BaseLoop
$addresses = $this->search($search, $pagination);
$loopResult = new LoopResult();
$loopResult = new LoopResult($addresses);
foreach ($addresses as $address) {
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $address, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow
->set("ID", $address->getId())
->set("LABEL", $address->getLabel())

View File

@@ -55,6 +55,8 @@ use Thelia\Type\BooleanOrBothType;
*/
class Attribute extends BaseI18nLoop
{
public $timestampable = true;
/**
* @return ArgumentCollection
*/
@@ -150,10 +152,10 @@ class Attribute extends BaseI18nLoop
/* perform search */
$attributes = $this->search($search, $pagination);
$loopResult = new LoopResult();
$loopResult = new LoopResult($attributes);
foreach ($attributes as $attribute) {
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $attribute, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow->set("ID", $attribute->getId())
->set("IS_TRANSLATED",$attribute->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale)

View File

@@ -48,6 +48,8 @@ use Thelia\Type;
*/
class AttributeAvailability extends BaseI18nLoop
{
public $timestampable = true;
/**
* @return ArgumentCollection
*/
@@ -119,10 +121,10 @@ class AttributeAvailability extends BaseI18nLoop
/* perform search */
$attributesAv = $this->search($search, $pagination);
$loopResult = new LoopResult();
$loopResult = new LoopResult($attributesAv);
foreach ($attributesAv as $attributeAv) {
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $attributeAv, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow->set("ID", $attributeAv->getId())
->set("IS_TRANSLATED",$attributeAv->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale)

View File

@@ -50,6 +50,8 @@ use Thelia\Type;
*/
class AttributeCombination extends BaseI18nLoop
{
public $timestampable = true;
/**
* @return ArgumentCollection
*/
@@ -111,10 +113,10 @@ class AttributeCombination extends BaseI18nLoop
$attributeCombinations = $this->search($search, $pagination);
$loopResult = new LoopResult();
$loopResult = new LoopResult($attributeCombinations);
foreach ($attributeCombinations as $attributeCombination) {
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $attributeCombination, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow
->set("LOCALE",$locale)

View File

@@ -71,20 +71,20 @@ class Cart extends BaseLoop
*/
public function exec(&$pagination)
{
$result = new LoopResult();
$cartItems = $cart->getCartItems();
$result = new LoopResult($cartItems);
$cart = $this->getCart($this->request);
if ($cart === null) {
return $result;
}
$cartItems = $cart->getCartItems();
foreach ($cartItems as $cartItem) {
$product = $cartItem->getProduct();
//$product->setLocale($this->request->getSession()->getLocale());
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($result, $cartItem, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow->set("ITEM_ID", $cartItem->getId());
$loopResultRow->set("TITLE", $product->getTitle());

View File

@@ -64,6 +64,9 @@ use Thelia\Type\BooleanOrBothType;
*/
class Category extends BaseI18nLoop
{
public $timestampable = true;
public $versionable = true;
/**
* @return ArgumentCollection
*/
@@ -165,7 +168,7 @@ class Category extends BaseI18nLoop
/* @todo */
$notEmpty = $this->getNot_empty();
$loopResult = new LoopResult();
$loopResult = new LoopResult($categories);
foreach ($categories as $category) {
/*
@@ -173,7 +176,7 @@ class Category extends BaseI18nLoop
* if ($this->getNotEmpty() && $category->countAllProducts() == 0) continue;
*/
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $category, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow
->set("ID", $category->getId())
@@ -188,12 +191,6 @@ class Category extends BaseI18nLoop
->set("PRODUCT_COUNT", $category->countChild())
->set("VISIBLE", $category->getVisible() ? "1" : "0")
->set("POSITION", $category->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

@@ -51,6 +51,8 @@ use Thelia\Type\EnumListType;
*/
class Config extends BaseI18nLoop
{
public $timestampable = true;
/**
* @return ArgumentCollection
*/
@@ -146,11 +148,11 @@ class Config extends BaseI18nLoop
$results = $this->search($search, $pagination);
$loopResult = new LoopResult();
$loopResult = new LoopResult($results);
foreach ($results as $result) {
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $result, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow
->set("ID" , $result->getId())
@@ -164,13 +166,7 @@ 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

@@ -51,6 +51,9 @@ use Thelia\Type\BooleanOrBothType;
*/
class Content extends BaseI18nLoop
{
public $timestampable = true;
public $versionable = true;
/**
* @return ArgumentCollection
*/
@@ -207,10 +210,10 @@ class Content extends BaseI18nLoop
$contents = $this->search($search, $pagination);
$loopResult = new LoopResult();
$loopResult = new LoopResult($contents);
foreach ($contents as $content) {
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $content, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow->set("ID", $content->getId())
->set("IS_TRANSLATED",$content->getVirtualColumn('IS_TRANSLATED'))

View File

@@ -45,6 +45,8 @@ use Thelia\Model\ConfigQuery;
*/
class Country extends BaseI18nLoop
{
public $timestampable = true;
/**
* @return ArgumentCollection
*/
@@ -101,10 +103,10 @@ class Country extends BaseI18nLoop
/* perform search */
$countries = $this->search($search, $pagination);
$loopResult = new LoopResult();
$loopResult = new LoopResult($countries);
foreach ($countries as $country) {
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $country, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow->set("ID", $country->getId())
->set("IS_TRANSLATED",$country->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale)

View File

@@ -47,6 +47,8 @@ use Thelia\Type\EnumListType;
*/
class Currency extends BaseI18nLoop
{
public $timestampable = true;
/**
* @return ArgumentCollection
*/
@@ -163,11 +165,11 @@ class Currency extends BaseI18nLoop
/* perform search */
$currencies = $this->search($search, $pagination);
$loopResult = new LoopResult();
$loopResult = new LoopResult($currencies);
foreach ($currencies as $currency) {
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $currency, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow
->set("ID" , $currency->getId())
->set("IS_TRANSLATED" , $currency->getVirtualColumn('IS_TRANSLATED'))
@@ -178,9 +180,6 @@ class Currency extends BaseI18nLoop
->set("RATE" , $currency->getRate())
->set("POSITION" , $currency->getPosition())
->set("IS_DEFAULT" , $currency->getByDefault())
->set("CREATE_DATE" , $currency->getCreatedAt())
->set("UPDATE_DATE" , $currency->getUpdatedAt())
;
$loopResult->addRow($loopResultRow);

View File

@@ -24,6 +24,7 @@
namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Collection\ObjectCollection;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
@@ -46,6 +47,8 @@ use Thelia\Type;
*/
class Customer extends BaseLoop
{
public $timestampable = true;
/**
* @return ArgumentCollection
*/
@@ -113,10 +116,10 @@ class Customer extends BaseLoop
$customers = $this->search($search, $pagination);
$loopResult = new LoopResult();
$loopResult = new LoopResult($customers);
foreach ($customers as $customer) {
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $customer, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow->set("ID", $customer->getId());
$loopResultRow->set("REF", $customer->getRef());
$loopResultRow->set("TITLE", $customer->getTitleId());

View File

@@ -51,6 +51,8 @@ use Thelia\Type\BooleanOrBothType;
*/
class Feature extends BaseI18nLoop
{
public $timestampable = true;
/**
* @return ArgumentCollection
*/
@@ -142,10 +144,10 @@ class Feature extends BaseI18nLoop
/* perform search */
$features = $this->search($search, $pagination);
$loopResult = new LoopResult();
$loopResult = new LoopResult($features);
foreach ($features as $feature) {
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $feature, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow->set("ID", $feature->getId())
->set("IS_TRANSLATED",$feature->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale)

View File

@@ -46,6 +46,8 @@ use Thelia\Type;
*/
class FeatureAvailability extends BaseI18nLoop
{
public $timestampable = true;
/**
* @return ArgumentCollection
*/
@@ -117,10 +119,10 @@ class FeatureAvailability extends BaseI18nLoop
/* perform search */
$featuresAv = $this->search($search, $pagination);
$loopResult = new LoopResult();
$loopResult = new LoopResult($featuresAv);
foreach ($featuresAv as $featureAv) {
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $featureAv, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow->set("ID", $featureAv->getId())
->set("IS_TRANSLATED",$featureAv->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale)

View File

@@ -51,6 +51,8 @@ use Thelia\Type;
*/
class FeatureValue extends BaseI18nLoop
{
public $timestampable = true;
/**
* @return ArgumentCollection
*/
@@ -135,10 +137,10 @@ class FeatureValue extends BaseI18nLoop
$featureValues = $this->search($search, $pagination);
$loopResult = new LoopResult();
$loopResult = new LoopResult($featureValues);
foreach ($featureValues as $featureValue) {
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $featureValue, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow->set("ID", $featureValue->getId());
$loopResultRow

View File

@@ -46,6 +46,9 @@ use Thelia\Type\BooleanOrBothType;
*/
class Folder extends BaseI18nLoop
{
public $timestampable = true;
public $versionable = true;
/**
* @return ArgumentCollection
*/
@@ -142,7 +145,7 @@ class Folder extends BaseI18nLoop
/* @todo */
$notEmpty = $this->getNot_empty();
$loopResult = new LoopResult();
$loopResult = new LoopResult($folders);
foreach ($folders as $folder) {
@@ -151,7 +154,7 @@ class Folder extends BaseI18nLoop
* if ($notEmpty && $folder->countAllProducts() == 0) continue;
*/
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $folder, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow
->set("ID", $folder->getId())
@@ -166,12 +169,6 @@ class Folder extends BaseI18nLoop
->set("CONTENT_COUNT", $folder->countChild())
->set("VISIBLE", $folder->getVisible() ? "1" : "0")
->set("POSITION", $folder->getPosition())
->set("CREATE_DATE", $folder->getCreatedAt())
->set("UPDATE_DATE", $folder->getUpdatedAt())
->set("VERSION", $folder->getVersion())
->set("VERSION_DATE", $folder->getVersionCreatedAt())
->set("VERSION_AUTHOR", $folder->getVersionCreatedBy())
;
$loopResult->addRow($loopResultRow);

View File

@@ -45,6 +45,8 @@ use Thelia\Log\Tlog;
*/
class Image extends BaseI18nLoop
{
public $timestampable = true;
/**
* @var array Possible image sources
*/
@@ -264,7 +266,7 @@ class Image extends BaseI18nLoop
$results = $this->search($search, $pagination);
$loopResult = new LoopResult();
$loopResult = new LoopResult($results);
foreach ($results as $result) {
@@ -295,7 +297,7 @@ class Image extends BaseI18nLoop
// Dispatch image processing event
$this->dispatcher->dispatch(TheliaEvents::IMAGE_PROCESS, $event);
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $result, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow
->set("ID" , $result->getId())

View File

@@ -45,6 +45,8 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
*/
class Lang extends BaseLoop
{
public $timestampable = true;
/**
* @return ArgumentCollection
*/
@@ -84,11 +86,11 @@ class Lang extends BaseLoop
$results = $this->search($search, $pagination);
$loopResult = new LoopResult();
$loopResult = new LoopResult($results);
foreach ($results as $result) {
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $result, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow
->set("ID", $result->getId())
@@ -99,9 +101,6 @@ class Lang extends BaseLoop
->set("IS_DEFAULT", $result->getByDefault())
->set("URL", $result->getUrl())
->set("POSITION", $result->getPosition())
->set("CREATE_DATE", $result->getCreatedAt())
->set("UPDATE_DATE", $result->getUpdatedAt())
;
$loopResult->addRow($loopResultRow);

View File

@@ -49,6 +49,8 @@ use Thelia\Type\BooleanOrBothType;
*/
class Message extends BaseI18nLoop
{
public $timestampable = true;
/**
* @return ArgumentCollection
*/
@@ -101,11 +103,11 @@ class Message extends BaseI18nLoop
$results = $this->search($search, $pagination);
$loopResult = new LoopResult();
$loopResult = new LoopResult($results);
foreach ($results as $result) {
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $result, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow
->set("ID" , $result->getId())
@@ -117,8 +119,6 @@ class Message extends BaseI18nLoop
->set("TEXT_MESSAGE" , $result->getVirtualColumn('i18n_TEXT_MESSAGE'))
->set("HTML_MESSAGE" , $result->getVirtualColumn('i18n_HTML_MESSAGE'))
->set("SECURED" , $result->getSecured())
->set("CREATE_DATE" , $result->getCreatedAt())
->set("UPDATE_DATE" , $result->getUpdatedAt())
;
$loopResult->addRow($loopResultRow);

View File

@@ -58,6 +58,9 @@ use Thelia\Type\BooleanOrBothType;
*/
class Product extends BaseI18nLoop
{
public $timestampable = true;
public $versionable = true;
/**
* @return ArgumentCollection
*/
@@ -501,10 +504,10 @@ class Product extends BaseI18nLoop
/* perform search */
$products = $this->search($search, $pagination);
$loopResult = new LoopResult();
$loopResult = new LoopResult($products);
foreach ($products as $product) {
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $product, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow->set("ID", $product->getId())
->set("REF",$product->getRef())
@@ -519,12 +522,6 @@ 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

@@ -50,6 +50,8 @@ use Thelia\Type;
*/
class ProductSaleElements extends BaseLoop
{
public $timestampable = true;
/**
* @return ArgumentCollection
*/
@@ -117,10 +119,10 @@ class ProductSaleElements extends BaseLoop
$PSEValues = $this->search($search, $pagination);
$loopResult = new LoopResult();
$loopResult = new LoopResult($PSEValues);
foreach ($PSEValues as $PSEValue) {
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $PSEValue, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow->set("ID", $PSEValue->getId())
->set("QUANTITY", $PSEValue->getQuantity())

View File

@@ -45,6 +45,8 @@ use Thelia\Model\ConfigQuery;
*/
class Title extends BaseI18nLoop
{
public $timestampable = true;
/**
* @return ArgumentCollection
*/
@@ -78,10 +80,10 @@ class Title extends BaseI18nLoop
/* perform search */
$titles = $this->search($search, $pagination);
$loopResult = new LoopResult();
$loopResult = new LoopResult($titles);
foreach ($titles as $title) {
$loopResultRow = new LoopResultRow();
$loopResultRow = new LoopResultRow($loopResult, $title, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow->set("ID", $title->getId())
->set("IS_TRANSLATED",$title->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE",$locale)

View File

@@ -70,7 +70,7 @@ class SmartyAssetsManager
$url = $this->assetic_manager->asseticize(
$asset_dir.'/'.$asset_file,
$this->web_root."/".$this->path_relative_to_web_root,
URL::absoluteUrl($this->path_relative_to_web_root, null, URL::PATH_TO_FILE /* path only */),
URL::getInstance()->absoluteUrl($this->path_relative_to_web_root, null, URL::PATH_TO_FILE /* path only */),
$assetType,
$filters,
$debug

View File

@@ -71,11 +71,11 @@ class AdminUtilities extends AbstractSmartyPlugin
if ($permissions == null || $this->securityContext->isGranted("ADMIN", array($permission))) {
return sprintf(
'<a href="%s"><i class="icon-arrow-up"></i></a><span class="%s" data-id="%s">%s</span><a href="%s"><i class="icon-arrow-down"></i></a>',
URL::absoluteUrl("$path/positionUp", array($url_parameter => $id)),
URL::getInstance()->absoluteUrl("$path/positionUp", array($url_parameter => $id)),
$in_place_edit_class,
$id,
$position,
URL::absoluteUrl("$path/positionDown", array($url_parameter => $id))
URL::getInstance()->absoluteUrl("$path/positionDown", array($url_parameter => $id))
);
}
else {
@@ -125,7 +125,7 @@ class AdminUtilities extends AbstractSmartyPlugin
else
$output = '';
return sprintf('%s<a href="%s">%s</a>', $output, URL::absoluteUrl($path, array('order' => $order_change)), $label);
return sprintf('%s<a href="%s">%s</a>', $output, URL::getInstance()->absoluteUrl($path, array('order' => $order_change)), $label);
}

View File

@@ -138,22 +138,6 @@ class TheliaLoop extends AbstractSmartyPlugin
if ($loopResults->valid()) {
$loopResultRow = $loopResults->current();
// On first iteration, save variables that may be overwritten by this loop
if (! isset($this->varstack[$name])) {
$saved_vars = array();
$varlist = $loopResultRow->getVars();
$varlist[] = 'LOOP_COUNT';
$varlist[] = 'LOOP_TOTAL';
foreach ($varlist as $var) {
$saved_vars[$var] = $template->getTemplateVars($var);
}
$this->varstack[$name] = $saved_vars;
}
foreach ($loopResultRow->getVarVal() as $var => $val) {
$template->assign($var, $val);
}
@@ -161,10 +145,6 @@ class TheliaLoop extends AbstractSmartyPlugin
$repeat = true;
}
// Assign meta information
$template->assign('LOOP_COUNT', 1 + $loopResults->key());
$template->assign('LOOP_TOTAL', $loopResults->getCount());
// Loop is terminated. Cleanup.
if (! $repeat) {
// Restore previous variables values before terminating

View File

@@ -51,7 +51,7 @@ class UrlGenerator extends AbstractSmartyPlugin
$target = $this->getParam($params, 'target', null);
$url = URL::absoluteUrl($path, $this->getArgsFromParam($params, array('path', 'target')));
$url = URL::getInstance()->absoluteUrl($path, $this->getArgsFromParam($params, array('path', 'target')));
if ($target != null) $url .= '#'.$target;
@@ -102,7 +102,7 @@ class UrlGenerator extends AbstractSmartyPlugin
$args = $this->getArgsFromParam($params, array('view', 'action', 'target'));
if (! empty($action)) $args['action'] = $action;
return $forAdmin ? URL::adminViewUrl($view, $args) : URL::viewUrl($view, $args);
return $forAdmin ? URL::getInstance()->adminViewUrl($view, $args) : URL::getInstance()->viewUrl($view, $args);
}
/**
@@ -169,18 +169,16 @@ class UrlGenerator extends AbstractSmartyPlugin
protected function getCurrentUrl()
{
$retriever = URL::init()->retrieveCurrent($this->request);
return $retriever->rewrittenUrl === null ? $retriever->url : $retriever->rewrittenUrl ;
return URL::getInstance()->retrieveCurrent()->toString();
}
protected function getReturnToUrl()
{
return URL::absoluteUrl($this->request->getSession()->getReturnToUrl());
return URL::getInstance()->absoluteUrl($this->request->getSession()->getReturnToUrl());
}
protected function getIndexUrl()
{
return Url::getIndexPage();
return URL::getInstance()->getIndexPage();
}
}

View File

@@ -122,6 +122,9 @@ class TheliaHttpKernel extends HttpKernel
*/
protected function initParam(Request $request)
{
// Ensure an instaciation of URL service
$this->container->get('thelia.url.manager');
$lang = $this->detectLang($request);
if ($lang) {
@@ -139,6 +142,7 @@ class TheliaHttpKernel extends HttpKernel
protected function detectLang(Request $request)
{
$lang = null;
//first priority => lang parameter present in request (get or post)
if ($request->query->has("lang")) {
$lang = Model\LangQuery::create()->findOneByCode($request->query->get("lang"));

View File

@@ -135,7 +135,7 @@ abstract class BaseForm
$successUrl = $default;
}
return URL::absoluteUrl($successUrl);
return URL::getInstance()->absoluteUrl($successUrl);
}
public function createView()

View File

@@ -13,6 +13,8 @@ class Category extends BaseCategory
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
/**
* @return int number of child for the current category
*/
@@ -23,7 +25,7 @@ class Category extends BaseCategory
public function getUrl($locale)
{
return URL::init()->retrieve('category', $this->getId(), $locale);
return URL::getInstance()->retrieve('category', $this->getId(), $locale);
}
/**
@@ -46,18 +48,6 @@ class Category extends BaseCategory
$this->save();
}
public function getNextPosition($parent) {
$last = CategoryQuery::create()
->filterByParent($parent)
->orderByPosition(Criteria::DESC)
->limit(1)
->findOne()
;
return $last != null ? $last->getPosition() + 1 : 1;
}
/**
*
* count all products for current category and sub categories

View File

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

View File

@@ -11,6 +11,8 @@ class Currency extends BaseCurrency {
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
/**
* {@inheritDoc}
*/

View File

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

View File

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

View File

@@ -66,7 +66,7 @@ class RewritingRetriever
$allParametersWithoutView[$view . '_id'] = $viewId;
}
$this->url = URL::viewUrl($view, $allParametersWithoutView);
$this->url = URL::getInstance()->viewUrl($view, $allParametersWithoutView);
if($this->search !== null) {
$this->rewrittenUrl = $this->search->getUrl();
}
@@ -93,9 +93,17 @@ class RewritingRetriever
$allParametersWithoutView[$view . '_id'] = $viewId;
}
$this->url = URL::viewUrl($view, $allParametersWithoutView);
$this->url = URL::getInstance()->viewUrl($view, $allParametersWithoutView);
if($this->search !== null) {
$this->rewrittenUrl = $this->search->getUrl();
}
}
/**
* @return mixed
*/
public function toString()
{
return $this->rewrittenUrl === null ? $this->url : $this->rewrittenUrl;
}
}

View File

@@ -71,7 +71,7 @@ class RewritingRetrieverTest extends \PHPUnit_Framework_TestCase
$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);
$this->assertEquals(URL::getInstance()->viewUrl('view', array('locale' => 'fr_FR', 'view_id' => 1)), $retriever->url);
}
public function testLoadSpecificUrl()
@@ -93,6 +93,6 @@ class RewritingRetrieverTest extends \PHPUnit_Framework_TestCase
$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);
$this->assertEquals(URL::getInstance()->viewUrl('view', array('foo0' => 'bar0', 'foo1' => 'bar1', 'locale' => 'fr_FR', 'view_id' => 1)), $retriever->url);
}
}

View File

@@ -23,38 +23,112 @@
namespace Thelia\Tools;
use Symfony\Component\HttpFoundation\Request;
use Thelia\Model\ConfigQuery;
use Thelia\Rewriting\RewritingResolver;
use Thelia\Rewriting\RewritingRetriever;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Thelia\Core\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\DependencyInjection\ContainerInterface;
class URL
{
protected $resolver = null;
protected $retriever = null;
protected $container;
protected $environment;
const PATH_TO_FILE = true;
const WITH_INDEX_PAGE = false;
public function __construct()
private static $instance = null;
public function __construct(ContainerInterface $container, $environment)
{
// Allow singleton style calls once intanciated.
self::$instance = $this;
$this->container = $container;
$this->environment = $environment;
$this->retriever = new RewritingRetriever();
$this->resolver = new RewritingResolver();
echo "instanciation ok !";
}
public static function getIndexPage()
{
return ConfigQuery::read('base_url', '/') . "index_dev.php"; // FIXME !
/**
* Return this class instance, only once instanciated.
*
* @throws \RuntimeException if the class has not been instanciated.
* @return \Thelia\Tools\URL the instance.
*/
public static function getInstance() {
if (self::$instance == null) throw new \RuntimeException("URL instance is not initialized.");
return self::$instance;
}
public static function init()
/**
* Return the base URL, either the base_url defined in Config, or the URL
* of the current language, if 'one_domain_foreach_lang' is enabled.
*
* @return string the base URL, with a trailing '/'
*/
public function getBaseUrl()
{
return new URL();
$lang = $this->container
->get('request')
->getSession()
->getLang();
// Check if we have a specific URL for each lang.
$one_domain_foreach_lang = ConfigQuery::read("one_domain_foreach_lang", false);
if ($one_domain_foreach_lang == true) {
// If it's the case, get the current lang URL
$base_url = $lang->getUrl();
$err_msg_part = 'base_url';
}
else {
// Get the base URL
$base_url = ConfigQuery::read('base_url', null);
$err_msg_part = sprintf('base_url for lang %s', $lang->getCode());
}
// Be sure that base-url starts with http, give up if it's not the case.
if (substr($base_url, 0, 4) != 'http') {
throw new \InvalidArgumentException(
sprintf("The %s configuration parameter shoud contains the URL of your shop, starting with http or https.", $err_msg_part));
}
// Normalize the base_url
return rtrim($base_url, '/').'/';
}
/**
* @return string the index page, which is basically the base_url in prod environment.
*/
public function getIndexPage()
{
// Get the base URL
$base_url = $this->getBaseUrl();
// For dev environment, add the proper page.
if ($this->environment == 'dev') {
$base_url .= "index_dev.php";
}
return $base_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
* the script name (index_dev.php) is added to the URL in dev_environment, use
* $path_only = true to get a path without the index script.
*
* @param string $path the relative path
@@ -63,7 +137,7 @@ class URL
*
* @return string The generated URL
*/
public static function absoluteUrl($path, array $parameters = null, $path_only = self::WITH_INDEX_PAGE)
public function absoluteUrl($path, array $parameters = null, $path_only = self::WITH_INDEX_PAGE)
{
// Already absolute ?
if (substr($path, 0, 4) != 'http') {
@@ -72,9 +146,9 @@ class URL
* @etienne : can't be done here for it's already done in ::viewUrl / ::adminViewUrl
* @franck : should be done, as absoluteUrl() is sometimes called directly (see UrlGenerator::generateUrlFunction())
*/
$root = $path_only == self::PATH_TO_FILE ? ConfigQuery::read('base_url', '/') : self::getIndexPage();
//$root = $path_only == self::PATH_TO_FILE ? ConfigQuery::read('base_url', '/') : '';
$root = $path_only == self::PATH_TO_FILE ? $this->getBaseUrl() : $this->getIndexPage();
// Normalize root path
$base = rtrim($root, '/') . '/' . ltrim($path, '/');
} else
$base = $path;
@@ -90,6 +164,7 @@ class URL
$sepChar = strstr($base, '?') === false ? '?' : '&';
if ('' !== $queryString = rtrim($queryString, "&")) $queryString = $sepChar . $queryString;
return $base . $queryString;
}
@@ -101,11 +176,11 @@ class URL
*
* @return string The generated URL
*/
public static function adminViewUrl($viewName, array $parameters = array())
public function adminViewUrl($viewName, array $parameters = array())
{
$path = sprintf("%s/admin/%s", self::getIndexPage(), $viewName); // FIXME ! view= should not be required, check routing parameters
$path = sprintf("%s/admin/%s", $this->getIndexPage(), $viewName);
return self::absoluteUrl($path, $parameters);
return $this->absoluteUrl($path, $parameters);
}
/**
@@ -116,39 +191,49 @@ class URL
*
* @return string The generated URL
*/
public static function viewUrl($viewName, array $parameters = array())
public function viewUrl($viewName, array $parameters = array())
{
$path = sprintf("?view=%s", $viewName);
return self::absoluteUrl($path, $parameters);
return $this->absoluteUrl($path, $parameters);
}
/**
* Retrieve a rewritten URL from a view, a view id and a locale
*
* @param $view
* @param $viewId
* @param $viewLocale
*
* @return null|string
* @return RewritingRetriever You can access $url and $rewrittenUrl properties
*/
public function retrieve($view, $viewId, $viewLocale)
{
$rewrittenUrl = null;
if(ConfigQuery::isRewritingEnable()) {
$rewrittenUrl = $this->retriever->loadViewUrl($view, $viewLocale, $viewId);
$this->retriever->loadViewUrl($view, $viewLocale, $viewId);
}
return $rewrittenUrl === null ? self::viewUrl($view, array($view . '_id' => $viewId, 'locale' => $viewLocale)) : $rewrittenUrl;
// Bug: $rewrittenUrl n'est pas initialisé
//return $rewrittenUrl === null ? $this->viewUrl($view, array($view . '_id' => $viewId, 'locale' => $viewLocale)) : $rewrittenUrl;
return $this->viewUrl($view, array($view . '_id' => $viewId, 'locale' => $viewLocale));
}
public function retrieveCurrent(Request $request)
/**
* Retrieve a rewritten URL from the current request GET parameters
*
* @return RewritingRetriever You can access $url and $rewrittenUrl properties or use toString method
*/
public function retrieveCurrent()
{
$rewrittenUrl = null;
if(ConfigQuery::isRewritingEnable()) {
$view = $request->query->get('view', null);
$viewLocale = $request->query->get('locale', null);
$viewId = $view === null ? null : $request->query->get($view . '_id', null);
if (ConfigQuery::isRewritingEnable()) {
$allOtherParameters = $request->query->all();
$query = $this->container->get('request')->query;
$view = $query->get('view', null);
$viewLocale = $query->get('locale', null);
$viewId = $view === null ? null : $query->get($view . '_id', null);
$allOtherParameters = $query->all();
if($view !== null) {
unset($allOtherParameters['view']);
}
@@ -165,9 +250,17 @@ class URL
return $this->retriever;
}
/**
* Retrieve a rewritten URL from the current GET parameters or use toString method
*
* @param $url
*
* @return RewritingResolver
*/
public function resolve($url)
{
$this->resolver->load($url);
return $this->resolver;
}
}
}