start rewriting
This commit is contained in:
@@ -218,10 +218,10 @@ abstract class BaseLoop
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \ModelCriteria $search
|
||||
* @param $pagination
|
||||
* @param ModelCriteria $search
|
||||
* @param $pagination
|
||||
*
|
||||
* @return array|\PropelModelPager
|
||||
* @return array|\Propel\Runtime\Util\PropelModelPager
|
||||
*/
|
||||
protected function searchWithPagination(ModelCriteria $search, &$pagination)
|
||||
{
|
||||
|
||||
@@ -92,7 +92,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());
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale());
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class AttributeAvailability extends BaseLoop
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale());
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ class AttributeCombination extends BaseLoop
|
||||
/* manage attribute translations */
|
||||
ModelCriteriaTools::getFrontEndI18n(
|
||||
$search,
|
||||
ConfigQuery::read("default_lang_without_translation", 1),
|
||||
ConfigQuery::getDefaultLangWhenNoTranslationAvailable(),
|
||||
$this->request->getSession()->getLocale(),
|
||||
array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'),
|
||||
AttributeTableMap::TABLE_NAME,
|
||||
@@ -91,7 +91,7 @@ class AttributeCombination extends BaseLoop
|
||||
/* manage attributeAv translations */
|
||||
ModelCriteriaTools::getFrontEndI18n(
|
||||
$search,
|
||||
ConfigQuery::read("default_lang_without_translation", 1),
|
||||
ConfigQuery::getDefaultLangWhenNoTranslationAvailable(),
|
||||
$this->request->getSession()->getLocale(),
|
||||
array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'),
|
||||
AttributeAvTableMap::TABLE_NAME,
|
||||
|
||||
@@ -103,7 +103,7 @@ class Category extends BaseLoop
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
$locale = ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale());
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
@@ -185,7 +185,7 @@ class Category extends BaseLoop
|
||||
->set("DESCRIPTION", $category->getVirtualColumn('i18n_DESCRIPTION'))
|
||||
->set("POSTSCRIPTUM", $category->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
||||
->set("PARENT", $category->getParent())
|
||||
->set("URL", $category->getUrl())
|
||||
->set("URL", $category->getUrl($locale))
|
||||
->set("PRODUCT_COUNT", $category->countChild())
|
||||
->set("VISIBLE", $category->getVisible() ? "1" : "0")
|
||||
->set("POSITION", $category->getPosition())
|
||||
|
||||
@@ -93,7 +93,7 @@ class Content extends BaseLoop
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
$locale = ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale());
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
@@ -226,7 +226,7 @@ class Content extends BaseLoop
|
||||
->set("DESCRIPTION", $content->getVirtualColumn('i18n_DESCRIPTION'))
|
||||
->set("POSTSCRIPTUM", $content->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
||||
->set("POSITION", $content->getPosition())
|
||||
->set("URL", $content->getUrl())
|
||||
->set("URL", $content->getUrl($locale))
|
||||
;
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
|
||||
@@ -75,7 +75,7 @@ class Country extends BaseLoop
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale());
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ class Currency extends BaseLoop
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale(), array('NAME'));
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale(), array('NAME'));
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ class Feature extends BaseLoop
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale());
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ class FeatureAvailability extends BaseLoop
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale());
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ class FeatureValue extends BaseLoop
|
||||
/* manage featureAv translations */
|
||||
ModelCriteriaTools::getFrontEndI18n(
|
||||
$search,
|
||||
ConfigQuery::read("default_lang_without_translation", 1),
|
||||
ConfigQuery::getDefaultLangWhenNoTranslationAvailable(),
|
||||
$this->request->getSession()->getLocale(),
|
||||
array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'),
|
||||
FeatureAvTableMap::TABLE_NAME,
|
||||
|
||||
@@ -85,7 +85,7 @@ class Folder extends BaseLoop
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
$locale = ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale());
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
@@ -168,7 +168,7 @@ class Folder extends BaseLoop
|
||||
->set("DESCRIPTION", $folder->getVirtualColumn('i18n_DESCRIPTION'))
|
||||
->set("POSTSCRIPTUM", $folder->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
||||
->set("PARENT", $folder->getParent())
|
||||
->set("URL", $folder->getUrl())
|
||||
->set("URL", $folder->getUrl($locale))
|
||||
->set("CONTENT_COUNT", $folder->countChild())
|
||||
->set("VISIBLE", $folder->getVisible() ? "1" : "0")
|
||||
->set("POSITION", $folder->getPosition())
|
||||
|
||||
@@ -215,7 +215,7 @@ class Image extends BaseLoop
|
||||
|
||||
$search->joinWithI18n(
|
||||
$this->request->getSession()->getLocale(),
|
||||
(ConfigQuery::read("default_lang_without_translation", 1)) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN
|
||||
(ConfigQuery::getDefaultLangWhenNoTranslationAvailable()) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN
|
||||
);
|
||||
|
||||
$results = $this->search($search, $pagination);
|
||||
|
||||
@@ -143,7 +143,7 @@ class Product extends BaseLoop
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale());
|
||||
$locale = ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale());
|
||||
|
||||
$attributeNonStrictMatch = $this->getAttribute_non_strict_match();
|
||||
$isPSELeftJoinList = array();
|
||||
@@ -520,7 +520,7 @@ class Product extends BaseLoop
|
||||
->set("CHAPO", $product->getVirtualColumn('i18n_CHAPO'))
|
||||
->set("DESCRIPTION", $product->getVirtualColumn('i18n_DESCRIPTION'))
|
||||
->set("POSTSCRIPTUM", $product->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
||||
->set("URL", $product->getUrl())
|
||||
->set("URL", $product->getUrl($locale))
|
||||
->set("BEST_PRICE", $product->getVirtualColumn('real_lowest_price'))
|
||||
->set("IS_PROMO", $product->getVirtualColumn('main_product_is_promo'))
|
||||
->set("IS_NEW", $product->getVirtualColumn('main_product_is_new'))
|
||||
|
||||
@@ -72,7 +72,7 @@ class Title extends BaseLoop
|
||||
$lang = $this->getLang();
|
||||
|
||||
/* manage translations */
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale(), array('SHORT', 'LONG'));
|
||||
ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale(), array('SHORT', 'LONG'));
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\Category as BaseCategory;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
class Category extends BaseCategory
|
||||
{
|
||||
@@ -15,8 +16,9 @@ class Category extends BaseCategory
|
||||
return CategoryQuery::countChild($this->getId());
|
||||
}
|
||||
|
||||
public function getUrl()
|
||||
public function getUrl($locale)
|
||||
{
|
||||
return URL::retrieve('category', $this->getId(), $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,4 +22,14 @@ class ConfigQuery extends BaseConfigQuery {
|
||||
|
||||
return $value ? $value->getValue() : $default;
|
||||
}
|
||||
|
||||
public static function getDefaultLangWhenNoTranslationAvailable()
|
||||
{
|
||||
return ConfigQuery::read("default_lang_without_translation", 1);
|
||||
}
|
||||
|
||||
public static function isRewritingEnable()
|
||||
{
|
||||
return self::read("rewriting_enable") == 1;
|
||||
}
|
||||
} // ConfigQuery
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\Content as BaseContent;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
class Content extends BaseContent
|
||||
{
|
||||
public function getUrl()
|
||||
public function getUrl($locale)
|
||||
{
|
||||
|
||||
return URL::retrieve('content', $this->getId(), $locale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\Folder as BaseFolder;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
class Folder extends BaseFolder
|
||||
{
|
||||
@@ -14,9 +15,9 @@ class Folder extends BaseFolder
|
||||
return FolderQuery::countChild($this->getId());
|
||||
}
|
||||
|
||||
public function getUrl()
|
||||
public function getUrl($locale)
|
||||
{
|
||||
|
||||
return URL::retrieve('folder', $this->getId(), $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\Product as BaseProduct;
|
||||
use Thelia\Model\ProductSaleElements;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
class Product extends BaseProduct
|
||||
{
|
||||
public function getUrl()
|
||||
public function getUrl($locale)
|
||||
{
|
||||
|
||||
return URL::retrieve('product', $this->getId(), $locale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,10 +109,14 @@ class ModelCriteriaTools
|
||||
}
|
||||
}
|
||||
|
||||
$askedLocale = $lang === null ? $currentLocale : $localeSearch->getLocale();
|
||||
|
||||
if($backendContext) {
|
||||
self::getBackEndI18n($search, $lang === null ? $currentLocale : $localeSearch->getLocale(), $columns, $foreignTable, $foreignKey);
|
||||
self::getBackEndI18n($search, $askedLocale, $columns, $foreignTable, $foreignKey);
|
||||
} else {
|
||||
self::getFrontEndI18n($search, $defaultLangWithoutTranslation, $lang === null ? $currentLocale : $localeSearch->getLocale(), $columns, $foreignTable, $foreignKey);
|
||||
self::getFrontEndI18n($search, $defaultLangWithoutTranslation, $askedLocale, $columns, $foreignTable, $foreignKey);
|
||||
}
|
||||
|
||||
return $askedLocale;
|
||||
}
|
||||
}
|
||||
|
||||
35
core/lib/Thelia/Rewriting/RewritingResolver.php
Executable file
35
core/lib/Thelia/Rewriting/RewritingResolver.php
Executable file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Rewriting;
|
||||
|
||||
/**
|
||||
* Class RewritingResolver
|
||||
* @package Thelia\Rewriting
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
* This class provides methods to resolve rewritten URL as a query
|
||||
*/
|
||||
class RewritingResolver
|
||||
{
|
||||
|
||||
}
|
||||
56
core/lib/Thelia/Rewriting/RewritingRetriever.php
Executable file
56
core/lib/Thelia/Rewriting/RewritingRetriever.php
Executable file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Rewriting;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Model\Base\RewritingUrlQuery;
|
||||
|
||||
/**
|
||||
* Class RewritingRetriever
|
||||
* @package Thelia\Rewriting
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
* This class provides methods to retrieve a rewritten URL from a query
|
||||
*/
|
||||
class RewritingRetriever
|
||||
{
|
||||
public function getViewUrl($view, $viewId, $viewLocale)
|
||||
{
|
||||
$url = RewritingUrlQuery::create()
|
||||
->joinRewritingArgument('ra', Criteria::LEFT_JOIN)
|
||||
->where('ISNULL(`ra`.REWRITING_URL_ID)')
|
||||
->filterByView($view)
|
||||
->filterByViewId($viewId)
|
||||
->filterByViewLocale($viewLocale)
|
||||
->filterByRedirected(null)
|
||||
->orderByUpdatedAt(Criteria::DESC)
|
||||
->findOne();
|
||||
|
||||
return $url === null ? null : $url->getUrl();
|
||||
}
|
||||
|
||||
/*public function getSpecificUrl($view, $viewId, $viewLocale, $viewOtherParameters = array())
|
||||
{
|
||||
|
||||
}*/
|
||||
}
|
||||
@@ -24,6 +24,7 @@
|
||||
namespace Thelia\Tools;
|
||||
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Rewriting\RewritingRetriever;
|
||||
|
||||
class URL
|
||||
{
|
||||
@@ -101,4 +102,15 @@ class URL
|
||||
|
||||
return self::absoluteUrl($path, $parameters);
|
||||
}
|
||||
|
||||
public static function retrieve($view, $viewId, $viewLocale)
|
||||
{
|
||||
$rewrittenUrl = null;
|
||||
if(ConfigQuery::isRewritingEnable()) {
|
||||
$retriever = new RewritingRetriever();
|
||||
$rewrittenUrl = $retriever->getViewUrl($view, $viewId, $viewLocale);
|
||||
}
|
||||
|
||||
return $rewrittenUrl === null ? self::viewUrl($view, array($view . '_id' => $viewId, 'locale' => $viewLocale)) : $rewrittenUrl;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user