Refactor addI18nCondition method, place it in I18n tool
modifié: core/lib/Thelia/ImportExport/Export/ExportHandler.php modifié: core/lib/Thelia/ImportExport/Export/Type/ContentExport.php modifié: core/lib/Thelia/ImportExport/Export/Type/CustomerExport.php modifié: core/lib/Thelia/ImportExport/Export/Type/OrderExport.php modifié: core/lib/Thelia/ImportExport/Export/Type/ProductTaxedPricesExport.php modifié: core/lib/Thelia/Tools/I18n.php
This commit is contained in:
@@ -123,60 +123,6 @@ abstract class ExportHandler extends AbstractHandler
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addI18nCondition(
|
|
||||||
ModelCriteria $query,
|
|
||||||
$i18nTableName,
|
|
||||||
$tableIdColumn,
|
|
||||||
$i18nIdColumn,
|
|
||||||
$localeColumn,
|
|
||||||
$locale
|
|
||||||
) {
|
|
||||||
|
|
||||||
$locale = $this->real_escape($locale);
|
|
||||||
$defaultLocale = $this->real_escape($this->defaultLocale);
|
|
||||||
|
|
||||||
$query
|
|
||||||
->_and()
|
|
||||||
->where(
|
|
||||||
"CASE WHEN ".$tableIdColumn." IN".
|
|
||||||
"(SELECT DISTINCT ".$i18nIdColumn." ".
|
|
||||||
"FROM `".$i18nTableName."` ".
|
|
||||||
"WHERE locale=$locale) ".
|
|
||||||
|
|
||||||
"THEN ".$localeColumn." = $locale ".
|
|
||||||
"ELSE ".$localeColumn." = $defaultLocale ".
|
|
||||||
"END"
|
|
||||||
)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $str
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* Really escapes a string for SQL request.
|
|
||||||
*/
|
|
||||||
protected function real_escape($str)
|
|
||||||
{
|
|
||||||
$str = trim($str, "\"'");
|
|
||||||
|
|
||||||
$return = "CONCAT(";
|
|
||||||
$len = strlen($str);
|
|
||||||
|
|
||||||
for ($i = 0; $i < $len; ++$i) {
|
|
||||||
$return .= "CHAR(".ord($str[$i])."),";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($i > 0) {
|
|
||||||
$return = substr($return, 0, -1);
|
|
||||||
} else {
|
|
||||||
$return = "\"\"";
|
|
||||||
}
|
|
||||||
$return .= ")";
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function renderLoop($type, array $args = array())
|
public function renderLoop($type, array $args = array())
|
||||||
{
|
{
|
||||||
$loopsDefinition = $this->container->getParameter("thelia.parser.loops");
|
$loopsDefinition = $this->container->getParameter("thelia.parser.loops");
|
||||||
|
|||||||
@@ -72,10 +72,9 @@ class ContentExport extends ExportHandler implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Lang $lang
|
* @return ContentQuery
|
||||||
* @return ModelCriteria|array|BaseLoop
|
|
||||||
*/
|
*/
|
||||||
public function buildDataSet(Lang $lang)
|
public function getQuery(Lang $lang)
|
||||||
{
|
{
|
||||||
$locale = $lang->getLocale();
|
$locale = $lang->getLocale();
|
||||||
|
|
||||||
@@ -162,6 +161,17 @@ class ContentExport extends ExportHandler implements
|
|||||||
->groupBy("folder_ID")
|
->groupBy("folder_ID")
|
||||||
;
|
;
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Lang $lang
|
||||||
|
* @return ModelCriteria|array|BaseLoop
|
||||||
|
*/
|
||||||
|
public function buildDataSet(Lang $lang)
|
||||||
|
{
|
||||||
|
$query = $this->getQuery($lang);
|
||||||
|
|
||||||
$dataSet = $query
|
$dataSet = $query
|
||||||
->find()
|
->find()
|
||||||
->toArray()
|
->toArray()
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ use Thelia\Model\Map\CustomerTableMap;
|
|||||||
use Thelia\Model\Map\CustomerTitleI18nTableMap;
|
use Thelia\Model\Map\CustomerTitleI18nTableMap;
|
||||||
use Thelia\Model\Map\NewsletterTableMap;
|
use Thelia\Model\Map\NewsletterTableMap;
|
||||||
use Thelia\Model\OrderQuery;
|
use Thelia\Model\OrderQuery;
|
||||||
|
use Thelia\Tools\I18n;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CustomerExport
|
* Class CustomerExport
|
||||||
@@ -132,7 +133,7 @@ class CustomerExport extends ExportHandler
|
|||||||
->orderById()
|
->orderById()
|
||||||
;
|
;
|
||||||
|
|
||||||
$this->addI18nCondition(
|
I18n::addI18nCondition(
|
||||||
$query,
|
$query,
|
||||||
CountryI18nTableMap::TABLE_NAME,
|
CountryI18nTableMap::TABLE_NAME,
|
||||||
CountryTableMap::ID,
|
CountryTableMap::ID,
|
||||||
@@ -141,7 +142,7 @@ class CustomerExport extends ExportHandler
|
|||||||
$locale
|
$locale
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->addI18nCondition(
|
I18n::addI18nCondition(
|
||||||
$query,
|
$query,
|
||||||
CustomerTitleI18nTableMap::TABLE_NAME,
|
CustomerTitleI18nTableMap::TABLE_NAME,
|
||||||
"`customer_title_`.ID",
|
"`customer_title_`.ID",
|
||||||
@@ -150,7 +151,7 @@ class CustomerExport extends ExportHandler
|
|||||||
$locale
|
$locale
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->addI18nCondition(
|
I18n::addI18nCondition(
|
||||||
$query,
|
$query,
|
||||||
CustomerTitleI18nTableMap::TABLE_NAME,
|
CustomerTitleI18nTableMap::TABLE_NAME,
|
||||||
"`address_title`.ID",
|
"`address_title`.ID",
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ use Thelia\Model\Map\OrderStatusI18nTableMap;
|
|||||||
use Thelia\Model\Map\OrderStatusTableMap;
|
use Thelia\Model\Map\OrderStatusTableMap;
|
||||||
use Thelia\Model\Map\OrderTableMap;
|
use Thelia\Model\Map\OrderTableMap;
|
||||||
use Thelia\Model\OrderQuery;
|
use Thelia\Model\OrderQuery;
|
||||||
|
use Thelia\Tools\I18n;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class OrderExport
|
* Class OrderExport
|
||||||
@@ -199,7 +200,7 @@ class OrderExport extends ExportHandler
|
|||||||
])
|
])
|
||||||
;
|
;
|
||||||
|
|
||||||
$this->addI18nCondition(
|
I18n::addI18nCondition(
|
||||||
$query,
|
$query,
|
||||||
CustomerTitleI18nTableMap::TABLE_NAME,
|
CustomerTitleI18nTableMap::TABLE_NAME,
|
||||||
"`delivery_address_customer_title_join`.ID",
|
"`delivery_address_customer_title_join`.ID",
|
||||||
@@ -208,7 +209,7 @@ class OrderExport extends ExportHandler
|
|||||||
$locale
|
$locale
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->addI18nCondition(
|
I18n::addI18nCondition(
|
||||||
$query,
|
$query,
|
||||||
CustomerTitleI18nTableMap::TABLE_NAME,
|
CustomerTitleI18nTableMap::TABLE_NAME,
|
||||||
"`invoice_address_customer_title_join`.ID",
|
"`invoice_address_customer_title_join`.ID",
|
||||||
@@ -217,7 +218,7 @@ class OrderExport extends ExportHandler
|
|||||||
$locale
|
$locale
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->addI18nCondition(
|
I18n::addI18nCondition(
|
||||||
$query,
|
$query,
|
||||||
CountryI18nTableMap::TABLE_NAME,
|
CountryI18nTableMap::TABLE_NAME,
|
||||||
"`delivery_address_country_join`.ID",
|
"`delivery_address_country_join`.ID",
|
||||||
@@ -226,7 +227,7 @@ class OrderExport extends ExportHandler
|
|||||||
$locale
|
$locale
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->addI18nCondition(
|
I18n::addI18nCondition(
|
||||||
$query,
|
$query,
|
||||||
CountryI18nTableMap::TABLE_NAME,
|
CountryI18nTableMap::TABLE_NAME,
|
||||||
"`invoice_address_country_join`.ID",
|
"`invoice_address_country_join`.ID",
|
||||||
@@ -235,7 +236,7 @@ class OrderExport extends ExportHandler
|
|||||||
$locale
|
$locale
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->addI18nCondition(
|
I18n::addI18nCondition(
|
||||||
$query,
|
$query,
|
||||||
OrderStatusI18nTableMap::TABLE_NAME,
|
OrderStatusI18nTableMap::TABLE_NAME,
|
||||||
OrderStatusI18nTableMap::ID,
|
OrderStatusI18nTableMap::ID,
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use Thelia\Model\Map\ProductTableMap;
|
|||||||
use Thelia\Model\Map\TaxRuleI18nTableMap;
|
use Thelia\Model\Map\TaxRuleI18nTableMap;
|
||||||
use Thelia\Model\Map\TaxRuleTableMap;
|
use Thelia\Model\Map\TaxRuleTableMap;
|
||||||
use Thelia\Model\ProductSaleElementsQuery;
|
use Thelia\Model\ProductSaleElementsQuery;
|
||||||
|
use Thelia\Tools\I18n;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ProductTaxedPricesExport
|
* Class ProductTaxedPricesExport
|
||||||
@@ -58,7 +59,7 @@ class ProductTaxedPricesExport extends ProductPricesExport
|
|||||||
])
|
])
|
||||||
;
|
;
|
||||||
|
|
||||||
$this->addI18nCondition(
|
I18n::addI18nCondition(
|
||||||
$query,
|
$query,
|
||||||
TaxRuleI18nTableMap::TABLE_NAME,
|
TaxRuleI18nTableMap::TABLE_NAME,
|
||||||
TaxRuleTableMap::ID,
|
TaxRuleTableMap::ID,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
namespace Thelia\Tools;
|
namespace Thelia\Tools;
|
||||||
|
|
||||||
|
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
||||||
use Thelia\Model\Lang;
|
use Thelia\Model\Lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,6 +28,8 @@ use Thelia\Model\Lang;
|
|||||||
*/
|
*/
|
||||||
class I18n
|
class I18n
|
||||||
{
|
{
|
||||||
|
protected static $defaultLocale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a \DateTime from a date picker form input
|
* Create a \DateTime from a date picker form input
|
||||||
* The date format is the same as the one from the current User Session
|
* The date format is the same as the one from the current User Session
|
||||||
@@ -78,4 +81,61 @@ class I18n
|
|||||||
|
|
||||||
return $i18n;
|
return $i18n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function addI18nCondition(
|
||||||
|
ModelCriteria $query,
|
||||||
|
$i18nTableName,
|
||||||
|
$tableIdColumn,
|
||||||
|
$i18nIdColumn,
|
||||||
|
$localeColumn,
|
||||||
|
$locale
|
||||||
|
) {
|
||||||
|
if (null === static::$defaultLocale) {
|
||||||
|
static::$defaultLocale = Lang::getDefaultLanguage()->getLocale();
|
||||||
|
}
|
||||||
|
|
||||||
|
$locale = static::real_escape($locale);
|
||||||
|
$defaultLocale = static::real_escape(static::$defaultLocale);
|
||||||
|
|
||||||
|
$query
|
||||||
|
->_and()
|
||||||
|
->where(
|
||||||
|
"CASE WHEN ".$tableIdColumn." IN".
|
||||||
|
"(SELECT DISTINCT ".$i18nIdColumn." ".
|
||||||
|
"FROM `".$i18nTableName."` ".
|
||||||
|
"WHERE locale=$locale) ".
|
||||||
|
|
||||||
|
"THEN ".$localeColumn." = $locale ".
|
||||||
|
"ELSE ".$localeColumn." = $defaultLocale ".
|
||||||
|
"END"
|
||||||
|
)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $str
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* Really escapes a string for SQL query.
|
||||||
|
*/
|
||||||
|
public static function real_escape($str)
|
||||||
|
{
|
||||||
|
$str = trim($str, "\"'");
|
||||||
|
|
||||||
|
$return = "CONCAT(";
|
||||||
|
$len = strlen($str);
|
||||||
|
|
||||||
|
for ($i = 0; $i < $len; ++$i) {
|
||||||
|
$return .= "CHAR(".ord($str[$i])."),";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($i > 0) {
|
||||||
|
$return = substr($return, 0, -1);
|
||||||
|
} else {
|
||||||
|
$return = "\"\"";
|
||||||
|
}
|
||||||
|
$return .= ")";
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user