working on loop translation

This commit is contained in:
Etienne Roudeix
2013-08-21 16:32:48 +02:00
parent 9dbd8a283b
commit 2e6cbe637a
3 changed files with 113 additions and 46 deletions

View File

@@ -156,10 +156,32 @@ class Category extends BaseLoop
* @todo : verify here if we want results for row without translations.
*/
$search->joinWithI18n(
$this->request->getSession()->getLocale(),
(ConfigQuery::read("default_lang_without_translation", 1)) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN
);
if(ConfigQuery::read("default_lang_without_translation", 1) == 0) {
/*
* don't use the following to be able to use the same getter than below
* $search->joinWithI18n( $this->request->getSession()->getLocale(), Criteria::INNER_JOIN );
*/
$search->joinCategoryI18n('asked_locale_i18n', Criteria::INNER_JOIN)
->addJoinCondition('asked_locale_i18n' ,'`asked_locale_i18n`.LOCALE = ?', 'en_EN', null, \PDO::PARAM_STR);
$search->withColumn('`asked_locale_i18n`.TITLE', 'i18n_TITLE');
$search->withColumn('`asked_locale_i18n`.CHAPO', 'i18n_CHAPO');
$search->withColumn('`asked_locale_i18n`.DESCRIPTION', 'i18n_DESCRIPTION');
$search->withColumn('`asked_locale_i18n`.POSTSCRIPTUM', 'i18n_POSTSCRIPTUM');
} else {
$search->joinCategoryI18n('default_locale_i18n')
->addJoinCondition('default_locale_i18n' ,'`default_locale_i18n`.LOCALE = ?', 'fr_FR', null, \PDO::PARAM_STR);
$search->joinCategoryI18n('asked_locale_i18n')
->addJoinCondition('asked_locale_i18n' ,'`asked_locale_i18n`.LOCALE = ?', 'en_EN', null, \PDO::PARAM_STR);
$search->where('NOT ISNULL(`asked_locale_i18n`.ID)')->_or()->where('NOT ISNULL(`default_locale_i18n`.ID)');
$search->withColumn('CASE WHEN ISNULL(`asked_locale_i18n`.ID) THEN `asked_locale_i18n`.TITLE ELSE `asked_locale_i18n`.TITLE END', 'i18n_TITLE');
$search->withColumn('CASE WHEN ISNULL(`asked_locale_i18n`.ID) THEN `asked_locale_i18n`.CHAPO ELSE `asked_locale_i18n`.CHAPO END', 'i18n_CHAPO');
$search->withColumn('CASE WHEN ISNULL(`asked_locale_i18n`.ID) THEN `asked_locale_i18n`.DESCRIPTION ELSE `asked_locale_i18n`.DESCRIPTION END', 'i18n_DESCRIPTION');
$search->withColumn('CASE WHEN ISNULL(`asked_locale_i18n`.ID) THEN `asked_locale_i18n`.POSTSCRIPTUM ELSE `asked_locale_i18n`.POSTSCRIPTUM END', 'i18n_POSTSCRIPTUM');
}
$categories = $this->search($search, $pagination);
@@ -171,15 +193,16 @@ class Category extends BaseLoop
if ($this->getNotEmpty() && $category->countAllProducts() == 0) continue;
$x = $category->getTitle();
$loopResultRow = new LoopResultRow();
$loopResultRow
->set("ID", $category->getId())
->set("TITLE",$category->getTitle())
->set("CHAPO", $category->getChapo())
->set("DESCRIPTION", $category->getDescription())
->set("POSTSCRIPTUM", $category->getPostscriptum())
->set("TITLE",$category->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $category->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $category->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM", $category->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("PARENT", $category->getParent())
->set("URL", $category->getUrl())
->set("PRODUCT_COUNT", $category->countChild())

View File

@@ -35,6 +35,7 @@ use Thelia\Log\Tlog;
use Thelia\Model\Base\FeatureProductQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Model\FeatureAvQuery;
use Thelia\Type\TypeCollection;
use Thelia\Type;
@@ -132,7 +133,12 @@ class FeatureValue extends BaseLoop
$loopResultRow->set("PERSONAL_VALUE", $featureValue->getByDefault());
$featureAvailability = $featureValue->getFeatureAv();
$featureAvailability = null;
if($featureValue->getFeatureAvId() !== null) {
$featureAvailability = FeatureAvQuery::create()
->joinWithI18n('fr_FR')
->findPk($featureValue->getFeatureAvId());
}
$loopResultRow->set("TITLE", ($featureAvailability === null ? '' : $featureAvailability->getTitle()));
$loopResultRow->set("CHAPO", ($featureAvailability === null ? '' : $featureAvailability->getChapo()));

View File

@@ -41,56 +41,70 @@ try {
->find();
$feature->delete();
$feature = Thelia\Model\FeatureI18nQuery::create()
->find();
$feature->delete();
$featureAv = Thelia\Model\FeatureAvQuery::create()
->find();
$featureAv->delete();
$featureAv = Thelia\Model\FeatureAvI18nQuery::create()
->find();
$featureAv->delete();
$attribute = Thelia\Model\AttributeQuery::create()
->find();
$attribute->delete();
$attribute = Thelia\Model\AttributeI18nQuery::create()
->find();
$attribute->delete();
$attributeAv = Thelia\Model\AttributeAvQuery::create()
->find();
$attributeAv->delete();
$attributeAv = Thelia\Model\AttributeAvI18nQuery::create()
->find();
$attributeAv->delete();
$category = Thelia\Model\CategoryQuery::create()
->find();
$category->delete();
$category = Thelia\Model\CategoryI18nQuery::create()
->find();
$category->delete();
$product = Thelia\Model\ProductQuery::create()
->find();
$product->delete();
$product = Thelia\Model\ProductI18nQuery::create()
->find();
$product->delete();
$customer = Thelia\Model\CustomerQuery::create()
->find();
$customer->delete();
$customer = new Thelia\Model\Customer();
$customer->createOrUpdate(
1,
"thelia",
"thelia",
"5 rue rochon",
"",
"",
"0102030405",
"0601020304",
"63000",
"clermont-ferrand",
64,
"test@thelia.net",
"azerty"
);
$folder = Thelia\Model\FolderQuery::create()
->find();
$folder->delete();
$folder = Thelia\Model\FolderI18nQuery::create()
->find();
$folder->delete();
$content = Thelia\Model\ContentQuery::create()
->find();
$content->delete();
$content = Thelia\Model\ContentI18nQuery::create()
->find();
$content->delete();
$accessory = Thelia\Model\AccessoryQuery::create()
->find();
$accessory->delete();
@@ -105,15 +119,32 @@ try {
$stmt = $con->prepare("SET foreign_key_checks = 1");
$stmt->execute();
//customer
$customer = new Thelia\Model\Customer();
$customer->createOrUpdate(
1,
"thelia",
"thelia",
"5 rue rochon",
"",
"",
"0102030405",
"0601020304",
"63000",
"clermont-ferrand",
64,
"test@thelia.net",
"azerty"
);
//features and features_av
$featureList = array();
for($i=0; $i<4; $i++) {
$feature = new Thelia\Model\Feature();
$feature->setVisible(rand(1, 10)>7 ? 0 : 1);
$feature->setPosition($i);
$feature->setTitle($faker->text(20));
$feature->setDescription($faker->text(50));
setI18n($faker, $feature);
$feature->save();
$featureId = $feature->getId();
@@ -123,8 +154,7 @@ try {
$featureAv = new Thelia\Model\FeatureAv();
$featureAv->setFeature($feature);
$featureAv->setPosition($j);
$featureAv->setTitle($faker->text(20));
$featureAv->setDescription($faker->text(255));
setI18n($faker, $featureAv);
$featureAv->save();
$featureList[$featureId][] = $featureAv->getId();
@@ -136,8 +166,7 @@ try {
for($i=0; $i<4; $i++) {
$attribute = new Thelia\Model\Attribute();
$attribute->setPosition($i);
$attribute->setTitle($faker->text(20));
$attribute->setDescription($faker->text(50));
setI18n($faker, $attribute);
$attribute->save();
$attributeId = $attribute->getId();
@@ -147,8 +176,7 @@ try {
$attributeAv = new Thelia\Model\AttributeAv();
$attributeAv->setAttribute($attribute);
$attributeAv->setPosition($j);
$attributeAv->setTitle($faker->text(20));
$attributeAv->setDescription($faker->text(255));
setI18n($faker, $attributeAv);
$attributeAv->save();
$attributeList[$attributeId][] = $attributeAv->getId();
@@ -271,8 +299,7 @@ try {
$folder->setParent(0);
$folder->setVisible(rand(1, 10)>7 ? 0 : 1);
$folder->setPosition($i);
$folder->setTitle($faker->text(20));
$folder->setDescription($faker->text(255));
setI18n($faker, $folder);
$folder->save();
@@ -285,8 +312,7 @@ try {
$subfolder->setParent($folder->getId());
$subfolder->setVisible(rand(1, 10)>7 ? 0 : 1);
$subfolder->setPosition($j);
$subfolder->setTitle($faker->text(20));
$subfolder->setDescription($faker->text(255));
setI18n($faker, $subfolder);
$subfolder->save();
@@ -299,8 +325,7 @@ try {
$content->addFolder($subfolder);
$content->setVisible(rand(1, 10)>7 ? 0 : 1);
$content->setPosition($k);
$content->setTitle($faker->text(20));
$content->setDescription($faker->text(255));
setI18n($faker, $content);
$content->save();
@@ -324,8 +349,7 @@ function createProduct($faker, $category, $position, &$productIdList)
$product->addCategory($category);
$product->setVisible(rand(1, 10)>7 ? 0 : 1);
$product->setPosition($position);
$product->setTitle($faker->text(20));
$product->setDescription($faker->text(255));
setI18n($faker, $product);
$product->save();
$productId = $product->getId();
@@ -344,8 +368,7 @@ function createCategory($faker, $parent, $position, &$categoryIdList)
$category->setParent($parent);
$category->setVisible(rand(1, 10)>7 ? 0 : 1);
$category->setPosition($position);
$category->setTitle($faker->text(20));
$category->setDescription($faker->text(255));
setI18n($faker, $category);
$category->save();
$cateogoryId = $category->getId();
@@ -407,3 +430,18 @@ function generate_image($image, $position, $typeobj, $id) {
$image->save($image_file);
}
function setI18n($faker, &$object)
{
$localeList = array('fr_FR', 'en_EN');
$title = $faker->text(20);
$description = $faker->text(50);
foreach($localeList as $locale) {
$object->setLocale($locale);
$object->setTitle($locale . ' : ' . $title);
$object->setDescription($locale . ' : ' . $description);
}
}