changes tests
create argument helpers start loop auto pagination
This commit is contained in:
@@ -26,6 +26,7 @@ namespace Thelia\Core\Template\Element;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -44,6 +45,14 @@ abstract class BaseLoop
|
||||
*/
|
||||
public $dispatcher;
|
||||
|
||||
protected function getDefaultArgs()
|
||||
{
|
||||
return array(
|
||||
Argument::createIntTypeArgument('offset'),
|
||||
Argument::createIntTypeArgument('limit'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
|
||||
@@ -54,6 +63,11 @@ abstract class BaseLoop
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
public function getArgs()
|
||||
{
|
||||
return $this->defineArgs()->addArguments($this->getDefaultArgs());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* this function have to be implement in your own loop class.
|
||||
@@ -99,6 +113,6 @@ abstract class BaseLoop
|
||||
*
|
||||
* @return ArgumentCollection
|
||||
*/
|
||||
abstract public function defineArgs();
|
||||
abstract protected function defineArgs();
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Core\Template\Loop\Argument;
|
||||
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
@@ -42,4 +45,43 @@ class Argument
|
||||
$this->mandatory = $mandatory ? true : false;
|
||||
$this->default = $default;
|
||||
}
|
||||
|
||||
public static function createAnyTypeArgument($name, $default=null, $mandatory=false, $empty=true)
|
||||
{
|
||||
return new Argument(
|
||||
$name,
|
||||
new TypeCollection(
|
||||
new Type\AnyType()
|
||||
),
|
||||
$default,
|
||||
$mandatory,
|
||||
$empty
|
||||
);
|
||||
}
|
||||
|
||||
public static function createIntTypeArgument($name, $default=null, $mandatory=false, $empty=true)
|
||||
{
|
||||
return new Argument(
|
||||
$name,
|
||||
new TypeCollection(
|
||||
new Type\IntType()
|
||||
),
|
||||
$default,
|
||||
$mandatory,
|
||||
$empty
|
||||
);
|
||||
}
|
||||
|
||||
public static function createIntListTypeArgument($name, $default=null, $mandatory=false, $empty=true)
|
||||
{
|
||||
return new Argument(
|
||||
$name,
|
||||
new TypeCollection(
|
||||
new Type\IntListType()
|
||||
),
|
||||
$default,
|
||||
$mandatory,
|
||||
$empty
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,9 +35,7 @@ class ArgumentCollection implements \Iterator
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
foreach(func_get_args() as $argument) {
|
||||
$this->addArgument($argument);
|
||||
}
|
||||
$this->addArguments(func_get_args());
|
||||
}
|
||||
|
||||
public function isEmpty()
|
||||
@@ -45,6 +43,20 @@ class ArgumentCollection implements \Iterator
|
||||
return count($this->arguments) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $argumentList
|
||||
*
|
||||
* @return ArgumentCollection
|
||||
*/
|
||||
public function addArguments(array $argumentList)
|
||||
{
|
||||
foreach($argumentList as $argument) {
|
||||
$this->addArgument($argument);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Argument $argument
|
||||
*
|
||||
|
||||
@@ -79,80 +79,23 @@ class Category extends BaseLoop {
|
||||
public $limit;
|
||||
public $offset;
|
||||
|
||||
public function defineArgs()
|
||||
protected function defineArgs()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
new Argument(
|
||||
'id',
|
||||
new TypeCollection(
|
||||
new Type\IntListType()
|
||||
)
|
||||
),
|
||||
new Argument(
|
||||
'parent',
|
||||
new TypeCollection(
|
||||
new Type\IntType()
|
||||
)
|
||||
),
|
||||
new Argument(
|
||||
'current',
|
||||
new TypeCollection(
|
||||
new Type\IntType()
|
||||
)
|
||||
),
|
||||
new Argument(
|
||||
'not_empty',
|
||||
new TypeCollection(
|
||||
new Type\IntType()
|
||||
),
|
||||
0
|
||||
),
|
||||
new Argument(
|
||||
'visible',
|
||||
new TypeCollection(
|
||||
new Type\IntType()
|
||||
),
|
||||
1
|
||||
),
|
||||
new Argument(
|
||||
'link',
|
||||
new TypeCollection(
|
||||
new Type\AnyType()
|
||||
)
|
||||
),
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createIntTypeArgument('parent'),
|
||||
Argument::createIntTypeArgument('current'),
|
||||
Argument::createIntTypeArgument('not_empty', 0),
|
||||
Argument::createIntTypeArgument('visible', 1),
|
||||
Argument::createAnyTypeArgument('link'),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
new Type\EnumType('alpha', 'alpha_reverse', 'reverse')
|
||||
)
|
||||
),
|
||||
new Argument(
|
||||
'random',
|
||||
new TypeCollection(
|
||||
new Type\AnyType()
|
||||
),
|
||||
0
|
||||
),
|
||||
new Argument(
|
||||
'exclude',
|
||||
new TypeCollection(
|
||||
new Type\IntListType()
|
||||
)
|
||||
),
|
||||
new Argument(
|
||||
'limit',
|
||||
new TypeCollection(
|
||||
new Type\IntType()
|
||||
),
|
||||
10
|
||||
),
|
||||
new Argument(
|
||||
'offset',
|
||||
new TypeCollection(
|
||||
new Type\IntType()
|
||||
),
|
||||
0
|
||||
)
|
||||
Argument::createIntTypeArgument('random', 0),
|
||||
Argument::createIntListTypeArgument('exclude')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -187,11 +130,11 @@ class Category extends BaseLoop {
|
||||
$search->filterByLink($this->link);
|
||||
}
|
||||
|
||||
if($this->limit > -1) {
|
||||
/*if($this->limit > -1) {
|
||||
$search->limit($this->limit);
|
||||
}
|
||||
}*/
|
||||
$search->filterByVisible($this->visible);
|
||||
$search->offset($this->offset);
|
||||
//$search->offset($this->offset);
|
||||
|
||||
|
||||
switch($this->order) {
|
||||
@@ -221,7 +164,8 @@ class Category extends BaseLoop {
|
||||
*/
|
||||
$search->joinWithI18n($this->request->getSession()->get('locale', 'en_US'), \Criteria::INNER_JOIN);
|
||||
|
||||
$categories = $search->find();
|
||||
//$categories = $search->find();
|
||||
$categories = $search->paginate($page = 2, $maxPerPage = 2);
|
||||
|
||||
$loopResult = new LoopResult();
|
||||
|
||||
|
||||
@@ -177,8 +177,8 @@ class TheliaLoop implements SmartyPluginInterface
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Thelia\Core\Template\Element\BaseLoop
|
||||
* @throws \Thelia\Tpex\Exception\InvalidElementException
|
||||
* @throws \Thelia\Tpex\Exception\ElementNotFoundException
|
||||
* @throws InvalidElementException
|
||||
* @throws ElementNotFoundException
|
||||
*/
|
||||
protected function createLoopInstance($name)
|
||||
{
|
||||
@@ -204,8 +204,8 @@ class TheliaLoop implements SmartyPluginInterface
|
||||
/**
|
||||
* Returns the value of a loop argument.
|
||||
*
|
||||
* @param unknown $loop a BaseLoop instance
|
||||
* @param unknown $smartyParam
|
||||
* @param BaseLoop $loop a BaseLoop instance
|
||||
* @param $smartyParam
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function getLoopArgument(BaseLoop $loop, $smartyParam)
|
||||
@@ -218,7 +218,7 @@ class TheliaLoop implements SmartyPluginInterface
|
||||
$faultActor = array();
|
||||
$faultDetails = array();
|
||||
|
||||
$argumentsCollection = $loop->defineArgs();
|
||||
$argumentsCollection = $loop->getArgs();
|
||||
foreach( $argumentsCollection as $argument ) {
|
||||
|
||||
$value = isset($smartyParam[$argument->name]) ? $smartyParam[$argument->name] : null;
|
||||
@@ -275,7 +275,7 @@ class TheliaLoop implements SmartyPluginInterface
|
||||
* "myLoop" => "My\Own\Loop"
|
||||
* );
|
||||
*
|
||||
* @param array $loops
|
||||
* @param array $loopDefinition
|
||||
* @throws \InvalidArgumentException if loop name already exists
|
||||
*/
|
||||
public function setLoopList(array $loopDefinition)
|
||||
|
||||
Reference in New Issue
Block a user