sid : rewriting
This commit is contained in:
@@ -24,6 +24,7 @@ namespace Thelia\Rewriting;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Model\Base\RewritingUrlQuery;
|
||||
use Thelia\Model\Map\RewritingUrlTableMap;
|
||||
|
||||
/**
|
||||
* Class RewritingRetriever
|
||||
@@ -36,7 +37,14 @@ class RewritingRetriever
|
||||
{
|
||||
public function getViewUrl($view, $viewId, $viewLocale)
|
||||
{
|
||||
$url = RewritingUrlQuery::create()
|
||||
$url = $this->getViewUrlQuery($view, $viewId, $viewLocale);
|
||||
|
||||
return $url === null ? null : $url->getUrl();
|
||||
}
|
||||
|
||||
protected function getViewUrlQuery($view, $viewId, $viewLocale)
|
||||
{
|
||||
return RewritingUrlQuery::create()
|
||||
->joinRewritingArgument('ra', Criteria::LEFT_JOIN)
|
||||
->where('ISNULL(`ra`.REWRITING_URL_ID)')
|
||||
->filterByView($view)
|
||||
@@ -45,12 +53,49 @@ class RewritingRetriever
|
||||
->filterByRedirected(null)
|
||||
->orderByUpdatedAt(Criteria::DESC)
|
||||
->findOne();
|
||||
}
|
||||
|
||||
public function getSpecificUrl($view = null, $viewId = null, $viewLocale = null, $viewOtherParameters = array())
|
||||
{
|
||||
$urlQuery = RewritingUrlQuery::create()
|
||||
->joinRewritingArgument('ra', Criteria::LEFT_JOIN)
|
||||
->withColumn('`ra`.PARAMETER', 'ra_parameter')
|
||||
->withColumn('`ra`.VALUE', 'ra_value')
|
||||
->filterByView($view)
|
||||
->filterByViewId($viewId)
|
||||
->filterByViewLocale($viewLocale)
|
||||
->filterByRedirected(null)
|
||||
->orderByUpdatedAt(Criteria::DESC);
|
||||
|
||||
$otherParametersCount = count($viewOtherParameters);
|
||||
if($otherParametersCount > 0) {
|
||||
$parameterConditions = array();
|
||||
foreach($viewOtherParameters as $parameter => $value) {
|
||||
$conditionName = 'other_parameter_condition_' . count($parameterConditions);
|
||||
$urlQuery->condition('parameter_condition', '`ra_parameter`= ?', $parameter, \PDO::PARAM_STR)
|
||||
->condition('value_condition', '`ra_value` = ?', $value, \PDO::PARAM_STR)
|
||||
->combine(array('parameter_condition', 'value_condition'), Criteria::LOGICAL_AND, $conditionName);
|
||||
$parameterConditions[] = $conditionName;
|
||||
}
|
||||
|
||||
$urlQuery->combine($parameterConditions, Criteria::LOGICAL_OR, 'parameter_full_condition');
|
||||
|
||||
$urlQuery->groupBy(RewritingUrlTableMap::ID);
|
||||
|
||||
$urlQuery->condition('count_condition', 'COUNT(' . RewritingUrlTableMap::ID . ') = ?', $otherParametersCount, \PDO::PARAM_INT)
|
||||
->combine(array('count_condition', 'parameter_full_condition'), Criteria::LOGICAL_AND, 'full_having_condition');
|
||||
|
||||
|
||||
$urlQuery
|
||||
->having(array('full_having_condition'))
|
||||
//->having('COUNT(' . RewritingUrlTableMap::ID . ') = ?', $otherParametersCount, \PDO::PARAM_INT)
|
||||
;
|
||||
} else {
|
||||
$urlQuery->where('ISNULL(`ra`.REWRITING_URL_ID)');
|
||||
}
|
||||
|
||||
$url = $urlQuery->findOne();
|
||||
|
||||
return $url === null ? null : $url->getUrl();
|
||||
}
|
||||
|
||||
/*public function getSpecificUrl($view, $viewId, $viewLocale, $viewOtherParameters = array())
|
||||
{
|
||||
|
||||
}*/
|
||||
}
|
||||
|
||||
44
core/lib/Thelia/Tests/Rewriting/RewritingRetrieverTest.php
Executable file
44
core/lib/Thelia/Tests/Rewriting/RewritingRetrieverTest.php
Executable file
@@ -0,0 +1,44 @@
|
||||
<?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\Tests\Rewriting;
|
||||
|
||||
use Thelia\Rewriting\RewritingRetriever;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RewritingRetrieverTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetViewUrl()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function testGetSpecificUrl()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
39
core/lib/Thelia/Tests/Tools/URLTest.php
Executable file
39
core/lib/Thelia/Tests/Tools/URLTest.php
Executable file
@@ -0,0 +1,39 @@
|
||||
<?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\Tests\Type;
|
||||
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class URLTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testRetrieve()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
namespace Thelia\Tools;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Rewriting\RewritingRetriever;
|
||||
|
||||
@@ -103,6 +104,13 @@ class URL
|
||||
return self::absoluteUrl($path, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $view
|
||||
* @param $viewId
|
||||
* @param $viewLocale
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public static function retrieve($view, $viewId, $viewLocale)
|
||||
{
|
||||
$rewrittenUrl = null;
|
||||
@@ -113,4 +121,30 @@ class URL
|
||||
|
||||
return $rewrittenUrl === null ? self::viewUrl($view, array($view . '_id' => $viewId, 'locale' => $viewLocale)) : $rewrittenUrl;
|
||||
}
|
||||
|
||||
public static function retrieveCurrent(Request $request)
|
||||
{
|
||||
$rewrittenUrl = null;
|
||||
if(ConfigQuery::isRewritingEnable()) {
|
||||
$view = $request->query->get('view', null);
|
||||
$viewId = $view === null ? null : $request->query->get($view . '_id', null);
|
||||
$viewLocale = $request->query->get('locale', null);
|
||||
|
||||
$allOtherParameters = $request->query->all();
|
||||
if($view !== null) {
|
||||
unset($allOtherParameters['view']);
|
||||
}
|
||||
if($viewId !== null) {
|
||||
unset($allOtherParameters[$view . '_id']);
|
||||
}
|
||||
if($viewLocale !== null) {
|
||||
unset($allOtherParameters['locale']);
|
||||
}
|
||||
|
||||
$retriever = new RewritingRetriever();
|
||||
$rewrittenUrl = $retriever->getSpecificUrl($view, $viewId, $viewLocale, $allOtherParameters);
|
||||
}
|
||||
|
||||
return $rewrittenUrl === null ? self::viewUrl($view, array($view . '_id' => $viewId, 'locale' => $viewLocale)) : $rewrittenUrl;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user