Conflicts:
	core/lib/Thelia/Core/Template/Element/BaseLoop.php
This commit is contained in:
franck
2013-07-09 11:45:01 +02:00
32 changed files with 2069 additions and 98 deletions

View File

@@ -0,0 +1,58 @@
<?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\Core\Security\Encoder;
/**
*
* use password api include in php 5.5 and available throw the password_compat library.
*
* Class PasswordPhpCompatEncoder
* @package Thelia\Core\Security\Encoder
*/
class PasswordPhpCompatEncoder implements PasswordEncoderInterface {
/**
* Encode a string.
*
* @param string $password the password to encode
* @param string $algorithm the hash() algorithm
* @return string $salt the salt, the salt is not used here.
*/
public function encode($password, $algorithm, $salt = null)
{
return password_hash($password, $algorithm);
}
/**
* Check a string against an encoded password.
*
* @param string $string the string to compare against password
* @param string $password the encoded password
* @param string $algorithm the hash() algorithm, not used here
* @return string $salt the salt, not used here
*/
public function isEqual($string, $password, $algorithm = null, $salt = null)
{
return password_verify($string, $password);
}
}

View File

@@ -115,6 +115,7 @@ abstract class BaseLoop
$faultDetails = array();
while (($argument = $this->args->current()) !== false) {
$this->args->next();
$value = isset($nameValuePairs[$argument->name]) ? $nameValuePairs[$argument->name] : null;

View File

@@ -52,11 +52,11 @@ class Argument
}
public function getValue() {
return $this->value;
return $this->type->getFormattedValue($this->value);
}
public function setValue($value) {
$this->value = $value;
$this->value = $value === null ? null : (string)$value;
}
public static function createAnyTypeArgument($name, $default=null, $mandatory=false, $empty=true)

View File

