backend loop translation

This commit is contained in:
Etienne Roudeix
2013-08-26 14:05:29 +02:00
parent 96b3de7c84
commit 9174e5154e
19 changed files with 380 additions and 304 deletions

View File

@@ -15,6 +15,7 @@
<loop class="Thelia\Core\Template\Loop\Category" name="category"/>
<loop class="Thelia\Core\Template\Loop\Content" name="content"/>
<loop class="Thelia\Core\Template\Loop\Country" name="country"/>
<loop class="Thelia\Core\Template\Loop\Currency" name="currency"/>
<loop class="Thelia\Core\Template\Loop\Customer" name="customer"/>
<loop class="Thelia\Core\Template\Loop\Feature" name="feature"/>
<loop class="Thelia\Core\Template\Loop\FeatureAvailability" name="feature_availability"/>

View File

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

View File

@@ -91,14 +91,8 @@ class Attribute extends BaseLoop
$lang = $this->getLang();
$x = LangQuery::create()->findOneById($lang);
/* 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($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
$id = $this->getId();
@@ -163,6 +157,7 @@ class Attribute extends BaseLoop
foreach ($attributes as $attribute) {
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $attribute->getId())
->set("IS_TRANSLATED",$attribute->getVirtualColumn('IS_TRANSLATED'))
->set("TITLE",$attribute->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $attribute->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $attribute->getVirtualColumn('i18n_DESCRIPTION'))

View File

@@ -79,8 +79,12 @@ class AttributeAvailability extends BaseLoop
{
$search = AttributeAvQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
$id = $this->getId();
@@ -127,6 +131,7 @@ class AttributeAvailability extends BaseLoop
foreach ($attributesAv as $attributeAv) {
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $attributeAv->getId())
->set("IS_TRANSLATED",$attributeAv->getVirtualColumn('IS_TRANSLATED'))
->set("TITLE",$attributeAv->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $attributeAv->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $attributeAv->getVirtualColumn('i18n_DESCRIPTION'))

View File

@@ -79,7 +79,7 @@ class AttributeCombination extends BaseLoop
$search = AttributeCombinationQuery::create();
/* manage attribute translations */
ModelCriteriaTools::getI18n(
ModelCriteriaTools::getFrontEndI18n(
$search,
ConfigQuery::read("default_lang_without_translation", 1),
$this->request->getSession()->getLocale(),
@@ -89,7 +89,7 @@ class AttributeCombination extends BaseLoop
);
/* manage attributeAv translations */
ModelCriteriaTools::getI18n(
ModelCriteriaTools::getFrontEndI18n(
$search,
ConfigQuery::read("default_lang_without_translation", 1),
$this->request->getSession()->getLocale(),

View File

@@ -98,8 +98,12 @@ class Category extends BaseLoop
{
$search = CategoryQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
$id = $this->getId();
@@ -175,6 +179,7 @@ class Category extends BaseLoop
$loopResultRow
->set("ID", $category->getId())
->set("IS_TRANSLATED",$category->getVirtualColumn('IS_TRANSLATED'))
->set("TITLE",$category->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $category->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $category->getVirtualColumn('i18n_DESCRIPTION'))

View File

@@ -88,8 +88,12 @@ class Content extends BaseLoop
{
$search = ContentQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
$id = $this->getId();
@@ -216,6 +220,7 @@ class Content extends BaseLoop
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $content->getId())
->set("IS_TRANSLATED",$content->getVirtualColumn('IS_TRANSLATED'))
->set("TITLE",$content->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $content->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $content->getVirtualColumn('i18n_DESCRIPTION'))

View File

@@ -70,8 +70,12 @@ class Country extends BaseLoop
{
$search = CountryQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
$id = $this->getId();
@@ -109,6 +113,7 @@ class Country extends BaseLoop
foreach ($countries as $country) {
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $country->getId())
->set("IS_TRANSLATED",$country->getVirtualColumn('IS_TRANSLATED'))
->set("TITLE",$country->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $country->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $country->getVirtualColumn('i18n_DESCRIPTION'))

View File

@@ -69,8 +69,12 @@ class Currency extends BaseLoop
{
$search = CurrencyQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale(), array('NAME'));
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale(), array('NAME'));
$id = $this->getId();
@@ -100,8 +104,10 @@ class Currency extends BaseLoop
foreach ($currencies as $currency) {
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $currency->getId())
->set("IS_TRANSLATED",$currency->getVirtualColumn('IS_TRANSLATED'))
->set("NAME",$currency->getVirtualColumn('i18n_NAME'))
->set("ISOCODE", $currency->getCode())
->set("SYMBOL", $currency->getSymbol())
->set("RATE", $currency->getRate())
->set("IS_DEFAULT", $currency->getByDefault());

View File

@@ -84,8 +84,12 @@ class Feature extends BaseLoop
{
$search = FeatureQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
$id = $this->getId();
@@ -150,6 +154,7 @@ class Feature extends BaseLoop
foreach ($features as $feature) {
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $feature->getId())
->set("IS_TRANSLATED",$feature->getVirtualColumn('IS_TRANSLATED'))
->set("TITLE",$feature->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $feature->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $feature->getVirtualColumn('i18n_DESCRIPTION'))

View File

@@ -77,8 +77,12 @@ class FeatureAvailability extends BaseLoop
{
$search = FeatureAvQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
$id = $this->getId();
@@ -125,6 +129,7 @@ class FeatureAvailability extends BaseLoop
foreach ($featuresAv as $featureAv) {
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $featureAv->getId())
->set("IS_TRANSLATED",$featureAv->getVirtualColumn('IS_TRANSLATED'))
->set("TITLE",$featureAv->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $featureAv->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $featureAv->getVirtualColumn('i18n_DESCRIPTION'))

View File

@@ -84,7 +84,7 @@ class FeatureValue extends BaseLoop
$search = FeatureProductQuery::create();
/* manage featureAv translations */
ModelCriteriaTools::getI18n(
ModelCriteriaTools::getFrontEndI18n(
$search,
ConfigQuery::read("default_lang_without_translation", 1),
$this->request->getSession()->getLocale(),

View File

@@ -80,8 +80,12 @@ class Folder extends BaseLoop
{
$search = FolderQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
$id = $this->getId();
@@ -158,6 +162,7 @@ class Folder extends BaseLoop
$loopResultRow
->set("ID", $folder->getId())
->set("IS_TRANSLATED",$folder->getVirtualColumn('IS_TRANSLATED'))
->set("TITLE",$folder->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $folder->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $folder->getVirtualColumn('i18n_DESCRIPTION'))

View File

@@ -138,8 +138,12 @@ class Product extends BaseLoop
{
$search = ProductQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
$attributeNonStrictMatch = $this->getAttribute_non_strict_match();
$isPSELeftJoinList = array();
@@ -511,6 +515,7 @@ class Product extends BaseLoop
$loopResultRow->set("ID", $product->getId())
->set("REF",$product->getRef())
->set("IS_TRANSLATED",$product->getVirtualColumn('IS_TRANSLATED'))
->set("TITLE",$product->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $product->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $product->getVirtualColumn('i18n_DESCRIPTION'))

View File

@@ -67,8 +67,12 @@ class Title extends BaseLoop
{
$search = CustomerTitleQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */
ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale(), array('SHORT', 'LONG'));
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale(), array('SHORT', 'LONG'));
$id = $this->getId();
@@ -86,6 +90,7 @@ class Title extends BaseLoop
foreach ($titles as $title) {
$loopResultRow = new LoopResultRow();
$loopResultRow->set("ID", $title->getId())
->set("IS_TRANSLATED",$title->getVirtualColumn('IS_TRANSLATED'))
->set("DEFAULT", $title->getByDefault())
->set("SHORT", $title->getVirtualColumn('i18n_SHORT'))
->set("LONG", $title->getVirtualColumn('i18n_LONG'));

View File

@@ -23,7 +23,7 @@ class ModelCriteriaTools
* @param null $foreignTable
* @param string $foreignKey
*/
public static function getI18n(ModelCriteria &$search, $defaultLangWithoutTranslation, $askedLocale, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID')
public static function getFrontEndI18n(ModelCriteria &$search, $defaultLangWithoutTranslation, $askedLocale, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID')
{
if($foreignTable === null) {
$foreignTable = $search->getTableMap()->getName();
@@ -43,7 +43,7 @@ class ModelCriteriaTools
$search->addJoinObject($askedLocaleJoin, $askedLocaleI18nAlias)
->addJoinCondition($askedLocaleI18nAlias ,'`' . $askedLocaleI18nAlias . '`.LOCALE = ?', $askedLocale, null, \PDO::PARAM_STR);
$search->withColumn('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'TRANSLATION_EXISTS');
$search->withColumn('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'IS_TRANSLATED');
foreach($columns as $column) {
$search->withColumn('`' . $askedLocaleI18nAlias . '`.`' . $column . '`', $aliasPrefix . 'i18n_' . $column);
@@ -65,7 +65,7 @@ class ModelCriteriaTools
$search->addJoinObject($askedLocaleJoin, $askedLocaleI18nAlias)
->addJoinCondition($askedLocaleI18nAlias ,'`' . $askedLocaleI18nAlias . '`.LOCALE = ?', $askedLocale, null, \PDO::PARAM_STR);
$search->withColumn('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'TRANSLATION_EXISTS');
$search->withColumn('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'IS_TRANSLATED');
$search->where('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.ID)')->_or()->where('NOT ISNULL(`' . $defaultLocaleI18nAlias . '`.ID)');
@@ -93,10 +93,26 @@ class ModelCriteriaTools
$search->addJoinObject($askedLocaleJoin, $askedLocaleI18nAlias)
->addJoinCondition($askedLocaleI18nAlias ,'`' . $askedLocaleI18nAlias . '`.LOCALE = ?', $askedLocale, null, \PDO::PARAM_STR);
$search->withColumn('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'TRANSLATION_EXISTS');
$search->withColumn('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'IS_TRANSLATED');
foreach($columns as $column) {
$search->withColumn('`' . $askedLocaleI18nAlias . '`.`' . $column . '`', $aliasPrefix . 'i18n_' . $column);
}
}
public static function getI18n($backendContext, $lang, ModelCriteria &$search, $defaultLangWithoutTranslation, $currentLocale, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID')
{
if($lang !== null) {
$localeSearch = LangQuery::create()->findOneById($lang);
if($localeSearch === null) {
throw new \InvalidArgumentException('Incorrect lang argument given in attribute loop');
}
}
if($backendContext) {
self::getBackEndI18n($search, $lang === null ? $currentLocale : $localeSearch->getLocale(), $columns, $foreignTable, $foreignKey);
} else {
self::getFrontEndI18n($search, $defaultLangWithoutTranslation, $lang === null ? $currentLocale : $localeSearch->getLocale(), $columns, $foreignTable, $foreignKey);
}
}
}