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

# By Etienne Roudeix
# Via Etienne Roudeix
* 'master' of https://github.com/thelia/thelia:
  fix URL::retrieve
  global outputs in loops
This commit is contained in:
gmorel
2013-09-04 15:45:19 +02:00
35 changed files with 203 additions and 118 deletions

View File

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

View File

@@ -52,5 +52,6 @@
<route id="url-rewriting.check" path="/{rewritten_url}" methods="GET"> <route id="url-rewriting.check" path="/{rewritten_url}" methods="GET">
<default key="_controller">Thelia\Controller\Front\UrlRewritingController::check</default> <default key="_controller">Thelia\Controller\Front\UrlRewritingController::check</default>
<requirement key="rewritten_url">.*</requirement>
</route> </route>
</routes> </routes>

View File

@@ -54,6 +54,10 @@ abstract class BaseLoop
protected $args; protected $args;
public $countable = true;
public $timestampable = false;
public $versionable = false;
/** /**
* Create a new Loop * Create a new Loop
* *

View File

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

View File

@@ -23,10 +23,37 @@
namespace Thelia\Core\Template\Element; namespace Thelia\Core\Template\Element;
use Propel\Runtime\ActiveRecord\ActiveRecordInterface;
class LoopResultRow class LoopResultRow
{ {
protected $substitution = array(); 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) public function set($key, $value)
{ {
$this->substitution[$key] = $value === null ? '' : $value; $this->substitution[$key] = $value === null ? '' : $value;
@@ -49,4 +76,38 @@ class LoopResultRow
return array_keys($this->substitution); 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; namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Collection\ObjectCollection;
use Thelia\Core\Template\Element\BaseLoop; use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
@@ -46,6 +47,8 @@ use Thelia\Type;
*/ */
class Address extends BaseLoop class Address extends BaseLoop
{ {
public $timestampable = true;
/** /**
* @return ArgumentCollection * @return ArgumentCollection
*/ */
@@ -110,10 +113,10 @@ class Address extends BaseLoop
$addresses = $this->search($search, $pagination); $addresses = $this->search($search, $pagination);
$loopResult = new LoopResult(); $loopResult = new LoopResult($addresses);
foreach ($addresses as $address) { foreach ($addresses as $address) {
$loopResultRow = new LoopResultRow(); $loopResultRow = new LoopResultRow($loopResult, $address, $this->versionable, $this->timestampable, $this->countable);
$loopResultRow $loopResultRow
->set("ID", $address->getId()) ->set("ID", $address->getId())
->set("NAME", $address->getName()) ->set("NAME", $address->getName())

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -138,22 +138,6 @@ class TheliaLoop extends AbstractSmartyPlugin
if ($loopResults->valid()) { if ($loopResults->valid()) {
$loopResultRow = $loopResults->current(); $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) { foreach ($loopResultRow->getVarVal() as $var => $val) {
$template->assign($var, $val); $template->assign($var, $val);
} }
@@ -161,10 +145,6 @@ class TheliaLoop extends AbstractSmartyPlugin
$repeat = true; $repeat = true;
} }
// Assign meta information
$template->assign('LOOP_COUNT', 1 + $loopResults->key());
$template->assign('LOOP_TOTAL', $loopResults->getCount());
// Loop is terminated. Cleanup. // Loop is terminated. Cleanup.
if (! $repeat) { if (! $repeat) {
// Restore previous variables values before terminating // Restore previous variables values before terminating

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -98,4 +98,12 @@ class RewritingRetriever
$this->rewrittenUrl = $this->search->getUrl(); $this->rewrittenUrl = $this->search->getUrl();
} }
} }
/**
* @return mixed
*/
public function toString()
{
return $this->rewrittenUrl === null ? $this->url : $this->rewrittenUrl;
}
} }

View File

@@ -124,25 +124,32 @@ class URL
} }
/** /**
* Retrieve a rewritten URL from a view, a view id and a locale
*
* @param $view * @param $view
* @param $viewId * @param $viewId
* @param $viewLocale * @param $viewLocale
* *
* @return null|string * @return RewritingRetriever You can access $url and $rewrittenUrl properties
*/ */
public function retrieve($view, $viewId, $viewLocale) public function retrieve($view, $viewId, $viewLocale)
{ {
$rewrittenUrl = null;
if(ConfigQuery::isRewritingEnable()) { 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; return $this->retriever;
} }
/**
* Retrieve a rewritten URL from the current GET parameters
*
* @param Request $request
*
* @return RewritingRetriever You can access $url and $rewrittenUrl properties or use toString method
*/
public function retrieveCurrent(Request $request) public function retrieveCurrent(Request $request)
{ {
$rewrittenUrl = null;
if(ConfigQuery::isRewritingEnable()) { if(ConfigQuery::isRewritingEnable()) {
$view = $request->query->get('view', null); $view = $request->query->get('view', null);
$viewLocale = $request->query->get('locale', null); $viewLocale = $request->query->get('locale', null);
@@ -165,6 +172,13 @@ class URL
return $this->retriever; return $this->retriever;
} }
/**
* Retrieve a rewritten URL from the current GET parameters or use toString method
*
* @param $url
*
* @return RewritingResolver
*/
public function resolve($url) public function resolve($url)
{ {
$this->resolver->load($url); $this->resolver->load($url);

View File

@@ -1,14 +1,11 @@
<h2>ALL ATTRIBUTES AND THEIR AVAILABILITY</h2> <h2>ALL ATTRIBUTES</h2>
<ul> <ul>
{loop name="attr" type="attribute" order="manual" lang="2" backend_context="true"} {loop name="attr" type="attribute"}
<li> <li>
{if #IS_TRANSLATED == 1}#TITLE{else}to be translated{/if} #TITLE - (#LOOP_COUNT / #LOOP_TOTAL)<br />
<ul> created at {format_date date=$CREATE_DATE} - updated at {format_date date=$UPDATE_DATE}
{loop name="attrav" type="attribute_availability" order="manual" attribute="#ID" lang="3"} <hr />
<li>{if #IS_TRANSLATED == 1}#TITLE{else}to be translated{/if}</li>
{/loop}
</ul>
</li> </li>
{/loop} {/loop}
</ul> </ul>