backend trasnlation in loops

This commit is contained in:
Etienne Roudeix
2013-08-26 12:38:23 +02:00
parent 3005a65463
commit 96b3de7c84
14 changed files with 69 additions and 26 deletions

View File

@@ -80,6 +80,7 @@ abstract class BaseLoop
Argument::createIntTypeArgument('offset', 0), Argument::createIntTypeArgument('offset', 0),
Argument::createIntTypeArgument('page'), Argument::createIntTypeArgument('page'),
Argument::createIntTypeArgument('limit', PHP_INT_MAX), Argument::createIntTypeArgument('limit', PHP_INT_MAX),
Argument::createIntTypeArgument('backend_context', false),
); );
} }

View File

@@ -33,6 +33,7 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog; use Thelia\Log\Tlog;
use Thelia\Model\Base\LangQuery;
use Thelia\Model\Tools\ModelCriteriaTools; use Thelia\Model\Tools\ModelCriteriaTools;
use Thelia\Model\Base\CategoryQuery; use Thelia\Model\Base\CategoryQuery;
@@ -66,6 +67,7 @@ class Attribute extends BaseLoop
Argument::createIntListTypeArgument('category'), Argument::createIntListTypeArgument('category'),
Argument::createBooleanOrBothTypeArgument('visible', 1), Argument::createBooleanOrBothTypeArgument('visible', 1),
Argument::createIntListTypeArgument('exclude'), Argument::createIntListTypeArgument('exclude'),
Argument::createIntTypeArgument('lang'),
new Argument( new Argument(
'order', 'order',
new TypeCollection( new TypeCollection(
@@ -85,8 +87,18 @@ class Attribute extends BaseLoop
{ {
$search = AttributeQuery::create(); $search = AttributeQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
$x = LangQuery::create()->findOneById($lang);
/* manage translations */ /* manage translations */
if($backendContext) {
ModelCriteriaTools::getBackEndI18n($search, $lang === null ? $this->request->getSession()->getLocale() : $x);
} else {
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale()); ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
}
$id = $this->getId(); $id = $this->getId();

View File

@@ -59,6 +59,7 @@ class AttributeAvailability extends BaseLoop
Argument::createIntListTypeArgument('id'), Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('attribute'), Argument::createIntListTypeArgument('attribute'),
Argument::createIntListTypeArgument('exclude'), Argument::createIntListTypeArgument('exclude'),
Argument::createIntTypeArgument('lang'),
new Argument( new Argument(
'order', 'order',
new TypeCollection( new TypeCollection(

View File

@@ -77,6 +77,7 @@ class Category extends BaseLoop
Argument::createBooleanTypeArgument('current'), Argument::createBooleanTypeArgument('current'),
Argument::createBooleanTypeArgument('not_empty', 0), Argument::createBooleanTypeArgument('not_empty', 0),
Argument::createBooleanOrBothTypeArgument('visible', 1), Argument::createBooleanOrBothTypeArgument('visible', 1),
Argument::createIntTypeArgument('lang'),
new Argument( new Argument(
'order', 'order',
new TypeCollection( new TypeCollection(

View File

@@ -65,6 +65,7 @@ class Content extends BaseLoop
Argument::createBooleanTypeArgument('current_folder'), Argument::createBooleanTypeArgument('current_folder'),
Argument::createIntTypeArgument('depth', 1), Argument::createIntTypeArgument('depth', 1),
Argument::createBooleanOrBothTypeArgument('visible', 1), Argument::createBooleanOrBothTypeArgument('visible', 1),
Argument::createIntTypeArgument('lang'),
new Argument( new Argument(
'order', 'order',
new TypeCollection( new TypeCollection(

View File

@@ -56,7 +56,8 @@ class Country extends BaseLoop
Argument::createIntListTypeArgument('id'), Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('area'), Argument::createIntListTypeArgument('area'),
Argument::createBooleanTypeArgument('with_area'), Argument::createBooleanTypeArgument('with_area'),
Argument::createIntListTypeArgument('exclude') Argument::createIntListTypeArgument('exclude'),
Argument::createIntTypeArgument('lang')
); );
} }

View File

@@ -55,7 +55,8 @@ class Currency extends BaseLoop
return new ArgumentCollection( return new ArgumentCollection(
Argument::createIntListTypeArgument('id'), Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('exclude'), Argument::createIntListTypeArgument('exclude'),
Argument::createBooleanTypeArgument('default_only', false) Argument::createBooleanTypeArgument('default_only', false),
Argument::createIntTypeArgument('lang')
); );
} }

View File

@@ -64,6 +64,7 @@ class Feature extends BaseLoop
Argument::createIntListTypeArgument('category'), Argument::createIntListTypeArgument('category'),
Argument::createBooleanOrBothTypeArgument('visible', 1), Argument::createBooleanOrBothTypeArgument('visible', 1),
Argument::createIntListTypeArgument('exclude'), Argument::createIntListTypeArgument('exclude'),
Argument::createIntTypeArgument('lang'),
new Argument( new Argument(
'order', 'order',
new TypeCollection( new TypeCollection(

View File

@@ -57,6 +57,7 @@ class FeatureAvailability extends BaseLoop
Argument::createIntListTypeArgument('id'), Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('feature'), Argument::createIntListTypeArgument('feature'),
Argument::createIntListTypeArgument('exclude'), Argument::createIntListTypeArgument('exclude'),
Argument::createIntTypeArgument('lang'),
new Argument( new Argument(
'order', 'order',
new TypeCollection( new TypeCollection(

View File

@@ -59,6 +59,7 @@ class Folder extends BaseLoop
Argument::createBooleanTypeArgument('current'), Argument::createBooleanTypeArgument('current'),
Argument::createBooleanTypeArgument('not_empty', 0), Argument::createBooleanTypeArgument('not_empty', 0),
Argument::createBooleanOrBothTypeArgument('visible', 1), Argument::createBooleanOrBothTypeArgument('visible', 1),
Argument::createIntTypeArgument('lang'),
new Argument( new Argument(
'order', 'order',
new TypeCollection( new TypeCollection(

View File

@@ -85,6 +85,7 @@ class Product extends BaseLoop
Argument::createBooleanTypeArgument('current_category'), Argument::createBooleanTypeArgument('current_category'),
Argument::createIntTypeArgument('depth', 1), Argument::createIntTypeArgument('depth', 1),
Argument::createBooleanOrBothTypeArgument('visible', 1), Argument::createBooleanOrBothTypeArgument('visible', 1),
Argument::createIntTypeArgument('lang'),
new Argument( new Argument(
'order', 'order',
new TypeCollection( new TypeCollection(

View File

@@ -53,7 +53,8 @@ class Title extends BaseLoop
protected function getArgDefinitions() protected function getArgDefinitions()
{ {
return new ArgumentCollection( return new ArgumentCollection(
Argument::createIntListTypeArgument('id') Argument::createIntListTypeArgument('id'),
Argument::createIntTypeArgument('lang')
); );
} }

View File

@@ -43,6 +43,8 @@ class ModelCriteriaTools
$search->addJoinObject($askedLocaleJoin, $askedLocaleI18nAlias) $search->addJoinObject($askedLocaleJoin, $askedLocaleI18nAlias)
->addJoinCondition($askedLocaleI18nAlias ,'`' . $askedLocaleI18nAlias . '`.LOCALE = ?', $askedLocale, null, \PDO::PARAM_STR); ->addJoinCondition($askedLocaleI18nAlias ,'`' . $askedLocaleI18nAlias . '`.LOCALE = ?', $askedLocale, null, \PDO::PARAM_STR);
$search->withColumn('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'TRANSLATION_EXISTS');
foreach($columns as $column) { foreach($columns as $column) {
$search->withColumn('`' . $askedLocaleI18nAlias . '`.`' . $column . '`', $aliasPrefix . 'i18n_' . $column); $search->withColumn('`' . $askedLocaleI18nAlias . '`.`' . $column . '`', $aliasPrefix . 'i18n_' . $column);
} }
@@ -63,6 +65,8 @@ class ModelCriteriaTools
$search->addJoinObject($askedLocaleJoin, $askedLocaleI18nAlias) $search->addJoinObject($askedLocaleJoin, $askedLocaleI18nAlias)
->addJoinCondition($askedLocaleI18nAlias ,'`' . $askedLocaleI18nAlias . '`.LOCALE = ?', $askedLocale, null, \PDO::PARAM_STR); ->addJoinCondition($askedLocaleI18nAlias ,'`' . $askedLocaleI18nAlias . '`.LOCALE = ?', $askedLocale, null, \PDO::PARAM_STR);
$search->withColumn('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'TRANSLATION_EXISTS');
$search->where('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.ID)')->_or()->where('NOT ISNULL(`' . $defaultLocaleI18nAlias . '`.ID)'); $search->where('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.ID)')->_or()->where('NOT ISNULL(`' . $defaultLocaleI18nAlias . '`.ID)');
foreach($columns as $column) { foreach($columns as $column) {
@@ -70,4 +74,29 @@ class ModelCriteriaTools
} }
} }
} }
public static function getBackEndI18n(ModelCriteria &$search, $askedLocale, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID')
{
if($foreignTable === null) {
$foreignTable = $search->getTableMap()->getName();
$aliasPrefix = '';
} else {
$aliasPrefix = $foreignTable . '_';
}
$askedLocaleI18nAlias = 'asked_locale_i18n';
$askedLocaleJoin = new Join();
$askedLocaleJoin->addExplicitCondition($search->getTableMap()->getName(), $foreignKey, null, $foreignTable . '_i18n', 'ID', $askedLocaleI18nAlias);
$askedLocaleJoin->setJoinType(Criteria::LEFT_JOIN);
$search->addJoinObject($askedLocaleJoin, $askedLocaleI18nAlias)
->addJoinCondition($askedLocaleI18nAlias ,'`' . $askedLocaleI18nAlias . '`.LOCALE = ?', $askedLocale, null, \PDO::PARAM_STR);
$search->withColumn('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'TRANSLATION_EXISTS');
foreach($columns as $column) {
$search->withColumn('`' . $askedLocaleI18nAlias . '`.`' . $column . '`', $aliasPrefix . 'i18n_' . $column);
}
}
} }

View File

@@ -1,23 +1,14 @@
{*loop name="product" type="product" new="on" promo="on" min_stock="20" attribute_non_strict_match="min_stock,promo"} <h2>ALL ATTRIBUTES AND THEIR AVAILABILITY</h2>
<h3>PRODUCT : #REF / #TITLE (#ID)</h3>
{/loop*}
{*loop name="product" type="product" min_weight="1000" max_weight="6000" attribute_non_strict_match="*"} <ul>
<h3>PRODUCT : #REF / #TITLE (#ID)</h3> {loop name="attr" type="attribute" order="manual"}
{/loop*} <li>
#TITLE
{*loop name="product" type="product" min_price="100" max_price="300" min_stock="4" min_weight="6000" max_weight="7000" attribute_non_strict_match="*" promo="on"} <ul>
<h3>PRODUCT : #REF / #TITLE (#ID)</h3> {loop name="attrav" type="attribute_availability" order="manual" attribute="#ID"}
{/loop*} <li>#TITLE</li>
{/loop}
{*loop name="product" type="product" promo="0" min_stock="4" order="promo,min_price"} </ul>
<h3>PRODUCT : #REF / #TITLE (#ID)</h3> </li>
{/loop*} {/loop}
</ul>
{*loop name="product" type="product" order="promo,min_price"}
<h3>PRODUCT : #REF / #TITLE (#ID) / NEW : #NEW / PROMO : #PROMO / best price : #BEST_PRICE</h3>
{/loop*}
{loop name="product" type="product"}
<h3>PRODUCT : #REF / #TITLE</h3>
{/loop}