update changelog and fix cs

This commit is contained in:
Manuel Raynaud
2014-02-22 19:01:37 +01:00
parent b833b4a5b6
commit a5cfcf91ca
590 changed files with 21397 additions and 24262 deletions

View File

@@ -26,7 +26,7 @@ class ModelCriteriaTools
*/
public static function getFrontEndI18n(ModelCriteria &$search, $requestedLocale, $columns, $foreignTable, $foreignKey, $forceReturn = false)
{
if($foreignTable === null) {
if ($foreignTable === null) {
$foreignTable = $search->getTableMap()->getName();
$aliasPrefix = '';
} else {
@@ -38,8 +38,8 @@ class ModelCriteriaTools
$requestedLocaleI18nAlias = $aliasPrefix . 'requested_locale_i18n';
$defaultLocaleI18nAlias = $aliasPrefix . 'default_locale_i18n';
if($defaultLangWithoutTranslation == 0) {
if ($defaultLangWithoutTranslation == 0) {
$requestedLocaleJoin = new Join();
$requestedLocaleJoin->addExplicitCondition($search->getTableMap()->getName(), $foreignKey, null, $foreignTable . '_i18n', 'ID', $requestedLocaleI18nAlias);
$requestedLocaleJoin->setJoinType($forceReturn === false ? Criteria::INNER_JOIN : Criteria::LEFT_JOIN);
@@ -49,7 +49,7 @@ class ModelCriteriaTools
$search->withColumn('NOT ISNULL(`' . $requestedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'IS_TRANSLATED');
foreach($columns as $column) {
foreach ($columns as $column) {
$search->withColumn('`' . $requestedLocaleI18nAlias . '`.`' . $column . '`', $aliasPrefix . 'i18n_' . $column);
}
} else {
@@ -71,11 +71,11 @@ class ModelCriteriaTools
$search->withColumn('NOT ISNULL(`' . $requestedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'IS_TRANSLATED');
if($forceReturn === false) {
if ($forceReturn === false) {
$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(`' . $requestedLocaleI18nAlias . '`.ID) THEN `' . $requestedLocaleI18nAlias . '`.`' . $column . '` ELSE `' . $defaultLocaleI18nAlias . '`.`' . $column . '` END', $aliasPrefix . 'i18n_' . $column);
}
}
@@ -83,7 +83,7 @@ class ModelCriteriaTools
public static function getBackEndI18n(ModelCriteria &$search, $requestedLocale, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID')
{
if($foreignTable === null) {
if ($foreignTable === null) {
$foreignTable = $search->getTableMap()->getName();
$aliasPrefix = '';
} else {
@@ -101,7 +101,7 @@ class ModelCriteriaTools
$search->withColumn('NOT ISNULL(`' . $requestedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'IS_TRANSLATED');
foreach($columns as $column) {
foreach ($columns as $column) {
$search->withColumn('`' . $requestedLocaleI18nAlias . '`.`' . $column . '`', $aliasPrefix . 'i18n_' . $column);
}
}
@@ -117,8 +117,7 @@ class ModelCriteriaTools
}
$locale = $localeSearch->getLocale();
}
else {
} else {
// Use the currently defined locale
$locale = $currentLocale;
}

View File

@@ -29,8 +29,8 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* A trait to provide event dispatching mechanism to Model objects
*/
trait ModelEventDispatcherTrait {
trait ModelEventDispatcherTrait
{
/**
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
@@ -59,4 +59,4 @@ trait ModelEventDispatcherTrait {
$this->dispatcher->dispatch($eventName, $event);
}
}
}
}

View File

@@ -27,19 +27,21 @@ use Propel\Runtime\ActiveQuery\PropelQuery;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Propel;
trait PositionManagementTrait {
trait PositionManagementTrait
{
/**
* Create an instancer of this object query
*/
private function createQuery() {
private function createQuery()
{
return PropelQuery::from(__CLASS__);
}
/**
* Return the database name from this object's table map.
*/
private function getDatabaseNameFromMap() {
private function getDatabaseNameFromMap()
{
$class = new \ReflectionClass(self::TABLE_MAP);
return $class->getConstant('DATABASE_NAME');
@@ -49,15 +51,16 @@ trait PositionManagementTrait {
* Implementors may add some search criteria (e.g., parent id) to the queries
* used to change/get position by overloading this method.
*/
protected function addCriteriaToPositionQuery($query) {
protected function addCriteriaToPositionQuery($query)
{
// Add required criteria here...
}
/**
* Get the position of the next inserted object
*/
public function getNextPosition() {
public function getNextPosition()
{
$query = $this->createQuery()
->orderByPosition(Criteria::DESC)
->limit(1);
@@ -72,14 +75,16 @@ trait PositionManagementTrait {
/**
* Move up a object
*/
public function movePositionUp() {
public function movePositionUp()
{
$this->movePositionUpOrDown(true);
}
/**
* Move down a object
*/
public function movePositionDown() {
public function movePositionDown()
{
$this->movePositionUpOrDown(false);
}
@@ -102,8 +107,7 @@ trait PositionManagementTrait {
if ($up === true) {
// Find the object immediately before me
$search->filterByPosition(array('max' => $my_position-1))->orderByPosition(Criteria::DESC);
}
else {
} else {
// Find the object immediately after me
$search->filterByPosition(array('min' => $my_position+1))->orderByPosition(Criteria::ASC);
}
@@ -126,8 +130,7 @@ trait PositionManagementTrait {
$result->setDispatcher($this->getDispatcher())->setPosition($my_position)->save($cnx);
$cnx->commit();
}
catch (Exception $e) {
} catch (Exception $e) {
$cnx->rollback();
}
}
@@ -136,7 +139,8 @@ trait PositionManagementTrait {
/**
* Simply return the database name, from the constant in the MAP class.
*/
protected function getDatabaseName() {
protected function getDatabaseName()
{
// Find DATABASE_NAME constant
$mapClassName = self::TABLE_MAP;
@@ -192,8 +196,7 @@ trait PositionManagementTrait {
;
$cnx->commit();
}
catch (Exception $e) {
} catch (Exception $e) {
$cnx->rollback();
}
}
@@ -207,7 +210,7 @@ trait PositionManagementTrait {
$data = array();
$whereCriteria = array();
foreach($fields as $field => $value) {
foreach ($fields as $field => $value) {
$whereCriteria[] = $field . '=:' . $field;
$data[':' . $field] = $value;
}
@@ -221,4 +224,4 @@ trait PositionManagementTrait {
$statement->execute($data);
}
}
}

View File

@@ -35,12 +35,12 @@ use Thelia\Model\ConfigQuery;
/**
* A trait for managing Rewritten URLs from model classes
*/
trait UrlRewritingTrait {
trait UrlRewritingTrait
{
/**
* @returns string the view name of the rewritten object (e.g., 'category', 'product')
*/
protected abstract function getRewrittenUrlViewName();
abstract protected function getRewrittenUrlViewName();
/**
* Get the object URL for the given locale, rewritten if rewriting is enabled.
@@ -49,9 +49,10 @@ trait UrlRewritingTrait {
*/
public function getUrl($locale = null)
{
if(null === $locale) {
if (null === $locale) {
$locale = $this->getLocale();
}
return URL::getInstance()->retrieve($this->getRewrittenUrlViewName(), $this->getId(), $locale)->toString();
}
@@ -73,15 +74,13 @@ trait UrlRewritingTrait {
$this->dispatchEvent(TheliaEvents::GENERATE_REWRITTENURL, $generateEvent);
if($generateEvent->isRewritten())
{
if ($generateEvent->isRewritten()) {
return $generateEvent->getUrl();
}
$title = $this->getTitle();
if(null == $title) {
if (null == $title) {
throw new \RuntimeException('Impossible to create an url if title is null');
}
// Replace all weird characters with dashes
@@ -94,9 +93,9 @@ trait UrlRewritingTrait {
// TODO :
// check if URL url already exists, and add a numeric suffix, or the like
try{
try {
$i=0;
while(URL::getInstance()->resolve($urlFilePart)) {
while (URL::getInstance()->resolve($urlFilePart)) {
$i++;
$urlFilePart = sprintf("%s-%d.html",$cleanString, $i);
}
@@ -117,7 +116,7 @@ trait UrlRewritingTrait {
/**
* return the rewritten URL for the given locale
*
* @param string $locale a valid locale (e.g. en_US)
* @param string $locale a valid locale (e.g. en_US)
* @return null
*/
public function getRewrittenUrl($locale)
@@ -130,7 +129,7 @@ trait UrlRewritingTrait {
->findOne()
;
if($rewritingUrl) {
if ($rewritingUrl) {
$url = $rewritingUrl->getUrl();
} else {
$url = null;
@@ -142,7 +141,8 @@ trait UrlRewritingTrait {
/**
* Mark the current URL as obseolete
*/
public function markRewritenUrlObsolete() {
public function markRewritenUrlObsolete()
{
RewritingUrlQuery::create()
->filterByView($this->getRewrittenUrlViewName())
->filterByViewId($this->getId())
@@ -154,7 +154,7 @@ trait UrlRewritingTrait {
/**
* Set the rewritten URL for the given locale
*
* @param string $locale a valid locale (e.g. en_US)
* @param string $locale a valid locale (e.g. en_US)
* @param $url
* @return $this
* @throws UrlRewritingException
@@ -163,8 +163,9 @@ trait UrlRewritingTrait {
public function setRewrittenUrl($locale, $url)
{
$currentUrl = $this->getRewrittenUrl($locale);
if($currentUrl == $url || null === $url) {
if ($currentUrl == $url || null === $url) {
/* no url update */
return $this;
}
@@ -172,12 +173,12 @@ trait UrlRewritingTrait {
$resolver = new RewritingResolver($url);
/* we can reassign old url */
if(null === $resolver->redirectedToUrl) {
if (null === $resolver->redirectedToUrl) {
/* else ... */
if($resolver->view == $this->getRewrittenUrlViewName() && $resolver->viewId == $this->getId()) {
if ($resolver->view == $this->getRewrittenUrlViewName() && $resolver->viewId == $this->getId()) {
/* it's an url related to the current object */
if($resolver->locale != $locale) {
if ($resolver->locale != $locale) {
/* it is an url related to this product for another locale */
throw new UrlRewritingException('URL_ALREADY_EXISTS', UrlRewritingException::URL_ALREADY_EXISTS);
}
@@ -193,15 +194,15 @@ trait UrlRewritingTrait {
throw new UrlRewritingException('URL_ALREADY_EXISTS', UrlRewritingException::URL_ALREADY_EXISTS);
}
}
} catch(UrlRewritingException $e) {
} catch (UrlRewritingException $e) {
/* It's all good if URL is not found */
if($e->getCode() !== UrlRewritingException::URL_NOT_FOUND) {
if ($e->getCode() !== UrlRewritingException::URL_NOT_FOUND) {
throw $e;
}
}
/* set the new URL */
if(isset($resolver)) {
if (isset($resolver)) {
/* erase the old one */
$rewritingUrl = RewritingUrlQuery::create()->findOneByUrl($url);
$rewritingUrl->setView($this->getRewrittenUrlViewName())
@@ -231,4 +232,4 @@ trait UrlRewritingTrait {
return $this;
}
}
}