From e98b733fc8519201282e495eb2d1e6dff3e31561 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Tue, 22 Jul 2014 17:00:51 +0200 Subject: [PATCH] =?UTF-8?q?Refactor=20i18n=20export=20methods=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/ImportExport/?= =?UTF-8?q?Export/ExportHandler.php=20=09modifi=C3=A9:=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20core/lib/Thelia/ImportExport/Export/Type/MailingExport?= =?UTF-8?q?.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thel?= =?UTF-8?q?ia/ImportExport/Export/Type/ProductPricesExport.php=20=09nouvea?= =?UTF-8?q?u=20fichier:=20core/lib/Thelia/ImportExport/Export/Type/Product?= =?UTF-8?q?SEOExport.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ImportExport/Export/ExportHandler.php | 54 +++++++++++++++ .../Export/Type/MailingExport.php | 1 - .../Export/Type/ProductPricesExport.php | 66 ++++++------------- .../Export/Type/ProductSEOExport.php | 59 +++++++++++++++++ 4 files changed, 132 insertions(+), 48 deletions(-) create mode 100644 core/lib/Thelia/ImportExport/Export/Type/ProductSEOExport.php diff --git a/core/lib/Thelia/ImportExport/Export/ExportHandler.php b/core/lib/Thelia/ImportExport/Export/ExportHandler.php index c9782667e..43cf64fd3 100644 --- a/core/lib/Thelia/ImportExport/Export/ExportHandler.php +++ b/core/lib/Thelia/ImportExport/Export/ExportHandler.php @@ -11,6 +11,7 @@ /*************************************************************************************/ namespace Thelia\ImportExport\Export; +use Propel\Runtime\ActiveQuery\ModelCriteria; use Thelia\Model\Lang; use Thelia\ImportExport\AbstractHandler; @@ -21,6 +22,59 @@ use Thelia\ImportExport\AbstractHandler; */ abstract class ExportHandler extends AbstractHandler { + public function addI18nCondition( + ModelCriteria $query, + $i18nTableName, + $tableIdColumn, + $i18nIdColumn, + $localeColumn, + $locale + ) { + + $locale = $this->real_escape($locale); + $defaultLocale = $this->real_escape(Lang::getDefaultLanguage()->getLocale()); + + $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) + { + $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; + } + /** * @param \Thelia\Model\Lang $lang * @return \Thelia\Core\FileFormat\Formatting\FormatterData diff --git a/core/lib/Thelia/ImportExport/Export/Type/MailingExport.php b/core/lib/Thelia/ImportExport/Export/Type/MailingExport.php index 97b8dc9ef..25531183f 100644 --- a/core/lib/Thelia/ImportExport/Export/Type/MailingExport.php +++ b/core/lib/Thelia/ImportExport/Export/Type/MailingExport.php @@ -13,7 +13,6 @@ namespace Thelia\ImportExport\Export\Type; use Thelia\Core\FileFormat\Formatting\FormatterData; use Thelia\Core\FileFormat\FormatType; -use Thelia\Core\Translation\Translator; use Thelia\ImportExport\Export\ExportHandler; use Thelia\Model\CustomerQuery; use Thelia\Model\Lang; diff --git a/core/lib/Thelia/ImportExport/Export/Type/ProductPricesExport.php b/core/lib/Thelia/ImportExport/Export/Type/ProductPricesExport.php index 6c3d91cd9..b4dad51d6 100644 --- a/core/lib/Thelia/ImportExport/Export/Type/ProductPricesExport.php +++ b/core/lib/Thelia/ImportExport/Export/Type/ProductPricesExport.php @@ -74,8 +74,7 @@ class ProductPricesExport extends ExportHandler "product_sale_elements_PROMO" => "promo", ]; - $locale = $this->real_escape($lang->getLocale()); - $defaultLocale = $this->real_escape(Lang::getDefaultLanguage()->getLocale()); + $locale = $lang->getLocale(); $query = AttributeCombinationQuery::create() ->useProductSaleElementsQuery() @@ -113,57 +112,30 @@ class ProductPricesExport extends ExportHandler "product_TITLE", "attribute_av_i18n_ATTRIBUTES", ]) - ->where( - "CASE WHEN ".ProductTableMap::ID." IN". - "(SELECT DISTINCT ".ProductI18nTableMap::ID." ". - "FROM `".ProductI18nTableMap::TABLE_NAME."` ". - "WHERE locale=$locale) ". - - "THEN ".ProductI18nTableMap::LOCALE." = $locale ". - "ELSE ".ProductI18nTableMap::LOCALE." = $defaultLocale ". - "END" - ) - ->_and() - ->where( - "CASE WHEN ".AttributeAvTableMap::ID." IN". - "(SELECT DISTINCT ".AttributeAvI18nTableMap::ID." ". - "FROM `".AttributeAvI18nTableMap::TABLE_NAME."` ". - "WHERE locale=$locale)". - "THEN ".AttributeAvI18nTableMap::LOCALE." = $locale ". - "ELSE ".AttributeAvI18nTableMap::LOCALE." = $defaultLocale ". - "END" - ) ->groupBy("product_sale_elements_REF") ; + $this->addI18nCondition( + $query, + ProductI18nTableMap::TABLE_NAME, + ProductTableMap::ID, + AttributeAvI18nTableMap::ID, + ProductI18nTableMap::LOCALE, + $locale + ); + + $this->addI18nCondition( + $query, + AttributeAvI18nTableMap::TABLE_NAME, + AttributeAvTableMap::ID, + AttributeAvI18nTableMap::ID, + AttributeAvI18nTableMap::LOCALE, + $locale + ); + $data = new FormatterData($aliases); return $data->loadModelCriteria($query); } - /** - * @param $str - * @return string - * - * Really escapes a string for SQL request. - */ - protected function real_escape($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; - } - } \ No newline at end of file diff --git a/core/lib/Thelia/ImportExport/Export/Type/ProductSEOExport.php b/core/lib/Thelia/ImportExport/Export/Type/ProductSEOExport.php new file mode 100644 index 000000000..93fdff6d3 --- /dev/null +++ b/core/lib/Thelia/ImportExport/Export/Type/ProductSEOExport.php @@ -0,0 +1,59 @@ + + */ +class ProductSEOExport extends ExportHandler +{ + /** + * @return string|array + * + * Define all the type of formatters that this can handle + * return a string if it handle a single type ( specific exports ), + * or an array if multiple. + * + * Thelia types are defined in \Thelia\Core\FileFormat\FormatType + * + * example: + * return array( + * FormatType::TABLE, + * FormatType::UNBOUNDED, + * ); + */ + public function getHandledTypes() + { + return array( + FormatType::TABLE, + FormatType::UNBOUNDED, + ); + } + + /** + * @param \Thelia\Model\Lang $lang + * @return \Thelia\Core\FileFormat\Formatting\FormatterData + * + * The method builds the FormatterData for the formatter + */ + public function buildFormatterData(Lang $lang) + { + + } + +} \ No newline at end of file