Factorized ModelCriterialTools calls in loops
This commit is contained in:
@@ -28,6 +28,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -234,6 +235,28 @@ abstract class BaseLoop
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup ModelCriteria for proper i18n processing
|
||||
*
|
||||
* @param ModelCriteria $search the Propel Criteria to configure
|
||||
* @param array $columns the i18n columns
|
||||
* @param string $foreignTable the specified table (default to criteria table)
|
||||
* @param string $foreignKey the foreign key in this table (default to criteria table)
|
||||
*/
|
||||
protected function configureI18nProcessing(ModelCriteria $search, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID') {
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n(
|
||||
$this->getBackend_context(),
|
||||
$this->getLang(),
|
||||
$search,
|
||||
$this->request->getSession()->getLocale(),
|
||||
$columns,
|
||||
$foreignTable,
|
||||
$foreignKey
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* this function have to be implement in your own loop class.
|
||||
|
||||
@@ -34,7 +34,6 @@ use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\Base\LangQuery;
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
|
||||
use Thelia\Model\Base\CategoryQuery;
|
||||
use Thelia\Model\Base\ProductCategoryQuery;
|
||||
@@ -92,7 +91,7 @@ class Attribute extends BaseLoop
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
$this->configureI18nProcessing($search);
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
|
||||
@@ -33,8 +33,6 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
|
||||
use Thelia\Model\Base\AttributeAvQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Type\TypeCollection;
|
||||
@@ -79,12 +77,8 @@ class AttributeAvailability extends BaseLoop
|
||||
{
|
||||
$search = AttributeAvQuery::create();
|
||||
|
||||
$backendContext = $this->getBackend_context();
|
||||
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
$this->configureI18nProcessing($search);
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
|
||||
@@ -33,8 +33,6 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
|
||||
use Thelia\Model\Base\AttributeCombinationQuery;
|
||||
use Thelia\Model\Map\AttributeAvTableMap;
|
||||
use Thelia\Model\Map\AttributeTableMap;
|
||||
@@ -59,6 +57,7 @@ class AttributeCombination extends BaseLoop
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntTypeArgument('product_sale_elements', null, true),
|
||||
Argument::createIntTypeArgument('lang'),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
@@ -79,20 +78,16 @@ class AttributeCombination extends BaseLoop
|
||||
$search = AttributeCombinationQuery::create();
|
||||
|
||||
/* manage attribute translations */
|
||||
ModelCriteriaTools::getFrontEndI18n(
|
||||
$this->configureI18nProcessing(
|
||||
$search,
|
||||
ConfigQuery::read("default_lang_without_translation", 1),
|
||||
$this->request->getSession()->getLocale(),
|
||||
array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'),
|
||||
AttributeTableMap::TABLE_NAME,
|
||||
'ATTRIBUTE_ID'
|
||||
);
|
||||
|
||||
/* manage attributeAv translations */
|
||||
ModelCriteriaTools::getFrontEndI18n(
|
||||
$this->configureI18nProcessing(
|
||||
$search,
|
||||
ConfigQuery::read("default_lang_without_translation", 1),
|
||||
$this->request->getSession()->getLocale(),
|
||||
array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'),
|
||||
AttributeAvTableMap::TABLE_NAME,
|
||||
'ATTRIBUTE_AV_ID'
|
||||
|
||||
@@ -32,8 +32,6 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Type\TypeCollection;
|
||||
@@ -98,12 +96,8 @@ class Category extends BaseLoop
|
||||
{
|
||||
$search = CategoryQuery::create();
|
||||
|
||||
$backendContext = $this->getBackend_context();
|
||||
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
$this->configureI18nProcessing($search);
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
@@ -169,7 +163,6 @@ class Category extends BaseLoop
|
||||
$loopResult = new LoopResult();
|
||||
|
||||
foreach ($categories as $category) {
|
||||
|
||||
/*
|
||||
* no cause pagination lost :
|
||||
* if ($this->getNotEmpty() && $category->countAllProducts() == 0) continue;
|
||||
|
||||
@@ -65,7 +65,8 @@ class CategoryPath extends BaseLoop
|
||||
Argument::createIntTypeArgument('category', null, true),
|
||||
Argument::createIntTypeArgument('depth'),
|
||||
Argument::createIntTypeArgument('level'),
|
||||
Argument::createBooleanOrBothTypeArgument('visible', true, false)
|
||||
Argument::createBooleanOrBothTypeArgument('visible', true, false),
|
||||
Argument::createIntTypeArgument('lang')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -80,6 +81,9 @@ class CategoryPath extends BaseLoop
|
||||
$visible = $this->getVisible();
|
||||
|
||||
$search = CategoryQuery::create();
|
||||
|
||||
$this->configureI18nProcessing($search, array('TITLE'));
|
||||
|
||||
$search->filterById($id);
|
||||
if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible);
|
||||
|
||||
@@ -95,7 +99,7 @@ class CategoryPath extends BaseLoop
|
||||
$loopResultRow = new LoopResultRow();
|
||||
|
||||
$loopResultRow
|
||||
->set("TITLE",$category->getTitle())
|
||||
->set("TITLE",$category->getVirtualColumn('i18n_TITLE'))
|
||||
->set("URL", $category->getUrl())
|
||||
->set("ID", $category->getId())
|
||||
;
|
||||
@@ -114,8 +118,11 @@ class CategoryPath extends BaseLoop
|
||||
$ids[] = $parent;
|
||||
|
||||
$search = CategoryQuery::create();
|
||||
|
||||
$this->configureI18nProcessing($search, array('TITLE'));
|
||||
|
||||
$search->filterById($parent);
|
||||
if ($visible == true) $search->filterByVisible($visible);
|
||||
if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible);
|
||||
}
|
||||
}
|
||||
} while ($category != null && $parent > 0);
|
||||
|
||||
@@ -31,8 +31,6 @@ use Thelia\Core\Template\Element\LoopResultRow;
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Model\Map\ContentTableMap;
|
||||
use Thelia\Model\ContentFolderQuery;
|
||||
@@ -88,12 +86,8 @@ class Content extends BaseLoop
|
||||
{
|
||||
$search = ContentQuery::create();
|
||||
|
||||
$backendContext = $this->getBackend_context();
|
||||
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
$this->configureI18nProcessing($search);
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
|
||||
@@ -31,8 +31,6 @@ use Thelia\Core\Template\Element\LoopResultRow;
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
|
||||
use Thelia\Model\CountryQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
@@ -70,12 +68,8 @@ class Country extends BaseLoop
|
||||
{
|
||||
$search = CountryQuery::create();
|
||||
|
||||
$backendContext = $this->getBackend_context();
|
||||
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
$this->configureI18nProcessing($search);
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
|
||||
@@ -31,8 +31,6 @@ use Thelia\Core\Template\Element\LoopResultRow;
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
@@ -69,12 +67,8 @@ class Currency extends BaseLoop
|
||||
{
|
||||
$search = CurrencyQuery::create();
|
||||
|
||||
$backendContext = $this->getBackend_context();
|
||||
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale(), array('NAME'));
|
||||
$this->configureI18nProcessing($search, array('NAME'));
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
|
||||
@@ -31,8 +31,6 @@ use Thelia\Core\Template\Element\LoopResultRow;
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
|
||||
use Thelia\Model\Base\CategoryQuery;
|
||||
use Thelia\Model\Base\ProductCategoryQuery;
|
||||
use Thelia\Model\Base\FeatureQuery;
|
||||
@@ -84,12 +82,8 @@ class Feature extends BaseLoop
|
||||
{
|
||||
$search = FeatureQuery::create();
|
||||
|
||||
$backendContext = $this->getBackend_context();
|
||||
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
$this->configureI18nProcessing($search);
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
|
||||
@@ -31,8 +31,6 @@ use Thelia\Core\Template\Element\LoopResultRow;
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
|
||||
use Thelia\Model\Base\FeatureAvQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Type\TypeCollection;
|
||||
@@ -77,12 +75,8 @@ class FeatureAvailability extends BaseLoop
|
||||
{
|
||||
$search = FeatureAvQuery::create();
|
||||
|
||||
$backendContext = $this->getBackend_context();
|
||||
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
$this->configureI18nProcessing($search);
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
|
||||
@@ -33,8 +33,6 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
|
||||
use Thelia\Model\Base\FeatureProductQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\Map\FeatureAvTableMap;
|
||||
@@ -70,7 +68,8 @@ class FeatureValue extends BaseLoop
|
||||
new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse'))
|
||||
),
|
||||
'manual'
|
||||
)
|
||||
),
|
||||
Argument::createIntTypeArgument('lang')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -84,10 +83,8 @@ class FeatureValue extends BaseLoop
|
||||
$search = FeatureProductQuery::create();
|
||||
|
||||
/* manage featureAv translations */
|
||||
ModelCriteriaTools::getFrontEndI18n(
|
||||
$this->configureI18nProcessing(
|
||||
$search,
|
||||
ConfigQuery::read("default_lang_without_translation", 1),
|
||||
$this->request->getSession()->getLocale(),
|
||||
array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'),
|
||||
FeatureAvTableMap::TABLE_NAME,
|
||||
'FEATURE_AV_ID'
|
||||
|
||||
@@ -32,8 +32,6 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Type\TypeCollection;
|
||||
@@ -80,12 +78,8 @@ class Folder extends BaseLoop
|
||||
{
|
||||
$search = FolderQuery::create();
|
||||
|
||||
$backendContext = $this->getBackend_context();
|
||||
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
$this->configureI18nProcessing($search);
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
|
||||
@@ -207,16 +207,8 @@ class Image extends BaseLoop
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* \Criteria::INNER_JOIN in second parameter for joinWithI18n exclude query without translation.
|
||||
*
|
||||
* @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
|
||||
);
|
||||
/* manage translations */
|
||||
$this->configureI18nProcessing($search);
|
||||
|
||||
$results = $this->search($search, $pagination);
|
||||
|
||||
@@ -295,6 +287,7 @@ class Image extends BaseLoop
|
||||
),
|
||||
'manual'
|
||||
),
|
||||
Argument::createIntTypeArgument('lang'),
|
||||
|
||||
Argument::createIntTypeArgument('width'),
|
||||
Argument::createIntTypeArgument('height'),
|
||||
|
||||
@@ -33,8 +33,6 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Model\Map\FeatureProductTableMap;
|
||||
use Thelia\Model\Map\ProductPriceTableMap;
|
||||
@@ -138,12 +136,8 @@ class Product extends BaseLoop
|
||||
{
|
||||
$search = ProductQuery::create();
|
||||
|
||||
$backendContext = $this->getBackend_context();
|
||||
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
$this->configureI18nProcessing($search);
|
||||
|
||||
$attributeNonStrictMatch = $this->getAttribute_non_strict_match();
|
||||
$isPSELeftJoinList = array();
|
||||
|
||||
@@ -31,8 +31,6 @@ use Thelia\Core\Template\Element\LoopResultRow;
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
|
||||
use Thelia\Model\CustomerTitleQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
@@ -67,12 +65,8 @@ class Title extends BaseLoop
|
||||
{
|
||||
$search = CustomerTitleQuery::create();
|
||||
|
||||
$backendContext = $this->getBackend_context();
|
||||
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale(), array('SHORT', 'LONG'));
|
||||
$this->configureI18nProcessing($search, array('SHORT', 'LONG'));
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user