diff --git a/core/lib/Thelia/Action/Image.php b/core/lib/Thelia/Action/Image.php index eabf03b0a..103633165 100755 --- a/core/lib/Thelia/Action/Image.php +++ b/core/lib/Thelia/Action/Image.php @@ -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), ); } -} +} \ No newline at end of file diff --git a/core/lib/Thelia/Action/PageNotFound.php b/core/lib/Thelia/Action/PageNotFound.php index c6f547fc4..a4d715fbb 100755 --- a/core/lib/Thelia/Action/PageNotFound.php +++ b/core/lib/Thelia/Action/PageNotFound.php @@ -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"); diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 58b6e53c2..ecf4e7b0b 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -72,6 +72,13 @@ + + + + + %kernel.environment% + + @@ -85,12 +92,6 @@ - - - - - - diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index 0ab559873..a4c621d5e 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -49,8 +49,11 @@ Thelia\Controller\Front\CartController::changeItem cart - + diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index d5a09a709..eab57394b 100755 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -174,7 +174,7 @@ 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)); } /** @@ -257,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. diff --git a/core/lib/Thelia/Controller/Admin/MessageController.php b/core/lib/Thelia/Controller/Admin/MessageController.php index 8b31e6b52..c024a5d34 100644 --- a/core/lib/Thelia/Controller/Admin/MessageController.php +++ b/core/lib/Thelia/Controller/Admin/MessageController.php @@ -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')); } } \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Front/BaseFrontController.php b/core/lib/Thelia/Controller/Front/BaseFrontController.php index b6d4a6f93..652e53254 100755 --- a/core/lib/Thelia/Controller/Front/BaseFrontController.php +++ b/core/lib/Thelia/Controller/Front/BaseFrontController.php @@ -44,6 +44,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)); } } diff --git a/core/lib/Thelia/Controller/Front/CustomerAddressController.php b/core/lib/Thelia/Controller/Front/CustomerAddressController.php index 4f44ce1d1..0d1eea308 100644 --- a/core/lib/Thelia/Controller/Front/CustomerAddressController.php +++ b/core/lib/Thelia/Controller/Front/CustomerAddressController.php @@ -41,7 +41,7 @@ class CustomerAddressController extends BaseFrontController public function createAction() { if ($this->getSecurityContext()->hasCustomerUser() === false) { - $this->redirect(URL::getIndexPage()); + $this->redirect(URL::getInstance()->getIndexPage()); } $addressCreate = new AddressForm($this->getRequest()); diff --git a/core/lib/Thelia/Controller/Front/CustomerController.php b/core/lib/Thelia/Controller/Front/CustomerController.php index 88e15396e..d753510a6 100755 --- a/core/lib/Thelia/Controller/Front/CustomerController.php +++ b/core/lib/Thelia/Controller/Front/CustomerController.php @@ -202,7 +202,7 @@ class CustomerController extends BaseFrontController } // Redirect to home page - $this->redirect(URL::getIndexPage()); + $this->redirect(URL::getInstance()->getIndexPage()); } /** diff --git a/core/lib/Thelia/Controller/Front/DefaultController.php b/core/lib/Thelia/Controller/Front/DefaultController.php index d9c5a681a..da7787365 100755 --- a/core/lib/Thelia/Controller/Front/DefaultController.php +++ b/core/lib/Thelia/Controller/Front/DefaultController.php @@ -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); diff --git a/core/lib/Thelia/Controller/Front/UrlRewritingController.php b/core/lib/Thelia/Controller/Front/UrlRewritingController.php index df2479969..2e725aecd 100755 --- a/core/lib/Thelia/Controller/Front/UrlRewritingController.php +++ b/core/lib/Thelia/Controller/Front/UrlRewritingController.php @@ -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 : diff --git a/core/lib/Thelia/Core/EventListener/ViewListener.php b/core/lib/Thelia/Core/EventListener/ViewListener.php index d55826d56..3bd3147a4 100755 --- a/core/lib/Thelia/Core/EventListener/ViewListener.php +++ b/core/lib/Thelia/Core/EventListener/ViewListener.php @@ -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())); } } diff --git a/core/lib/Thelia/Core/HttpFoundation/Session/Session.php b/core/lib/Thelia/Core/HttpFoundation/Session/Session.php index 53c4c45e8..4a486e488 100755 --- a/core/lib/Thelia/Core/HttpFoundation/Session/Session.php +++ b/core/lib/Thelia/Core/HttpFoundation/Session/Session.php @@ -118,7 +118,7 @@ class Session extends BaseSession */ public function getReturnToUrl() { - return $this->get('thelia.return_to_url', URL::getIndexPage()); + return $this->get('thelia.return_to_url', URL::getInstance()->getIndexPage()); } // -- Cart ------------------------------------------------------------------ diff --git a/core/lib/Thelia/Core/Template/Element/BaseLoop.php b/core/lib/Thelia/Core/Template/Element/BaseLoop.php index fc05b23a7..98ed8af33 100755 --- a/core/lib/Thelia/Core/Template/Element/BaseLoop.php +++ b/core/lib/Thelia/Core/Template/Element/BaseLoop.php @@ -54,6 +54,10 @@ abstract class BaseLoop protected $args; + public $countable = true; + public $timestampable = false; + public $versionable = false; + /** * Create a new Loop * diff --git a/core/lib/Thelia/Core/Template/Element/LoopResult.php b/core/lib/Thelia/Core/Template/Element/LoopResult.php index c3a97983f..169fdb4f7 100755 --- a/core/lib/Thelia/Core/Template/Element/LoopResult.php +++ b/core/lib/Thelia/Core/Template/Element/LoopResult.php @@ -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() diff --git a/core/lib/Thelia/Core/Template/Element/LoopResultRow.php b/core/lib/Thelia/Core/Template/Element/LoopResultRow.php index 8485bd78c..cfea52d8f 100755 --- a/core/lib/Thelia/Core/Template/Element/LoopResultRow.php +++ b/core/lib/Thelia/Core/Template/Element/LoopResultRow.php @@ -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()); + } + } } diff --git a/core/lib/Thelia/Core/Template/Loop/Address.php b/core/lib/Thelia/Core/Template/Loop/Address.php index 43bbbaefb..fab153969 100755 --- a/core/lib/Thelia/Core/Template/Loop/Address.php +++ b/core/lib/Thelia/Core/Template/Loop/Address.php @@ -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 */ @@ -110,10 +113,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("NAME", $address->getName()) diff --git a/core/lib/Thelia/Core/Template/Loop/Attribute.php b/core/lib/Thelia/Core/Template/Loop/Attribute.php index 79ffd4677..e967709f3 100755 --- a/core/lib/Thelia/Core/Template/Loop/Attribute.php +++ b/core/lib/Thelia/Core/Template/Loop/Attribute.php @@ -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) diff --git a/core/lib/Thelia/Core/Template/Loop/AttributeAvailability.php b/core/lib/Thelia/Core/Template/Loop/AttributeAvailability.php index 13e905670..cd5ad6564 100755 --- a/core/lib/Thelia/Core/Template/Loop/AttributeAvailability.php +++ b/core/lib/Thelia/Core/Template/Loop/AttributeAvailability.php @@ -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) diff --git a/core/lib/Thelia/Core/Template/Loop/AttributeCombination.php b/core/lib/Thelia/Core/Template/Loop/AttributeCombination.php index 53566c053..78cf33e21 100755 --- a/core/lib/Thelia/Core/Template/Loop/AttributeCombination.php +++ b/core/lib/Thelia/Core/Template/Loop/AttributeCombination.php @@ -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) diff --git a/core/lib/Thelia/Core/Template/Loop/Cart.php b/core/lib/Thelia/Core/Template/Loop/Cart.php index 27f295ed1..f9e5c00aa 100755 --- a/core/lib/Thelia/Core/Template/Loop/Cart.php +++ b/core/lib/Thelia/Core/Template/Loop/Cart.php @@ -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()); diff --git a/core/lib/Thelia/Core/Template/Loop/Category.php b/core/lib/Thelia/Core/Template/Loop/Category.php index 9d4a2b4ec..68ae33507 100755 --- a/core/lib/Thelia/Core/Template/Loop/Category.php +++ b/core/lib/Thelia/Core/Template/Loop/Category.php @@ -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); diff --git a/core/lib/Thelia/Core/Template/Loop/Config.php b/core/lib/Thelia/Core/Template/Loop/Config.php index a1bba2a98..8e03de636 100644 --- a/core/lib/Thelia/Core/Template/Loop/Config.php +++ b/core/lib/Thelia/Core/Template/Loop/Config.php @@ -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,10 +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()) - ; + ; $loopResult->addRow($loopResultRow); } diff --git a/core/lib/Thelia/Core/Template/Loop/Content.php b/core/lib/Thelia/Core/Template/Loop/Content.php index 58836daa7..baec33344 100755 --- a/core/lib/Thelia/Core/Template/Loop/Content.php +++ b/core/lib/Thelia/Core/Template/Loop/Content.php @@ -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')) diff --git a/core/lib/Thelia/Core/Template/Loop/Country.php b/core/lib/Thelia/Core/Template/Loop/Country.php index d031e135d..aee6492f7 100755 --- a/core/lib/Thelia/Core/Template/Loop/Country.php +++ b/core/lib/Thelia/Core/Template/Loop/Country.php @@ -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) diff --git a/core/lib/Thelia/Core/Template/Loop/Currency.php b/core/lib/Thelia/Core/Template/Loop/Currency.php index 6db6c6223..b7261ba45 100755 --- a/core/lib/Thelia/Core/Template/Loop/Currency.php +++ b/core/lib/Thelia/Core/Template/Loop/Currency.php @@ -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); diff --git a/core/lib/Thelia/Core/Template/Loop/Customer.php b/core/lib/Thelia/Core/Template/Loop/Customer.php index 478c3d5bb..1a4b84105 100755 --- a/core/lib/Thelia/Core/Template/Loop/Customer.php +++ b/core/lib/Thelia/Core/Template/Loop/Customer.php @@ -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()); diff --git a/core/lib/Thelia/Core/Template/Loop/Feature.php b/core/lib/Thelia/Core/Template/Loop/Feature.php index 4a631dda8..6c2401f42 100755 --- a/core/lib/Thelia/Core/Template/Loop/Feature.php +++ b/core/lib/Thelia/Core/Template/Loop/Feature.php @@ -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) diff --git a/core/lib/Thelia/Core/Template/Loop/FeatureAvailability.php b/core/lib/Thelia/Core/Template/Loop/FeatureAvailability.php index d298a5234..45eed6dc3 100755 --- a/core/lib/Thelia/Core/Template/Loop/FeatureAvailability.php +++ b/core/lib/Thelia/Core/Template/Loop/FeatureAvailability.php @@ -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) diff --git a/core/lib/Thelia/Core/Template/Loop/FeatureValue.php b/core/lib/Thelia/Core/Template/Loop/FeatureValue.php index a91e25cd0..700eff39c 100755 --- a/core/lib/Thelia/Core/Template/Loop/FeatureValue.php +++ b/core/lib/Thelia/Core/Template/Loop/FeatureValue.php @@ -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 diff --git a/core/lib/Thelia/Core/Template/Loop/Folder.php b/core/lib/Thelia/Core/Template/Loop/Folder.php index 95aedaed6..ca07ffa02 100755 --- a/core/lib/Thelia/Core/Template/Loop/Folder.php +++ b/core/lib/Thelia/Core/Template/Loop/Folder.php @@ -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); diff --git a/core/lib/Thelia/Core/Template/Loop/Image.php b/core/lib/Thelia/Core/Template/Loop/Image.php index 697ce5d73..793b5c03e 100755 --- a/core/lib/Thelia/Core/Template/Loop/Image.php +++ b/core/lib/Thelia/Core/Template/Loop/Image.php @@ -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()) diff --git a/core/lib/Thelia/Core/Template/Loop/Lang.php b/core/lib/Thelia/Core/Template/Loop/Lang.php index 3986fdb56..487acb565 100755 --- a/core/lib/Thelia/Core/Template/Loop/Lang.php +++ b/core/lib/Thelia/Core/Template/Loop/Lang.php @@ -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); diff --git a/core/lib/Thelia/Core/Template/Loop/Message.php b/core/lib/Thelia/Core/Template/Loop/Message.php index 9a73312dd..ad6bd29aa 100644 --- a/core/lib/Thelia/Core/Template/Loop/Message.php +++ b/core/lib/Thelia/Core/Template/Loop/Message.php @@ -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); diff --git a/core/lib/Thelia/Core/Template/Loop/Product.php b/core/lib/Thelia/Core/Template/Loop/Product.php index 65a2d4346..4d785b8b0 100755 --- a/core/lib/Thelia/Core/Template/Loop/Product.php +++ b/core/lib/Thelia/Core/Template/Loop/Product.php @@ -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", $product->getCreatedAt()) - ->set("UPDATE_DATE", $product->getUpdatedAt()) - ->set("VERSION", $product->getVersion()) - ->set("VERSION_DATE", $product->getVersionCreatedAt()) - ->set("VERSION_AUTHOR", $product->getVersionCreatedBy()) ; $loopResult->addRow($loopResultRow); diff --git a/core/lib/Thelia/Core/Template/Loop/ProductSaleElement.php b/core/lib/Thelia/Core/Template/Loop/ProductSaleElement.php index ec7cbc37f..7a1a0b8c8 100755 --- a/core/lib/Thelia/Core/Template/Loop/ProductSaleElement.php +++ b/core/lib/Thelia/Core/Template/Loop/ProductSaleElement.php @@ -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()) diff --git a/core/lib/Thelia/Core/Template/Loop/Title.php b/core/lib/Thelia/Core/Template/Loop/Title.php index cd7ec7d5d..38dcb3fe3 100755 --- a/core/lib/Thelia/Core/Template/Loop/Title.php +++ b/core/lib/Thelia/Core/Template/Loop/Title.php @@ -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) diff --git a/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php index a07eba565..17fe122d3 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php +++ b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php @@ -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 diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php index aab63177a..4e2c065fd 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php @@ -71,11 +71,11 @@ class AdminUtilities extends AbstractSmartyPlugin if ($permissions == null || $this->securityContext->isGranted("ADMIN", array($permission))) { return sprintf( '%s', - 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%s', $output, URL::absoluteUrl($path, array('order' => $order_change)), $label); + return sprintf('%s%s', $output, URL::getInstance()->absoluteUrl($path, array('order' => $order_change)), $label); } diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php index 91036517a..e7ee5e995 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php @@ -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 diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php index 635c03b8c..72b3b88fb 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php @@ -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(); } } diff --git a/core/lib/Thelia/Core/TheliaHttpKernel.php b/core/lib/Thelia/Core/TheliaHttpKernel.php index 7109f5ba2..950f08832 100755 --- a/core/lib/Thelia/Core/TheliaHttpKernel.php +++ b/core/lib/Thelia/Core/TheliaHttpKernel.php @@ -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")); diff --git a/core/lib/Thelia/Form/BaseForm.php b/core/lib/Thelia/Form/BaseForm.php index edb51ad2a..870f94505 100755 --- a/core/lib/Thelia/Form/BaseForm.php +++ b/core/lib/Thelia/Form/BaseForm.php @@ -135,7 +135,7 @@ abstract class BaseForm $successUrl = $default; } - return URL::absoluteUrl($successUrl); + return URL::getInstance()->absoluteUrl($successUrl); } public function createView() diff --git a/core/lib/Thelia/Model/Category.php b/core/lib/Thelia/Model/Category.php index 10c61adcd..e380457ca 100755 --- a/core/lib/Thelia/Model/Category.php +++ b/core/lib/Thelia/Model/Category.php @@ -25,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); } /** diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index f51915776..430408521 100755 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -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); } } diff --git a/core/lib/Thelia/Model/Folder.php b/core/lib/Thelia/Model/Folder.php index 2672c17de..5aab7c5bf 100755 --- a/core/lib/Thelia/Model/Folder.php +++ b/core/lib/Thelia/Model/Folder.php @@ -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); } /** diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index b4b036896..f02792285 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -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); } } diff --git a/core/lib/Thelia/Rewriting/RewritingRetriever.php b/core/lib/Thelia/Rewriting/RewritingRetriever.php index 7958af012..dfbe63517 100755 --- a/core/lib/Thelia/Rewriting/RewritingRetriever.php +++ b/core/lib/Thelia/Rewriting/RewritingRetriever.php @@ -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; + } } diff --git a/core/lib/Thelia/Tests/Rewriting/RewritingRetrieverTest.php b/core/lib/Thelia/Tests/Rewriting/RewritingRetrieverTest.php index 9a5036adc..8723e0096 100755 --- a/core/lib/Thelia/Tests/Rewriting/RewritingRetrieverTest.php +++ b/core/lib/Thelia/Tests/Rewriting/RewritingRetrieverTest.php @@ -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); } } diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index e6e3c32dd..1816f76ec 100755 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -30,34 +30,43 @@ 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 extends ContainerAware +class URL { - protected $container; - protected $request; - protected $resolver = null; protected $retriever = null; + protected $container; + protected $environment; + const PATH_TO_FILE = true; const WITH_INDEX_PAGE = false; private static $instance = null; - public function __construct(Request $request) + public function __construct(ContainerInterface $container, $environment) { - $this->request = $request; + // Allow singleton style calls once intanciated. + self::$instance = $this; + + $this->container = $container; + $this->environment = $environment; $this->retriever = new RewritingRetriever(); $this->resolver = new RewritingResolver(); - self::instance = $this; + echo "instanciation ok !"; } /** - * Give this class a singleton behavior + * Return this class instance, only once instanciated. + * + * @throws \RuntimeException if the class has not been instanciated. + * @return \Thelia\Tools\URL the instance. */ - public static getInstance() { + public static function getInstance() { + if (self::$instance == null) throw new \RuntimeException("URL instance is not initialized."); return self::$instance; } @@ -70,25 +79,31 @@ class URL extends ContainerAware */ public function getBaseUrl() { + $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 = $this->request->getSession()->getLang()->getUrl(); + $base_url = $lang->getUrl(); - $err_msg = 'base_url'; + $err_msg_part = 'base_url'; } else { // Get the base URL $base_url = ConfigQuery::read('base_url', null); - $err_msg = sprintf('base_url for lang %s', $this->request->getSession()->getCode()); + $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("The 'base_url' configuration parameter shoud contains the URL of your shop, starting with http or https."); + 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 @@ -103,11 +118,8 @@ class URL extends ContainerAware // Get the base URL $base_url = $this->getBaseUrl(); - // Check if we're in dev or prod - $env = $this->container->get(‘kernel’)->getEnvironment(); - - // For dev, add the proper page. - if ($env == 'dev') { + // For dev environment, add the proper page. + if ($this->environment == 'dev') { $base_url .= "index_dev.php"; } @@ -183,35 +195,45 @@ class URL extends ContainerAware { $path = sprintf("?view=%s", $viewName); - return $this>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 ? $this->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']); } @@ -228,9 +250,17 @@ class URL extends ContainerAware 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; } -} +} \ No newline at end of file diff --git a/templates/default/debug.html b/templates/default/debug.html index 21f69ad33..461e8eed7 100755 --- a/templates/default/debug.html +++ b/templates/default/debug.html @@ -1,14 +1,11 @@ -

ALL ATTRIBUTES AND THEIR AVAILABILITY

+

ALL ATTRIBUTES

    - {loop name="attr" type="attribute" order="manual" lang="2" backend_context="true"} + {loop name="attr" type="attribute"}
  • - {if #IS_TRANSLATED == 1}#TITLE{else}to be translated{/if} -
      - {loop name="attrav" type="attribute_availability" order="manual" attribute="#ID" lang="3"} -
    • {if #IS_TRANSLATED == 1}#TITLE{else}to be translated{/if}
    • - {/loop} -
    + #TITLE - (#LOOP_COUNT / #LOOP_TOTAL)
    + created at {format_date date=$CREATE_DATE} - updated at {format_date date=$UPDATE_DATE} +
  • {/loop}
\ No newline at end of file