@@ -83,7 +83,7 @@ class Category extends BaseLoop
new Argument(
'order',
new TypeCollection(
new Type\EnumType('alpha', 'alpha_reverse', 'reverse')
new Type\EnumListType('alpha', 'alpha_reverse', 'reverse')
)
),
Argument::createBooleanTypeArgument('random', 0),
@@ -137,23 +137,32 @@ class Category extends BaseLoop
$search->filterByVisible($this->getVisible() ? 1 : 0);
switch ($this->getOrder()) {
case "alpha":
$search->addAscendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
break;
case "alpha_reverse":
$search->addDescendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
break;
case "reverse":
$search->orderByPosition(\Criteria::DESC);
break;
default:
$search->orderByPosition();
break;
$orders = $this->getOrder();
if(null === $orders) {
$search->orderByPosition();
} else {
foreach($orders as $order) {
switch ($order) {
case "alpha":
$search->addAscendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
break;
case "alpha_reverse":
$search->addDescendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
break;
case "reverse":
$search->orderByPosition(\Criteria::DESC);
break;
default:
$search->orderByPosition();
break;
}
}
}
$random = $this->getRandom();
if ($this->getRandom() === true) {
if ($random === true) {
$search->clearOrderByColumns();
$search->addAscendingOrderByColumn('RAND()');
}

View File

@@ -24,7 +24,6 @@
namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
@@ -34,8 +33,8 @@ use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog;
use Thelia\Model\CategoryQuery;
use Thelia\Model\Map\ProductTableMap;
use Thelia\Model\ProductCategoryQuery;
use Thelia\Model\ProductPeer;
use Thelia\Model\ProductQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Type\TypeCollection;
@@ -80,7 +79,7 @@ class Product extends BaseLoop
new Argument(
'order',
new TypeCollection(
new Type\EnumType(array('alpha', 'alpha_reverse', 'reverse', 'min_price', 'max_price', 'category', 'manual', 'manual_reverse', 'ref', 'promo', 'new'))
new Type\EnumListType(array('alpha', 'alpha_reverse', 'reverse', 'min_price', 'max_price', 'manual', 'manual_reverse', 'ref', 'promo', 'new'))
)
),
Argument::createBooleanTypeArgument('random', 0),
@@ -97,6 +96,8 @@ class Product extends BaseLoop
{
$search = ProductQuery::create();
$search->withColumn('CASE WHEN ' . ProductTableMap::PROMO . '=1 THEN ' . ProductTableMap::PRICE2 . ' ELSE ' . ProductTableMap::PRICE . ' END', 'real_price');
$id = $this->getId();
if (!is_null($id)) {
@@ -153,10 +154,15 @@ class Product extends BaseLoop
$min_price = $this->getMin_price();
if(null !== $min_price) {
$search->condition('in_promo', ProductPeer::PROMO . Criteria::EQUAL . '1')
->condition('not_in_promo', ProductPeer::PROMO . Criteria::NOT_EQUAL . '1')
->condition('min_price2', ProductPeer::PRICE2 . Criteria::GREATER_EQUAL . '?', $min_price)
->condition('min_price', ProductPeer::PRICE . Criteria::GREATER_EQUAL . '?', $min_price)
/**
* Following should work but does not :
*
* $search->filterBy('real_price', $max_price, Criteria::GREATER_EQUAL);
*/
$search->condition('in_promo', ProductTableMap::PROMO . Criteria::EQUAL . '1')
->condition('not_in_promo', ProductTableMap::PROMO . Criteria::NOT_EQUAL . '1')
->condition('min_price2', ProductTableMap::PRICE2 . Criteria::GREATER_EQUAL . '?', $min_price)
->condition('min_price', ProductTableMap::PRICE . Criteria::GREATER_EQUAL . '?', $min_price)
->combine(array('in_promo', 'min_price2'), Criteria::LOGICAL_AND, 'in_promo_min_price')
->combine(array('not_in_promo', 'min_price'), Criteria::LOGICAL_AND, 'not_in_promo_min_price')
->where(array('not_in_promo_min_price', 'in_promo_min_price'), Criteria::LOGICAL_OR);
@@ -165,10 +171,15 @@ class Product extends BaseLoop
$max_price = $this->getMax_price();
if(null !== $max_price) {
$search->condition('in_promo', ProductPeer::PROMO . Criteria::EQUAL . '1')
->condition('not_in_promo', ProductPeer::PROMO . Criteria::NOT_EQUAL . '1')
->condition('max_price2', ProductPeer::PRICE2 . Criteria::LESS_EQUAL . '?', $max_price)
->condition('max_price', ProductPeer::PRICE . Criteria::LESS_EQUAL . '?', $max_price)
/**
* Following should work but does not :
*
* $search->filterBy('real_price', $max_price, Criteria::LESS_EQUAL);
*/
$search->condition('in_promo', ProductTableMap::PROMO . Criteria::EQUAL . '1')
->condition('not_in_promo', ProductTableMap::PROMO . Criteria::NOT_EQUAL . '1')
->condition('max_price2', ProductTableMap::PRICE2 . Criteria::LESS_EQUAL . '?', $max_price)
->condition('max_price', ProductTableMap::PRICE . Criteria::LESS_EQUAL . '?', $max_price)
->combine(array('in_promo', 'max_price2'), Criteria::LOGICAL_AND, 'in_promo_max_price')
->combine(array('not_in_promo', 'max_price'), Criteria::LOGICAL_AND, 'not_in_promo_max_price')
->where(array('not_in_promo_max_price', 'in_promo_max_price'), Criteria::LOGICAL_OR);
@@ -222,47 +233,58 @@ class Product extends BaseLoop
$search->filterByVisible($this->getVisible());
switch ($this->getOrder()) {
case "alpha":
$search->addAscendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
break;
case "alpha_reverse":
$search->addDescendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
break;
case "reverse":
$search->orderByPosition(Criteria::DESC);
break;
case "min_price":
//$search->order
//$search->orderByPosition(Criteria::DESC);
break;
/*case "max_price":
$search->orderByPosition(Criteria::DESC);
break;
case "category":
$search->orderByPosition(Criteria::DESC);
break;*/
case "manual":
$search->addAscendingOrderByColumn(\Thelia\Model\ProductPeer::POSITION);
break;
case "manual_reverse":
$search->addDescendingOrderByColumn(\Thelia\Model\ProductPeer::POSITION);
break;
case "ref":
$search->addAscendingOrderByColumn(\Thelia\Model\ProductPeer::REF);
break;
case "promo":
$search->addDescendingOrderByColumn(\Thelia\Model\ProductPeer::PROMO);
break;
case "new":
$search->addDescendingOrderByColumn(\Thelia\Model\ProductPeer::NEWNESS);
break;
default:
$search->orderByPosition();
break;
$orders = $this->getOrder();
if(null === $orders) {
$search->orderByPosition();
} else {
foreach($orders as $order) {
switch ($order) {
case "alpha":
$search->addAscendingOrderByColumn(\Thelia\Model\Map\CategoryI18nTableMap::TITLE);
$search->addAscendingOrderByColumn(\Thelia\Model\Map\CategoryI18nTableMap::TITLE);
break;
case "alpha_reverse":
$search->addDescendingOrderByColumn(\Thelia\Model\Map\CategoryI18nTableMap::TITLE);
break;
case "reverse":
$search->orderByPosition(Criteria::DESC);
break;
case "min_price":
$search->orderBy('real_price', Criteria::ASC);
break;
case "max_price":
$search->orderBy('real_price', Criteria::DESC);
break;
case "manual":
if(null === $this->category || count($this->category) != 1)
throw new \InvalidArgumentException('Manual order cannot be set without single category argument');
$search->addAscendingOrderByColumn(ProductTableMap::POSITION);
break;
case "manual_reverse":
if(null === $this->category || count($this->category) != 1)
throw new \InvalidArgumentException('Manual order cannot be set without single category argument');
$search->addDescendingOrderByColumn(ProductTableMap::POSITION);
break;
case "ref":
$search->addAscendingOrderByColumn(ProductTableMap::REF);
break;
case "promo":
$search->addDescendingOrderByColumn(ProductTableMap::PROMO);
break;
case "new":
$search->addDescendingOrderByColumn(ProductTableMap::NEWNESS);
break;
default:
$search->orderByPosition();
break;
}
}
}
if ($this->getRandom() === true) {
$random = $this->getRandom();
if ($random === true) {
$search->clearOrderByColumns();
$search->addAscendingOrderByColumn('RAND()');
}