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. * @todo : verify here if we want results for row without translations.
*/ */
$search->joinWithI18n( if(ConfigQuery::read("default_lang_without_translation", 1) == 0) {
$this->request->getSession()->getLocale(), /*
(ConfigQuery::read("default_lang_without_translation", 1)) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN * 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); $categories = $this->search($search, $pagination);
@@ -171,15 +193,16 @@ class Category extends BaseLoop
if ($this->getNotEmpty() && $category->countAllProducts() == 0) continue; if ($this->getNotEmpty() && $category->countAllProducts() == 0) continue;
$x = $category->getTitle();
$loopResultRow = new LoopResultRow(); $loopResultRow = new LoopResultRow();
$loopResultRow $loopResultRow
->set("ID", $category->getId()) ->set("ID", $category->getId())
->set("TITLE",$category->getTitle()) ->set("TITLE",$category->getVirtualColumn('i18n_TITLE'))
->set("CHAPO", $category->getChapo()) ->set("CHAPO", $category->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $category->getDescription()) ->set("DESCRIPTION", $category->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM", $category->getPostscriptum()) ->set("POSTSCRIPTUM", $category->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("PARENT", $category->getParent()) ->set("PARENT", $category->getParent())
->set("URL", $category->getUrl()) ->set("URL", $category->getUrl())
->set("PRODUCT_COUNT", $category->countChild()) ->set("PRODUCT_COUNT", $category->countChild())

View File

@@ -35,6 +35,7 @@ use Thelia\Log\Tlog;
use Thelia\Model\Base\FeatureProductQuery; use Thelia\Model\Base\FeatureProductQuery;
use Thelia\Model\ConfigQuery; use Thelia\Model\ConfigQuery;
use Thelia\Model\FeatureAvQuery;
use Thelia\Type\TypeCollection; use Thelia\Type\TypeCollection;
use Thelia\Type; use Thelia\Type;
@@ -132,7 +133,12 @@ class FeatureValue extends BaseLoop
$loopResultRow->set("PERSONAL_VALUE", $featureValue->getByDefault()); $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("TITLE", ($featureAvailability === null ? '' : $featureAvailability->getTitle()));
$loopResultRow->set("CHAPO", ($featureAvailability === null ? '' : $featureAvailability->getChapo())); $loopResultRow->set("CHAPO", ($featureAvailability === null ? '' : $featureAvailability->getChapo()));

View File

@@ -41,56 +41,70 @@ try {
->find(); ->find();
$feature->delete(); $feature->delete();
$feature = Thelia\Model\FeatureI18nQuery::create()
->find();
$feature->delete();
$featureAv = Thelia\Model\FeatureAvQuery::create() $featureAv = Thelia\Model\FeatureAvQuery::create()
->find(); ->find();
$featureAv->delete(); $featureAv->delete();
$featureAv = Thelia\Model\FeatureAvI18nQuery::create()
->find();
$featureAv->delete();
$attribute = Thelia\Model\AttributeQuery::create() $attribute = Thelia\Model\AttributeQuery::create()
->find(); ->find();
$attribute->delete(); $attribute->delete();
$attribute = Thelia\Model\AttributeI18nQuery::create()
->find();
$attribute->delete();
$attributeAv = Thelia\Model\AttributeAvQuery::create() $attributeAv = Thelia\Model\AttributeAvQuery::create()
->find(); ->find();
$attributeAv->delete(); $attributeAv->delete();
$attributeAv = Thelia\Model\AttributeAvI18nQuery::create()
->find();
$attributeAv->delete();
$category = Thelia\Model\CategoryQuery::create() $category = Thelia\Model\CategoryQuery::create()
->find(); ->find();
$category->delete(); $category->delete();
$category = Thelia\Model\CategoryI18nQuery::create()
->find();
$category->delete();
$product = Thelia\Model\ProductQuery::create() $product = Thelia\Model\ProductQuery::create()
->find(); ->find();
$product->delete(); $product->delete();
$product = Thelia\Model\ProductI18nQuery::create()
->find();
$product->delete();
$customer = Thelia\Model\CustomerQuery::create() $customer = Thelia\Model\CustomerQuery::create()
->find(); ->find();
$customer->delete(); $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() $folder = Thelia\Model\FolderQuery::create()
->find(); ->find();
$folder->delete(); $folder->delete();
$folder = Thelia\Model\FolderI18nQuery::create()
->find();
$folder->delete();
$content = Thelia\Model\ContentQuery::create() $content = Thelia\Model\ContentQuery::create()
->find(); ->find();
$content->delete(); $content->delete();
$content = Thelia\Model\ContentI18nQuery::create()
->find();
$content->delete();
$accessory = Thelia\Model\AccessoryQuery::create() $accessory = Thelia\Model\AccessoryQuery::create()
->find(); ->find();
$accessory->delete(); $accessory->delete();
@@ -106,14 +120,31 @@ try {
$stmt = $con->prepare("SET foreign_key_checks = 1"); $stmt = $con->prepare("SET foreign_key_checks = 1");
$stmt->execute(); $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 //features and features_av
$featureList = array(); $featureList = array();
for($i=0; $i<4; $i++) { for($i=0; $i<4; $i++) {
$feature = new Thelia\Model\Feature(); $feature = new Thelia\Model\Feature();
$feature->setVisible(rand(1, 10)>7 ? 0 : 1); $feature->setVisible(rand(1, 10)>7 ? 0 : 1);
$feature->setPosition($i); $feature->setPosition($i);
$feature->setTitle($faker->text(20)); setI18n($faker, $feature);
$feature->setDescription($faker->text(50));
$feature->save(); $feature->save();
$featureId = $feature->getId(); $featureId = $feature->getId();
@@ -123,8 +154,7 @@ try {
$featureAv = new Thelia\Model\FeatureAv(); $featureAv = new Thelia\Model\FeatureAv();
$featureAv->setFeature($feature); $featureAv->setFeature($feature);
$featureAv->setPosition($j); $featureAv->setPosition($j);
$featureAv->setTitle($faker->text(20)); setI18n($faker, $featureAv);
$featureAv->setDescription($faker->text(255));
$featureAv->save(); $featureAv->save();
$featureList[$featureId][] = $featureAv->getId(); $featureList[$featureId][] = $featureAv->getId();
@@ -136,8 +166,7 @@ try {
for($i=0; $i<4; $i++) { for($i=0; $i<4; $i++) {
$attribute = new Thelia\Model\Attribute(); $attribute = new Thelia\Model\Attribute();
$attribute->setPosition($i); $attribute->setPosition($i);
$attribute->setTitle($faker->text(20)); setI18n($faker, $attribute);
$attribute->setDescription($faker->text(50));
$attribute->save(); $attribute->save();
$attributeId = $attribute->getId(); $attributeId = $attribute->getId();
@@ -147,8 +176,7 @@ try {
$attributeAv = new Thelia\Model\AttributeAv(); $attributeAv = new Thelia\Model\AttributeAv();
$attributeAv->setAttribute($attribute); $attributeAv->setAttribute($attribute);
$attributeAv->setPosition($j); $attributeAv->setPosition($j);
$attributeAv->setTitle($faker->text(20)); setI18n($faker, $attributeAv);
$attributeAv->setDescription($faker->text(255));
$attributeAv->save(); $attributeAv->save();
$attributeList[$attributeId][] = $attributeAv->getId(); $attributeList[$attributeId][] = $attributeAv->getId();
@@ -271,8 +299,7 @@ try {
$folder->setParent(0); $folder->setParent(0);
$folder->setVisible(rand(1, 10)>7 ? 0 : 1); $folder->setVisible(rand(1, 10)>7 ? 0 : 1);
$folder->setPosition($i); $folder->setPosition($i);
$folder->setTitle($faker->text(20)); setI18n($faker, $folder);
$folder->setDescription($faker->text(255));
$folder->save(); $folder->save();
@@ -285,8 +312,7 @@ try {
$subfolder->setParent($folder->getId()); $subfolder->setParent($folder->getId());
$subfolder->setVisible(rand(1, 10)>7 ? 0 : 1); $subfolder->setVisible(rand(1, 10)>7 ? 0 : 1);
$subfolder->setPosition($j); $subfolder->setPosition($j);
$subfolder->setTitle($faker->text(20)); setI18n($faker, $subfolder);
$subfolder->setDescription($faker->text(255));
$subfolder->save(); $subfolder->save();
@@ -299,8 +325,7 @@ try {
$content->addFolder($subfolder); $content->addFolder($subfolder);
$content->setVisible(rand(1, 10)>7 ? 0 : 1); $content->setVisible(rand(1, 10)>7 ? 0 : 1);
$content->setPosition($k); $content->setPosition($k);
$content->setTitle($faker->text(20)); setI18n($faker, $content);
$content->setDescription($faker->text(255));
$content->save(); $content->save();
@@ -324,8 +349,7 @@ function createProduct($faker, $category, $position, &$productIdList)
$product->addCategory($category); $product->addCategory($category);
$product->setVisible(rand(1, 10)>7 ? 0 : 1); $product->setVisible(rand(1, 10)>7 ? 0 : 1);
$product->setPosition($position); $product->setPosition($position);
$product->setTitle($faker->text(20)); setI18n($faker, $product);
$product->setDescription($faker->text(255));
$product->save(); $product->save();
$productId = $product->getId(); $productId = $product->getId();
@@ -344,8 +368,7 @@ function createCategory($faker, $parent, $position, &$categoryIdList)
$category->setParent($parent); $category->setParent($parent);
$category->setVisible(rand(1, 10)>7 ? 0 : 1); $category->setVisible(rand(1, 10)>7 ? 0 : 1);
$category->setPosition($position); $category->setPosition($position);
$category->setTitle($faker->text(20)); setI18n($faker, $category);
$category->setDescription($faker->text(255));
$category->save(); $category->save();
$cateogoryId = $category->getId(); $cateogoryId = $category->getId();
@@ -407,3 +430,18 @@ function generate_image($image, $position, $typeobj, $id) {
$image->save($image_file); $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);
}
}