Merge branch 'master' into rewrite

Conflicts:
	core/lib/Thelia/Core/Template/Loop/Attribute.php
	core/lib/Thelia/Core/Template/Loop/AttributeAvailability.php
	core/lib/Thelia/Core/Template/Loop/AttributeCombination.php
	core/lib/Thelia/Core/Template/Loop/Category.php
	core/lib/Thelia/Core/Template/Loop/Content.php
	core/lib/Thelia/Core/Template/Loop/Country.php
	core/lib/Thelia/Core/Template/Loop/Currency.php
	core/lib/Thelia/Core/Template/Loop/Feature.php
	core/lib/Thelia/Core/Template/Loop/FeatureAvailability.php
	core/lib/Thelia/Core/Template/Loop/FeatureValue.php
	core/lib/Thelia/Core/Template/Loop/Folder.php
	core/lib/Thelia/Core/Template/Loop/Image.php
	core/lib/Thelia/Core/Template/Loop/Product.php
	core/lib/Thelia/Core/Template/Loop/Title.php
	core/lib/Thelia/Model/Tools/ModelCriteriaTools.php
This commit is contained in:
Etienne Roudeix
2013-08-30 15:02:48 +02:00
49 changed files with 780 additions and 802 deletions

View File

@@ -4,10 +4,10 @@ namespace Thelia\Model;
use Propel\Runtime\Connection\ConnectionInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Thelia\Core\Event\Internal\CartEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\Base\CartItem as BaseCartItem;
use Thelia\Model\ConfigQuery;
use Thelia\Core\Event\CartEvent;
class CartItem extends BaseCartItem
{

View File

@@ -50,7 +50,7 @@ class Category extends BaseCategory
->findOne()
;
return $last->getPosition() + 1;
return $last != null ? $last->getPosition() + 1 : 1;
}
/**
@@ -76,6 +76,4 @@ class Category extends BaseCategory
return $countProduct;
}
}

View File

@@ -3,7 +3,6 @@
namespace Thelia\Model;
use Symfony\Component\Config\Definition\Exception\Exception;
use Thelia\Core\Event\Internal\CustomerEvent;
use Thelia\Model\Base\Customer as BaseCustomer;
use Thelia\Model\Exception\InvalidArgumentException;
@@ -17,6 +16,7 @@ use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Propel;
use Thelia\Model\Map\CustomerTableMap;
use Thelia\Core\Security\Role\Role;
use Thelia\Core\Event\CustomerEvent;
/**
* Skeleton subclass for representing a row from the 'customer' table.

View File

@@ -6,6 +6,7 @@ use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Thelia\Model\Base\LangQuery;
use Thelia\Model\ConfigQuery;
/**
* Class ModelCriteriaTools
@@ -17,13 +18,12 @@ class ModelCriteriaTools
{
/**
* @param ModelCriteria $search
* @param $defaultLangWithoutTranslation
* @param $askedLocale
* @param $requestedLocale
* @param array $columns
* @param null $foreignTable
* @param string $foreignKey
*/
public static function getFrontEndI18n(ModelCriteria &$search, $defaultLangWithoutTranslation, $askedLocale, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID', $forceReturn = false)
public static function getFrontEndI18n(ModelCriteria &$search, $requestedLocale, $columns, $foreignTable, $foreignKey, $forceReturn = false)
{
if($foreignTable === null) {
$foreignTable = $search->getTableMap()->getName();
@@ -32,21 +32,24 @@ class ModelCriteriaTools
$aliasPrefix = $foreignTable . '_';
}
$askedLocaleI18nAlias = $aliasPrefix . 'asked_locale_i18n';
$defaultLangWithoutTranslation = ConfigQuery::getDefaultLangWhenNoTranslationAvailable();
$requestedLocaleI18nAlias = $aliasPrefix . 'requested_locale_i18n';
$defaultLocaleI18nAlias = $aliasPrefix . 'default_locale_i18n';
if($defaultLangWithoutTranslation == 0) {
$askedLocaleJoin = new Join();
$askedLocaleJoin->addExplicitCondition($search->getTableMap()->getName(), $foreignKey, null, $foreignTable . '_i18n', 'ID', $askedLocaleI18nAlias);
$askedLocaleJoin->setJoinType($forceReturn === false ? Criteria::INNER_JOIN : Criteria::LEFT_JOIN);
$requestedLocaleJoin = new Join();
$requestedLocaleJoin->addExplicitCondition($search->getTableMap()->getName(), $foreignKey, null, $foreignTable . '_i18n', 'ID', $requestedLocaleI18nAlias);
$requestedLocaleJoin->setJoinType($forceReturn === false ? Criteria::INNER_JOIN : Criteria::LEFT_JOIN);
$search->addJoinObject($askedLocaleJoin, $askedLocaleI18nAlias)
->addJoinCondition($askedLocaleI18nAlias ,'`' . $askedLocaleI18nAlias . '`.LOCALE = ?', $askedLocale, null, \PDO::PARAM_STR);
$search->addJoinObject($requestedLocaleJoin, $requestedLocaleI18nAlias)
->addJoinCondition($requestedLocaleI18nAlias ,'`' . $requestedLocaleI18nAlias . '`.LOCALE = ?', $requestedLocale, null, \PDO::PARAM_STR);
$search->withColumn('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'IS_TRANSLATED');
$search->withColumn('NOT ISNULL(`' . $requestedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'IS_TRANSLATED');
foreach($columns as $column) {
$search->withColumn('`' . $askedLocaleI18nAlias . '`.`' . $column . '`', $aliasPrefix . 'i18n_' . $column);
$search->withColumn('`' . $requestedLocaleI18nAlias . '`.`' . $column . '`', $aliasPrefix . 'i18n_' . $column);
}
} else {
$defaultLocale = LangQuery::create()->findOneById($defaultLangWithoutTranslation)->getLocale();
@@ -58,26 +61,26 @@ class ModelCriteriaTools
$search->addJoinObject($defaultLocaleJoin, $defaultLocaleI18nAlias)
->addJoinCondition($defaultLocaleI18nAlias ,'`' . $defaultLocaleI18nAlias . '`.LOCALE = ?', $defaultLocale, null, \PDO::PARAM_STR);
$askedLocaleJoin = new Join();
$askedLocaleJoin->addExplicitCondition($search->getTableMap()->getName(), $foreignKey, null, $foreignTable . '_i18n', 'ID', $askedLocaleI18nAlias);
$askedLocaleJoin->setJoinType(Criteria::LEFT_JOIN);
$requestedLocaleJoin = new Join();
$requestedLocaleJoin->addExplicitCondition($search->getTableMap()->getName(), $foreignKey, null, $foreignTable . '_i18n', 'ID', $requestedLocaleI18nAlias);
$requestedLocaleJoin->setJoinType(Criteria::LEFT_JOIN);
$search->addJoinObject($askedLocaleJoin, $askedLocaleI18nAlias)
->addJoinCondition($askedLocaleI18nAlias ,'`' . $askedLocaleI18nAlias . '`.LOCALE = ?', $askedLocale, null, \PDO::PARAM_STR);
$search->addJoinObject($requestedLocaleJoin, $requestedLocaleI18nAlias)
->addJoinCondition($requestedLocaleI18nAlias ,'`' . $requestedLocaleI18nAlias . '`.LOCALE = ?', $requestedLocale, null, \PDO::PARAM_STR);
$search->withColumn('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'IS_TRANSLATED');
$search->withColumn('NOT ISNULL(`' . $requestedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'IS_TRANSLATED');
if(!$forceReturn) {
$search->where('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.ID)')->_or()->where('NOT ISNULL(`' . $defaultLocaleI18nAlias . '`.ID)');
if($forceReturn === false) {
$search->where('NOT ISNULL(`' . $requestedLocaleI18nAlias . '`.ID)')->_or()->where('NOT ISNULL(`' . $defaultLocaleI18nAlias . '`.ID)');
}
foreach($columns as $column) {
$search->withColumn('CASE WHEN NOT ISNULL(`' . $askedLocaleI18nAlias . '`.ID) THEN `' . $askedLocaleI18nAlias . '`.`' . $column . '` ELSE `' . $defaultLocaleI18nAlias . '`.`' . $column . '` END', $aliasPrefix . 'i18n_' . $column);
$search->withColumn('CASE WHEN NOT ISNULL(`' . $requestedLocaleI18nAlias . '`.ID) THEN `' . $requestedLocaleI18nAlias . '`.`' . $column . '` ELSE `' . $defaultLocaleI18nAlias . '`.`' . $column . '` END', $aliasPrefix . 'i18n_' . $column);
}
}
}
public static function getBackEndI18n(ModelCriteria &$search, $askedLocale, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID')
public static function getBackEndI18n(ModelCriteria &$search, $requestedLocale, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID')
{
if($foreignTable === null) {
$foreignTable = $search->getTableMap()->getName();
@@ -86,39 +89,46 @@ class ModelCriteriaTools
$aliasPrefix = $foreignTable . '_';
}
$askedLocaleI18nAlias = $aliasPrefix . 'asked_locale_i18n';
$requestedLocaleI18nAlias = 'requested_locale_i18n';
$askedLocaleJoin = new Join();
$askedLocaleJoin->addExplicitCondition($search->getTableMap()->getName(), $foreignKey, null, $foreignTable . '_i18n', 'ID', $askedLocaleI18nAlias);
$askedLocaleJoin->setJoinType(Criteria::LEFT_JOIN);
$requestedLocaleJoin = new Join();
$requestedLocaleJoin->addExplicitCondition($search->getTableMap()->getName(), $foreignKey, null, $foreignTable . '_i18n', 'ID', $requestedLocaleI18nAlias);
$requestedLocaleJoin->setJoinType(Criteria::LEFT_JOIN);
$search->addJoinObject($askedLocaleJoin, $askedLocaleI18nAlias)
->addJoinCondition($askedLocaleI18nAlias ,'`' . $askedLocaleI18nAlias . '`.LOCALE = ?', $askedLocale, null, \PDO::PARAM_STR);
$search->addJoinObject($requestedLocaleJoin, $requestedLocaleI18nAlias)
->addJoinCondition($requestedLocaleI18nAlias ,'`' . $requestedLocaleI18nAlias . '`.LOCALE = ?', $requestedLocale, null, \PDO::PARAM_STR);
$search->withColumn('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'IS_TRANSLATED');
$search->withColumn('NOT ISNULL(`' . $requestedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'IS_TRANSLATED');
foreach($columns as $column) {
$search->withColumn('`' . $askedLocaleI18nAlias . '`.`' . $column . '`', $aliasPrefix . 'i18n_' . $column);
$search->withColumn('`' . $requestedLocaleI18nAlias . '`.`' . $column . '`', $aliasPrefix . 'i18n_' . $column);
}
}
public static function getI18n($backendContext, $lang, ModelCriteria &$search, $defaultLangWithoutTranslation, $currentLocale, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID')
public static function getI18n($backendContext, $requestedLangId, ModelCriteria &$search, $currentLocale, $columns, $foreignTable, $foreignKey, $forceReturn = false)
{
if($lang !== null) {
$localeSearch = LangQuery::create()->findOneById($lang);
if($localeSearch === null) {
throw new \InvalidArgumentException('Incorrect lang argument given in attribute loop');
// If a lang has been requested, find the related Lang object, and get the locale
if ($requestedLangId !== null) {
$localeSearch = LangQuery::create()->findOneById($requestedLangId);
if ($localeSearch === null) {
throw new \InvalidArgumentException(sprintf('Incorrect lang argument given in attribute loop: lang ID %d not found', $requestedLangId));
}
$locale = $localeSearch->getLocale();
}
else {
// Use the currently defined locale
$locale = $currentLocale;
}
$askedLocale = $lang === null ? $currentLocale : $localeSearch->getLocale();
if($backendContext) {
self::getBackEndI18n($search, $askedLocale, $columns, $foreignTable, $foreignKey);
// Call the proper method depending on the context: front or back
if ($backendContext) {
self::getBackEndI18n($search, $locale, $columns, $foreignTable, $foreignKey);
} else {
self::getFrontEndI18n($search, $defaultLangWithoutTranslation, $askedLocale, $columns, $foreignTable, $foreignKey);
self::getFrontEndI18n($search, $locale, $columns, $foreignTable, $foreignKey, $forceReturn);
}
return $askedLocale;
return $locale;
}
}