Factorized ModelCriterialTools calls in loops

This commit is contained in:
franck
2013-08-28 19:47:31 +02:00
parent 0361cd1ff2
commit cce270fdcc
24 changed files with 150 additions and 193 deletions

View File

@@ -89,7 +89,7 @@ class CategoryController extends BaseAdminController
$categoryDeletionForm = new CategoryDeletionForm($this->getRequest()); $categoryDeletionForm = new CategoryDeletionForm($this->getRequest());
$data = $this->validateForm($categoryDeletionForm, "POST")->getData(); $data = $this->validateForm($categoryDeletionForm, "POST")->getData();
var_dump($data);
$categoryDeleteEvent = new CategoryDeleteEvent($data['category_id']); $categoryDeleteEvent = new CategoryDeleteEvent($data['category_id']);
$this->dispatch(TheliaEvents::CATEGORY_DELETE, $categoryDeleteEvent); $this->dispatch(TheliaEvents::CATEGORY_DELETE, $categoryDeleteEvent);
@@ -151,8 +151,8 @@ var_dump($data);
protected function positionDown($args) protected function positionDown($args)
{ {
$event = new CategoryChangePositionEvent( $event = new CategoryChangePositionEvent(
$this->getRequest()->get('category_id', 0), $this->getRequest()->get('category_id', 0),
CategoryChangePositionEvent::POSITION_DOWN CategoryChangePositionEvent::POSITION_DOWN
); );
$this->dispatch(TheliaEvents::CATEGORY_CHANGE_POSITION, $event); $this->dispatch(TheliaEvents::CATEGORY_CHANGE_POSITION, $event);

View File

@@ -28,6 +28,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Propel\Runtime\ActiveQuery\ModelCriteria; use Propel\Runtime\ActiveQuery\ModelCriteria;
use Thelia\Core\Security\SecurityContext; 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. * this function have to be implement in your own loop class.

View File

@@ -34,7 +34,6 @@ use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog; use Thelia\Log\Tlog;
use Thelia\Model\Base\LangQuery; use Thelia\Model\Base\LangQuery;
use Thelia\Model\Tools\ModelCriteriaTools;
use Thelia\Model\Base\CategoryQuery; use Thelia\Model\Base\CategoryQuery;
use Thelia\Model\Base\ProductCategoryQuery; use Thelia\Model\Base\ProductCategoryQuery;
@@ -92,7 +91,7 @@ class Attribute extends BaseLoop
$lang = $this->getLang(); $lang = $this->getLang();
/* manage translations */ /* manage translations */
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale()); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();

View File

@@ -33,8 +33,6 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog; use Thelia\Log\Tlog;
use Thelia\Model\Tools\ModelCriteriaTools;
use Thelia\Model\Base\AttributeAvQuery; use Thelia\Model\Base\AttributeAvQuery;
use Thelia\Model\ConfigQuery; use Thelia\Model\ConfigQuery;
use Thelia\Type\TypeCollection; use Thelia\Type\TypeCollection;
@@ -79,12 +77,8 @@ class AttributeAvailability extends BaseLoop
{ {
$search = AttributeAvQuery::create(); $search = AttributeAvQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */ /* manage translations */
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale()); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();

View File

@@ -33,8 +33,6 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog; use Thelia\Log\Tlog;
use Thelia\Model\Tools\ModelCriteriaTools;
use Thelia\Model\Base\AttributeCombinationQuery; use Thelia\Model\Base\AttributeCombinationQuery;
use Thelia\Model\Map\AttributeAvTableMap; use Thelia\Model\Map\AttributeAvTableMap;
use Thelia\Model\Map\AttributeTableMap; use Thelia\Model\Map\AttributeTableMap;
@@ -59,6 +57,7 @@ class AttributeCombination extends BaseLoop
{ {
return new ArgumentCollection( return new ArgumentCollection(
Argument::createIntTypeArgument('product_sale_elements', null, true), Argument::createIntTypeArgument('product_sale_elements', null, true),
Argument::createIntTypeArgument('lang'),
new Argument( new Argument(
'order', 'order',
new TypeCollection( new TypeCollection(
@@ -79,20 +78,16 @@ class AttributeCombination extends BaseLoop
$search = AttributeCombinationQuery::create(); $search = AttributeCombinationQuery::create();
/* manage attribute translations */ /* manage attribute translations */
ModelCriteriaTools::getFrontEndI18n( $this->configureI18nProcessing(
$search, $search,
ConfigQuery::read("default_lang_without_translation", 1),
$this->request->getSession()->getLocale(),
array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'),
AttributeTableMap::TABLE_NAME, AttributeTableMap::TABLE_NAME,
'ATTRIBUTE_ID' 'ATTRIBUTE_ID'
); );
/* manage attributeAv translations */ /* manage attributeAv translations */
ModelCriteriaTools::getFrontEndI18n( $this->configureI18nProcessing(
$search, $search,
ConfigQuery::read("default_lang_without_translation", 1),
$this->request->getSession()->getLocale(),
array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'),
AttributeAvTableMap::TABLE_NAME, AttributeAvTableMap::TABLE_NAME,
'ATTRIBUTE_AV_ID' 'ATTRIBUTE_AV_ID'

View File

@@ -32,8 +32,6 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog; use Thelia\Log\Tlog;
use Thelia\Model\Tools\ModelCriteriaTools;
use Thelia\Model\CategoryQuery; use Thelia\Model\CategoryQuery;
use Thelia\Model\ConfigQuery; use Thelia\Model\ConfigQuery;
use Thelia\Type\TypeCollection; use Thelia\Type\TypeCollection;
@@ -98,12 +96,8 @@ class Category extends BaseLoop
{ {
$search = CategoryQuery::create(); $search = CategoryQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */ /* manage translations */
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale()); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();
@@ -169,7 +163,6 @@ class Category extends BaseLoop
$loopResult = new LoopResult(); $loopResult = new LoopResult();
foreach ($categories as $category) { foreach ($categories as $category) {
/* /*
* no cause pagination lost : * no cause pagination lost :
* if ($this->getNotEmpty() && $category->countAllProducts() == 0) continue; * if ($this->getNotEmpty() && $category->countAllProducts() == 0) continue;

View File

@@ -65,7 +65,8 @@ class CategoryPath extends BaseLoop
Argument::createIntTypeArgument('category', null, true), Argument::createIntTypeArgument('category', null, true),
Argument::createIntTypeArgument('depth'), Argument::createIntTypeArgument('depth'),
Argument::createIntTypeArgument('level'), 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(); $visible = $this->getVisible();
$search = CategoryQuery::create(); $search = CategoryQuery::create();
$this->configureI18nProcessing($search, array('TITLE'));
$search->filterById($id); $search->filterById($id);
if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible); if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible);
@@ -95,7 +99,7 @@ class CategoryPath extends BaseLoop
$loopResultRow = new LoopResultRow(); $loopResultRow = new LoopResultRow();
$loopResultRow $loopResultRow
->set("TITLE",$category->getTitle()) ->set("TITLE",$category->getVirtualColumn('i18n_TITLE'))
->set("URL", $category->getUrl()) ->set("URL", $category->getUrl())
->set("ID", $category->getId()) ->set("ID", $category->getId())
; ;
@@ -114,8 +118,11 @@ class CategoryPath extends BaseLoop
$ids[] = $parent; $ids[] = $parent;
$search = CategoryQuery::create(); $search = CategoryQuery::create();
$this->configureI18nProcessing($search, array('TITLE'));
$search->filterById($parent); $search->filterById($parent);
if ($visible == true) $search->filterByVisible($visible); if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible);
} }
} }
} while ($category != null && $parent > 0); } while ($category != null && $parent > 0);

View File

@@ -31,8 +31,6 @@ use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Model\Tools\ModelCriteriaTools;
use Thelia\Model\FolderQuery; use Thelia\Model\FolderQuery;
use Thelia\Model\Map\ContentTableMap; use Thelia\Model\Map\ContentTableMap;
use Thelia\Model\ContentFolderQuery; use Thelia\Model\ContentFolderQuery;
@@ -88,12 +86,8 @@ class Content extends BaseLoop
{ {
$search = ContentQuery::create(); $search = ContentQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */ /* manage translations */
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale()); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();

View File

@@ -31,8 +31,6 @@ use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Model\Tools\ModelCriteriaTools;
use Thelia\Model\CountryQuery; use Thelia\Model\CountryQuery;
use Thelia\Model\ConfigQuery; use Thelia\Model\ConfigQuery;
@@ -70,12 +68,8 @@ class Country extends BaseLoop
{ {
$search = CountryQuery::create(); $search = CountryQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */ /* manage translations */
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale()); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();

View File

@@ -31,8 +31,6 @@ use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Model\Tools\ModelCriteriaTools;
use Thelia\Model\CurrencyQuery; use Thelia\Model\CurrencyQuery;
use Thelia\Model\ConfigQuery; use Thelia\Model\ConfigQuery;
@@ -69,12 +67,8 @@ class Currency extends BaseLoop
{ {
$search = CurrencyQuery::create(); $search = CurrencyQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */ /* 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(); $id = $this->getId();

View File

@@ -31,8 +31,6 @@ use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Model\Tools\ModelCriteriaTools;
use Thelia\Model\Base\CategoryQuery; use Thelia\Model\Base\CategoryQuery;
use Thelia\Model\Base\ProductCategoryQuery; use Thelia\Model\Base\ProductCategoryQuery;
use Thelia\Model\Base\FeatureQuery; use Thelia\Model\Base\FeatureQuery;
@@ -84,12 +82,8 @@ class Feature extends BaseLoop
{ {
$search = FeatureQuery::create(); $search = FeatureQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */ /* manage translations */
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale()); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();

View File

@@ -31,8 +31,6 @@ use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Model\Tools\ModelCriteriaTools;
use Thelia\Model\Base\FeatureAvQuery; use Thelia\Model\Base\FeatureAvQuery;
use Thelia\Model\ConfigQuery; use Thelia\Model\ConfigQuery;
use Thelia\Type\TypeCollection; use Thelia\Type\TypeCollection;
@@ -77,12 +75,8 @@ class FeatureAvailability extends BaseLoop
{ {
$search = FeatureAvQuery::create(); $search = FeatureAvQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */ /* manage translations */
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale()); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();

View File

@@ -33,8 +33,6 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog; use Thelia\Log\Tlog;
use Thelia\Model\Tools\ModelCriteriaTools;
use Thelia\Model\Base\FeatureProductQuery; use Thelia\Model\Base\FeatureProductQuery;
use Thelia\Model\ConfigQuery; use Thelia\Model\ConfigQuery;
use Thelia\Model\Map\FeatureAvTableMap; use Thelia\Model\Map\FeatureAvTableMap;
@@ -70,7 +68,8 @@ class FeatureValue extends BaseLoop
new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse')) new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse'))
), ),
'manual' 'manual'
) ),
Argument::createIntTypeArgument('lang')
); );
} }
@@ -84,10 +83,8 @@ class FeatureValue extends BaseLoop
$search = FeatureProductQuery::create(); $search = FeatureProductQuery::create();
/* manage featureAv translations */ /* manage featureAv translations */
ModelCriteriaTools::getFrontEndI18n( $this->configureI18nProcessing(
$search, $search,
ConfigQuery::read("default_lang_without_translation", 1),
$this->request->getSession()->getLocale(),
array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'),
FeatureAvTableMap::TABLE_NAME, FeatureAvTableMap::TABLE_NAME,
'FEATURE_AV_ID' 'FEATURE_AV_ID'

View File

@@ -32,8 +32,6 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog; use Thelia\Log\Tlog;
use Thelia\Model\Tools\ModelCriteriaTools;
use Thelia\Model\FolderQuery; use Thelia\Model\FolderQuery;
use Thelia\Model\ConfigQuery; use Thelia\Model\ConfigQuery;
use Thelia\Type\TypeCollection; use Thelia\Type\TypeCollection;
@@ -80,12 +78,8 @@ class Folder extends BaseLoop
{ {
$search = FolderQuery::create(); $search = FolderQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */ /* manage translations */
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale()); $this->configureI18nProcessing($search);
$id = $this->getId(); $id = $this->getId();

View File

@@ -207,16 +207,8 @@ class Image extends BaseLoop
} }
/** /* manage translations */
* \Criteria::INNER_JOIN in second parameter for joinWithI18n exclude query without translation. $this->configureI18nProcessing($search);
*
* @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
);
$results = $this->search($search, $pagination); $results = $this->search($search, $pagination);
@@ -295,6 +287,7 @@ class Image extends BaseLoop
), ),
'manual' 'manual'
), ),
Argument::createIntTypeArgument('lang'),
Argument::createIntTypeArgument('width'), Argument::createIntTypeArgument('width'),
Argument::createIntTypeArgument('height'), Argument::createIntTypeArgument('height'),

View File

@@ -33,8 +33,6 @@ use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog; use Thelia\Log\Tlog;
use Thelia\Model\Tools\ModelCriteriaTools;
use Thelia\Model\CategoryQuery; use Thelia\Model\CategoryQuery;
use Thelia\Model\Map\FeatureProductTableMap; use Thelia\Model\Map\FeatureProductTableMap;
use Thelia\Model\Map\ProductPriceTableMap; use Thelia\Model\Map\ProductPriceTableMap;
@@ -138,12 +136,8 @@ class Product extends BaseLoop
{ {
$search = ProductQuery::create(); $search = ProductQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */ /* 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(); $attributeNonStrictMatch = $this->getAttribute_non_strict_match();
$isPSELeftJoinList = array(); $isPSELeftJoinList = array();

View File

@@ -31,8 +31,6 @@ use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Model\Tools\ModelCriteriaTools;
use Thelia\Model\CustomerTitleQuery; use Thelia\Model\CustomerTitleQuery;
use Thelia\Model\ConfigQuery; use Thelia\Model\ConfigQuery;
@@ -67,12 +65,8 @@ class Title extends BaseLoop
{ {
$search = CustomerTitleQuery::create(); $search = CustomerTitleQuery::create();
$backendContext = $this->getBackend_context();
$lang = $this->getLang();
/* manage translations */ /* 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(); $id = $this->getId();

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
/*! X-editable - v1.4.6 /*! X-editable - v1.4.6
* In-place editing with Twitter Bootstrap, jQuery UI or pure jQuery * In-place editing with Twitter Bootstrap, jQuery UI or pure jQuery
* http://github.com/vitalets/x-editable * http://github.com/vitalets/x-editable
* Copyright (c) 2013 Vitaliy Potapov; Licensed MIT */ * Copyright (c) 2013 Vitaliy Potapov; Licensed MIT */
@@ -18,45 +18,45 @@
vertical-align: top; vertical-align: top;
margin-left: 7px; margin-left: 7px;
/* inline-block emulation for IE7*/ /* inline-block emulation for IE7*/
zoom: 1; zoom: 1;
*display: inline; *display: inline;
} }
.editable-buttons.editable-buttons-bottom { .editable-buttons.editable-buttons-bottom {
display: block; display: block;
margin-top: 7px; margin-top: 7px;
margin-left: 0; margin-left: 0;
} }
.editable-input { .editable-input {
vertical-align: top; vertical-align: top;
display: inline-block; /* should be inline to take effect of parent's white-space: nowrap */ display: inline-block; /* should be inline to take effect of parent's white-space: nowrap */
width: auto; /* bootstrap-responsive has width: 100% that breakes layout */ width: auto; /* bootstrap-responsive has width: 100% that breakes layout */
white-space: normal; /* reset white-space decalred in parent*/ white-space: normal; /* reset white-space decalred in parent*/
/* display-inline emulation for IE7*/ /* display-inline emulation for IE7*/
zoom: 1; zoom: 1;
*display: inline; *display: inline;
} }
.editable-buttons .editable-cancel { .editable-buttons .editable-cancel {
margin-left: 7px; margin-left: 7px;
} }
/*for jquery-ui buttons need set height to look more pretty*/ /*for jquery-ui buttons need set height to look more pretty*/
.editable-buttons button.ui-button-icon-only { .editable-buttons button.ui-button-icon-only {
height: 24px; height: 24px;
width: 30px; width: 30px;
} }
.editableform-loading { .editableform-loading {
background: url('../img/loading.gif') center center no-repeat; background: url('../img/loading.gif') center center no-repeat;
height: 25px; height: 25px;
width: auto; width: auto;
min-width: 25px; min-width: 25px;
} }
.editable-inline .editableform-loading { .editable-inline .editableform-loading {
background-position: left 5px; background-position: left 5px;
} }
.editable-error-block { .editable-error-block {
@@ -68,17 +68,17 @@
/*add padding for jquery ui*/ /*add padding for jquery ui*/
.editable-error-block.ui-state-error { .editable-error-block.ui-state-error {
padding: 3px; padding: 3px;
} }
.editable-error { .editable-error {
color: red; color: red;
} }
/* ---- For specific types ---- */ /* ---- For specific types ---- */
.editableform .editable-date { .editableform .editable-date {
padding: 0; padding: 0;
margin: 0; margin: 0;
float: left; float: left;
} }
@@ -86,25 +86,25 @@
/* move datepicker icon to center of add-on button. See https://github.com/vitalets/x-editable/issues/183 */ /* move datepicker icon to center of add-on button. See https://github.com/vitalets/x-editable/issues/183 */
.editable-inline .add-on .icon-th { .editable-inline .add-on .icon-th {
margin-top: 3px; margin-top: 3px;
margin-left: 1px; margin-left: 1px;
} }
/* checklist vertical alignment */ /* checklist vertical alignment */
.editable-checklist label input[type="checkbox"], .editable-checklist label input[type="checkbox"],
.editable-checklist label span { .editable-checklist label span {
vertical-align: middle; vertical-align: middle;
margin: 0; margin: 0;
} }
.editable-checklist label { .editable-checklist label {
white-space: nowrap; white-space: nowrap;
} }
/* set exact width of textarea to fit buttons toolbar */ /* set exact width of textarea to fit buttons toolbar */
.editable-wysihtml5 { .editable-wysihtml5 {
width: 566px; width: 566px;
height: 250px; height: 250px;
} }
/* clear button shown as link in date inputs */ /* clear button shown as link in date inputs */
@@ -119,16 +119,16 @@
.editable-clear-x { .editable-clear-x {
background: url('../img/clear.png') center center no-repeat; background: url('../img/clear.png') center center no-repeat;
display: block; display: block;
width: 13px; width: 13px;
height: 13px; height: 13px;
position: absolute; position: absolute;
opacity: 0.6; opacity: 0.6;
z-index: 100; z-index: 100;
top: 50%; top: 50%;
right: 6px; right: 6px;
margin-top: -6px; margin-top: -6px;
} }
.editable-clear-x:hover { .editable-clear-x:hover {
@@ -140,49 +140,49 @@
} }
.editable-container.editable-popup { .editable-container.editable-popup {
max-width: none !important; /* without this rule poshytip/tooltip does not stretch */ max-width: none !important; /* without this rule poshytip/tooltip does not stretch */
} }
.editable-container.popover { .editable-container.popover {
width: auto; /* without this rule popover does not stretch */ width: auto; /* without this rule popover does not stretch */
} }
.editable-container.editable-inline { .editable-container.editable-inline {
display: inline-block; display: inline-block;
vertical-align: middle; vertical-align: middle;
width: auto; width: auto;
/* inline-block emulation for IE7*/ /* inline-block emulation for IE7*/
zoom: 1; zoom: 1;
*display: inline; *display: inline;
} }
.editable-container.ui-widget { .editable-container.ui-widget {
font-size: inherit; /* jqueryui widget font 1.1em too big, overwrite it */ font-size: inherit; /* jqueryui widget font 1.1em too big, overwrite it */
z-index: 9990; /* should be less than select2 dropdown z-index to close dropdown first when click */ z-index: 9990; /* should be less than select2 dropdown z-index to close dropdown first when click */
} }
.editable-click, .editable-click,
a.editable-click, a.editable-click,
a.editable-click:hover { a.editable-click:hover {
text-decoration: none; text-decoration: none;
border-bottom: dashed 1px #0088cc; border-bottom: dotted 1px #0088cc;
} }
.editable-click.editable-disabled, .editable-click.editable-disabled,
a.editable-click.editable-disabled, a.editable-click.editable-disabled,
a.editable-click.editable-disabled:hover { a.editable-click.editable-disabled:hover {
color: #585858; color: #585858;
cursor: default; cursor: default;
border-bottom: none; border-bottom: none;
} }
.editable-empty, .editable-empty:hover, .editable-empty:focus{ .editable-empty, .editable-empty:hover, .editable-empty:focus{
font-style: italic; font-style: italic;
color: #DD1144; color: #DD1144;
/* border-bottom: none; */ /* border-bottom: none; */
text-decoration: none; text-decoration: none;
} }
.editable-unsaved { .editable-unsaved {
font-weight: bold; font-weight: bold;
} }
.editable-unsaved:after { .editable-unsaved:after {
@@ -194,12 +194,12 @@ a.editable-click.editable-disabled:hover {
-moz-transition: background-color 1400ms ease-out; -moz-transition: background-color 1400ms ease-out;
-o-transition: background-color 1400ms ease-out; -o-transition: background-color 1400ms ease-out;
-ms-transition: background-color 1400ms ease-out; -ms-transition: background-color 1400ms ease-out;
transition: background-color 1400ms ease-out; transition: background-color 1400ms ease-out;
} }
/*see https://github.com/vitalets/x-editable/issues/139 */ /*see https://github.com/vitalets/x-editable/issues/139 */
.form-horizontal .editable .form-horizontal .editable
{ {
padding-top: 5px; padding-top: 5px;
display:inline-block; display:inline-block;
} }

View File

@@ -717,10 +717,4 @@ label {
// Center the alert box (20px bottom margin) in the table cell // Center the alert box (20px bottom margin) in the table cell
padding: 20px 20px 0 20px; padding: 20px 20px 0 20px;
} }
}
// -- Editable tweaks ---------------------------------------------------------
.editable-click, a.editable-click, a.editable-click:hover {
border-bottom: 1px dotted #0088CC;
} }

View File

@@ -241,7 +241,7 @@ $(function() {
$.ajax({ $.ajax({
url : "{url path='admin/catalog/category'}", url : "{url path='admin/catalog/category'}",
data : { data : {
id : $(this).data('id'), category_id : $(this).data('id'),
action : 'visibilityToggle' action : 'visibilityToggle'
} }
}); });

View File

@@ -12,11 +12,11 @@
{if $action == 'edit'} {if $action == 'edit'}
{intl l='Editing %cat' cat="{$TITLE}"} {intl l='Editing %cat' cat="{$TITLE}"}
{else} {else}
{$TITLE} <a href="{url path="admin/catalog/category/edit/$ID"}" title="{intl l='Edit this category'}">{intl l="(edit)"}</a> {$TITLE} <a href="{url path='admin/catalog/category' id="$ID" action='edit'}" title="{intl l='Edit this category'}">{intl l="(edit)"}</a>
{/if} {/if}
</li> </li>
{else} {else}
<li><a href="{url path="admin/catalog/category/browse/$ID"}">{$TITLE}</a> <span class="divider">/</span></li> <li><a href="{url path='admin/catalog/category' id="$ID" action='browse'}">{$TITLE}</a> <span class="divider">/</span></li>
{/if} {/if}
{/loop} {/loop}
{/ifloop} {/ifloop}

View File

@@ -12,7 +12,7 @@
<ul class="nav nav-pills"> <ul class="nav nav-pills">
{loop name="lang_list" type="lang" default_only={$default_only}} {loop name="lang_list" type="lang" default_only={$default_only}}
<li {if $IS_DEFAULT}class="active"{/if}> <li {if $IS_DEFAULT}class="active"{/if}>
<a href="#" title="{intl l="Edit information for %lng" lng=$TITLE}"> <a href="#" title="{intl l="Edit information in %lng" lng=$TITLE}">
<img src="{image file="../assets/img/flags/{$CODE}.gif"}" alt="{intl l=$TITLE}" /> <img src="{image file="../assets/img/flags/{$CODE}.gif"}" alt="{intl l=$TITLE}" />
</a> </a>
</li> </li>