Merge branch 'admin'

Conflicts:
	core/lib/Thelia/Admin/Controller/BaseAdminController.php
	core/lib/Thelia/Config/Resources/config.xml
	core/lib/Thelia/Core/Template/Element/BaseLoop.php
	core/lib/Thelia/Core/Template/Loop/Category.php
	core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php
	core/lib/Thelia/Model/Admin.php
	core/lib/Thelia/Model/Customer.php
This commit is contained in:
franck
2013-07-08 11:27:37 +02:00
62 changed files with 752 additions and 282 deletions

View File

@@ -0,0 +1,41 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace use Thelia\Core\Security\Role;
/**
* Role is a simple implementation of a RoleInterface where the role is a
* string.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Role implements RoleInterface
{
private $role;
/**
* Constructor.
*
* @param string $role The role name
*/
public function __construct($role)
{
$this->role = (string) $role;
}
/**
* {@inheritdoc}
*/
public function getRole()
{
return $this->role;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Thelia\Core\Security\Role;
/**
* RoleInterface represents a role granted to a user.
*
* A role must either have a string representation or it needs to be explicitly
* supported by at least one AccessDecisionManager.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface RoleInterface
{
/**
* Returns the role.
*
* This method returns a string representation whenever possible.
*
* When the role cannot be represented with sufficient precision by a
* string, it should return null.
*
* @return string|null A string representation of the role, or null
*/
public function getRole();
}

View File

@@ -30,6 +30,20 @@ interface UserInterface {
*/
public function getAlgo();
/**
* Returns the roles granted to the user.
*
* <code>
* public function getRoles()
* {
* return array('ROLE_USER');
* }
* </code>
*
* @return Role[] The user roles
*/
public function getRoles();
/**
* Removes sensitive data from the user.
*

View File

@@ -38,16 +38,14 @@ abstract class BaseLoop
/**
* @var \Symfony\Component\HttpFoundation\Request
*/
public $request;
protected $request;
/**
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
public $dispatcher;
protected $dispatcher;
public $limit;
public $page;
public $offset;
private $args;
protected function getDefaultArgs()
{
@@ -59,6 +57,8 @@ abstract class BaseLoop
}
/**
* Create a new Loop
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
*/
@@ -66,14 +66,94 @@ abstract class BaseLoop
{
$this->request = $request;
$this->dispatcher = $dispatcher;
$this->args = $this->getArgDefinitions()->addArguments($this->getDefaultArgs());
}
/**
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
* Initialize the loop arguments.
*
* @param array $nameValuePairs a array of name => value pairs. The name is the name of the argument.
*
* @throws \InvalidArgumentException if somùe argument values are missing, or invalid
*/
public function getArgs()
{
return $this->defineArgs()->addArguments($this->getDefaultArgs());
public function initializeArgs(array $nameValuePairs) {
$faultActor = array();
$faultDetails = array();
while (($argument = $this->args->current()) !== false) {
$value = isset($nameValuePairs[$argument->name]) ? $nameValuePairs[$argument->name] : null;
/* check if mandatory */
if($value === null && $argument->mandatory) {
$faultActor[] = $argument->name;
$faultDetails[] = sprintf('"%s" parameter is missing', $argument->name);
continue;
}
/* check if empty */
if($value === '' && !$argument->empty) {
$faultActor[] = $argument->name;
$faultDetails[] = sprintf('"%s" parameter cannot be empty', $argument->name);
continue;
}
/* check type */
if($value !== null && !$argument->type->isValid($value)) {
$faultActor[] = $argument->name;
$faultDetails[] = sprintf('Invalid value for "%s" argument', $argument->name);
continue;
}
/* set default */
/* did it as last checking for we consider default value is acceptable no matter type or empty restriction */
if($value === null) {
$value = $argument->default;
}
$argument->setValue($value);
$this->args->next();
}
if (!empty($faultActor)) {
$complement = sprintf('[%s]', implode(', ', $faultDetails));
throw new \InvalidArgumentException($complement);
}
}
/**
* Return a loop argument
*
* @param string $argumentName the argument name
*
* @throws \InvalidArgumentException if argument is not found in loop argument list
* @return Argument the loop argument.
*/
public function getArg($argumentName) {
$arg = $this->args->get($argumentName);
if ($arg === null)
throw new \InvalidArgumentException("Undefined loop argument '$argumentName'");
return $arg;
}
/**
* Return a loop argument value
*
* @param string $argumentName the argument name
*
* @throws \InvalidArgumentException if argument is not found in loop argument list
* @return Argument the loop argument.
*/
public function getArgValue($argumentName) {
return $this->getArg($argumentName)->getValue();
}
/**
@@ -84,7 +164,7 @@ abstract class BaseLoop
*/
public function search(ModelCriteria $search, &$pagination = null)
{
if($this->page !== null) {
if($this->getArgValue('page') !== null) {
return $this->searchWithPagination($search, $pagination);
} else {
return $this->searchWithOffset($search);
@@ -98,10 +178,10 @@ abstract class BaseLoop
*/
public function searchWithOffset(ModelCriteria $search)
{
if($this->limit >= 0) {
$search->limit($this->limit);
if($this->getArgValue('limit') >= 0) {
$search->limit($this->getArgValue('limit'));
}
$search->offset($this->offset);
$search->offset($this->getArgValue('offset'));
return $search->find();
}
@@ -114,9 +194,9 @@ abstract class BaseLoop
*/
public function searchWithPagination(ModelCriteria $search, &$pagination)
{
$pagination = $search->paginate($this->page, $this->limit);
$pagination = $search->paginate($this->getArgValue('page'), $this->getArgValue('limit'));
if($this->page > $pagination->getLastPage()) {
if($this->getArgValue('page') > $pagination->getLastPage()) {
return array();
} else {
return $pagination;
@@ -148,7 +228,8 @@ abstract class BaseLoop
* @param $pagination
*
* @return mixed
*/abstract public function exec(&$pagination);
*/
abstract public function exec(&$pagination);
/**
*
@@ -169,6 +250,6 @@ abstract class BaseLoop
*
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
*/
abstract protected function defineArgs();
abstract protected function getArgDefinitions();
}

View File

@@ -38,12 +38,25 @@ class Argument
public $mandatory;
public $empty;
public function __construct($name, \Thelia\Type\TypeCollection $type, $default = null, $mandatory = false, $empty = true)
private $value;
public function __construct($name, \Thelia\Type\TypeCollection $type, $default = null, $mandatory = false, $empty = true, $value = null)
{
$this->name = $name;
$this->type = $type;
$this->mandatory = $mandatory ? true : false;
$this->default = $default;
$this->empty = $empty;
$this->setValue($value);
}
public function getValue() {
return $this->value;
}
public function setValue($value) {
$this->value = $value;
}
public static function createAnyTypeArgument($name, $default=null, $mandatory=false, $empty=true)

View File

@@ -30,14 +30,21 @@ namespace Thelia\Core\Template\Loop\Argument;
class ArgumentCollection implements \Iterator
{
private $position;
protected $arguments = array();
private $arguments = array();
public function __construct()
{
$this->addArguments(func_get_args());
}
public function hasKey($key) {
return isset($this->arguments[$key]);
}
public function get($key) {
return $this->hasKey($key) ? $this->arguments[$key] : null;
}
public function isEmpty()
{
return count($this->arguments) == 0;
@@ -64,7 +71,8 @@ class ArgumentCollection implements \Iterator
*/
public function addArgument(Argument $argument)
{
$this->arguments[] = $argument;
$this->arguments[$argument->name] = $argument;
return $this;
}
@@ -81,7 +89,7 @@ class ArgumentCollection implements \Iterator
*/
public function current()
{
return $this->arguments[$this->position];
return current($this->arguments);
}
/**
@@ -92,7 +100,7 @@ class ArgumentCollection implements \Iterator
*/
public function next()
{
$this->position++;
next($this->arguments);
}
/**
@@ -103,7 +111,7 @@ class ArgumentCollection implements \Iterator
*/
public function key()
{
return $this->position;
return key($this->arguments);
}
/**
@@ -115,7 +123,7 @@ class ArgumentCollection implements \Iterator
*/
public function valid()
{
return isset($this->arguments[$this->position]);
return $this->key() !== null;
}
/**
@@ -126,6 +134,6 @@ class ArgumentCollection implements \Iterator
*/
public function rewind()
{
$this->position = 0;
reset($this->arguments);
}
}

View File

@@ -68,20 +68,10 @@ use Thelia\Type;
*/
class Category extends BaseLoop
{
public $id;
public $parent;
public $current;
public $not_empty;
public $visible;
public $link;
public $order;
public $random;
public $exclude;
/**
* @return ArgumentCollection
*/
protected function defineArgs()
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntListTypeArgument('id'),
@@ -110,31 +100,45 @@ class Category extends BaseLoop
{
$search = CategoryQuery::create();
if (!is_null($this->id)) {
$search->filterById($this->id, Criteria::IN);
$id = $this->getArgValue('id');
if (!is_null($id)) {
$search->filterById($id, Criteria::IN);
}
if (!is_null($this->parent)) {
$search->filterByParent($this->parent);
$parent = $this->getArgValue('parent');
if (!is_null($parent)) {
$search->filterByParent($parent);
}
if ($this->current === true) {
$current = $this->getArgValue('current');
if ($current === true) {
$search->filterById($this->request->get("category_id"));
} elseif ($this->current === false) {
} elseif ($current === false) {
$search->filterById($this->request->get("category_id"), Criteria::NOT_IN);
}
if (!is_null($this->exclude)) {
$search->filterById($this->exclude, Criteria::NOT_IN);
$exclude = $this->getArgValue('exclude');
if (!is_null($exclude)) {
$search->filterById($exclude, Criteria::NOT_IN);
}
if (!is_null($this->link)) {
$search->filterByLink($this->link);
$link = $this->getArgValue('link');
if (!is_null($link)) {
$search->filterByLink($link);
}
$search->filterByVisible($this->visible ? 1 : 0);
$search->filterByVisible($this->getArgValue('visible') ? 1 : 0);
switch ($this->order) {
switch ($this->getArgValue('order')) {
case "alpha":
$search->addAscendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
break;
@@ -149,7 +153,8 @@ class Category extends BaseLoop
break;
}
if ($this->random === true) {
if ($this->getArgValue('random') === true) {
$search->clearOrderByColumns();
$search->addAscendingOrderByColumn('RAND()');
}
@@ -161,7 +166,7 @@ class Category extends BaseLoop
*/
$search->joinWithI18n(
$this->request->getSession()->get('locale', 'en_US'),
$this->request->getSession()->getLocale(),
(ConfigQuery::read("default_lang_without_translation", 1)) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN
);
@@ -189,5 +194,4 @@ class Category extends BaseLoop
return $loopResult;
}
}
}

View File

@@ -0,0 +1,115 @@
<?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\Template\Loop;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Type\TypeCollection;
use Thelia\Type;
/**
*
* @package Thelia\Core\Template\Loop
*
* @author Franck Allimant <franck@cqfdev.fr>
*/
class Feed extends BaseLoop
{
public function getArgDefinitions()
{
return new ArgumentCollection(
new Argument(
'url',
new TypeCollection(new Type\AnyType())
),
new Argument(
'timeout',
new TypeCollection(
new Type\IntType()
),
10
)
);
}
/**
*
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
public function exec(&$pagination)
{
$cachedir = THELIA_ROOT . 'cache/feeds';
if (! is_dir($cachedir)) {
if (! mkdir($cachedir)) {
throw new \Exception(sprintf("Failed to create cache directory '%s'", $cachedir));
}
}
$feed = new \SimplePie($this->getArgValue('url'), THELIA_ROOT . 'cache/feeds');
$feed->init();
$feed->handle_content_type();
$feed->set_timeout($this->getArgValue('timeout'));
$items = $feed->get_items();
$limit = min(count($items), $this->getArgValue('limit'));
$loopResult = new LoopResult();
for($idx = 0; $idx < $limit; $idx++) {
$item = $items[$idx];
$link = $item->get_permalink();
$title = $item->get_title();
$author = $item->get_author();
$description = $item->get_description();
$date = $item->get_date('d/m/Y');
$loopResultRow = new LoopResultRow();
$loopResultRow->set("URL", $item->get_permalink());
$loopResultRow->set("TITLE", $item->get_title());
$loopResultRow->set("AUTHOR", $item->get_author());
$loopResultRow->set("DESCRIPTION", $item->get_description());
$loopResultRow->set("DATE", $item->get_date('d/m/Y')); // FIXME - date format should be an intl parameter
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
}

View File

@@ -52,24 +52,6 @@ use Thelia\Type;
*/
class Product extends BaseLoop
{
public $id;
public $ref;
public $category;
public $new;
public $promo;
public $min_price;
public $max_price;
public $min_stock;
public $min_weight;
public $max_weight;
public $current;
public $current_category;
public $depth;
public $visible;
public $order;
public $random;
public $exclude;
/**
* @return ArgumentCollection
*/
@@ -115,19 +97,27 @@ class Product extends BaseLoop
{
$search = ProductQuery::create();
if (!is_null($this->id)) {
$search->filterById($this->id, Criteria::IN);
$id = $this->getArgValue('id');
if (!is_null($id)) {
$search->filterById($id, Criteria::IN);
}
if (!is_null($this->ref)) {
$search->filterByRef($this->ref, Criteria::IN);
$ref = $this->getArgValue('ref');
if (!is_null($ref)) {
$search->filterByRef($ref, Criteria::IN);
}
if (!is_null($this->category)) {
$categories = CategoryQuery::create()->filterById($this->category, Criteria::IN)->find();
$category = $this->getArgValue('category');
if(null !== $this->depth) {
foreach(CategoryQuery::findAllChild($this->category, $this->depth) as $subCategory) {
if (!is_null($category)) {
$categories = CategoryQuery::create()->filterById($category, Criteria::IN)->find();
$depth = $this->getArgValue('depth');
if(null !== $depth) {
foreach(CategoryQuery::findAllChild($category, $depth) as $subCategory) {
$categories->prepend($subCategory);
}
}
@@ -138,57 +128,75 @@ class Product extends BaseLoop
);
}
if ($this->new === true) {
$new = $this->getArgValue('new');
if ($new === true) {
$search->filterByNewness(1, Criteria::EQUAL);
} else if($this->new === false) {
} else if($new === false) {
$search->filterByNewness(0, Criteria::EQUAL);
}
if ($this->promo === true) {
$promo = $this->getArgValue('promo');
if ($promo === true) {
$search->filterByPromo(1, Criteria::EQUAL);
} else if($this->promo === false) {
} else if($promo === false) {
$search->filterByNewness(0, Criteria::EQUAL);
}
if (null != $this->min_stock) {
$search->filterByQuantity($this->min_stock, Criteria::GREATER_EQUAL);
$min_stock = $this->getArgValue('min_stock');
if (null != $min_stock) {
$search->filterByQuantity($min_stock, Criteria::GREATER_EQUAL);
}
if(null !== $this->min_price) {
$min_price = $this->getArgValue('min_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 . '?', $this->min_price)
->condition('min_price', ProductPeer::PRICE . Criteria::GREATER_EQUAL . '?', $this->min_price)
->condition('min_price2', ProductPeer::PRICE2 . Criteria::GREATER_EQUAL . '?', $min_price)
->condition('min_price', ProductPeer::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);
}
if(null !== $this->max_price) {
$max_price = $this->getArgValue('max_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 . '?', $this->max_price)
->condition('max_price', ProductPeer::PRICE . Criteria::LESS_EQUAL . '?', $this->max_price)
->condition('max_price2', ProductPeer::PRICE2 . Criteria::LESS_EQUAL . '?', $max_price)
->condition('max_price', ProductPeer::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);
}
if(null !== $this->min_weight) {
$search->filterByWeight($this->min_weight, Criteria::GREATER_EQUAL);
$min_weight = $this->getArgValue('min_weight');
if(null !== $min_weight) {
$search->filterByWeight($min_weight, Criteria::GREATER_EQUAL);
}
if(null !== $this->max_weight) {
$search->filterByWeight($this->max_weight, Criteria::LESS_EQUAL);
$max_weight = $this->getArgValue('max_weight');
if(null !== $max_weight) {
$search->filterByWeight($max_weight, Criteria::LESS_EQUAL);
}
if ($this->current === true) {
$current = $this->getArgValue('current');
if ($current === true) {
$search->filterById($this->request->get("product_id"));
} elseif($this->current === false) {
} elseif($current === false) {
$search->filterById($this->request->get("product_id"), Criteria::NOT_IN);
}
if ($this->current_category === true) {
$current_category = $this->getArgValue('current_category');
if ($current_category === true) {
$search->filterByCategory(
CategoryQuery::create()->filterByProduct(
ProductCategoryQuery::create()->filterByProductId(
@@ -199,7 +207,7 @@ class Product extends BaseLoop
)->find(),
Criteria::IN
);
} elseif($this->current_category === false) {
} elseif($current_category === false) {
$search->filterByCategory(
CategoryQuery::create()->filterByProduct(
ProductCategoryQuery::create()->filterByProductId(
@@ -212,9 +220,9 @@ class Product extends BaseLoop
);
}
$search->filterByVisible($this->visible);
$search->filterByVisible($this->getArgValue('visible'));
switch ($this->order) {
switch ($this->getArgValue('order')) {
case "alpha":
$search->addAscendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
break;
@@ -254,13 +262,15 @@ class Product extends BaseLoop
break;
}
if ($this->random === true) {
if ($this->getArgValue('random') === true) {
$search->clearOrderByColumns();
$search->addAscendingOrderByColumn('RAND()');
}
if (!is_null($this->exclude)) {
$search->filterById($this->exclude, Criteria::NOT_IN);
$exclude = $this->getArgValue('exclude');
if (!is_null($exclude)) {
$search->filterById($exclude, Criteria::NOT_IN);
}
/**
@@ -270,7 +280,7 @@ class Product extends BaseLoop
*/
$search->joinWithI18n(
$this->request->getSession()->get('locale', 'en_US'),
$this->request->getSession()->getLocale(),
(ConfigQuery::read("default_lang_without_translation", 1)) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN
);

View File

@@ -35,7 +35,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class TheliaLoop implements SmartyPluginInterface
{
protected static $pagination = null;
protected $pagination = null;
protected $loopDefinition = array();
@@ -43,8 +43,9 @@ class TheliaLoop implements SmartyPluginInterface
protected $dispatcher;
protected $loopstack = array();
protected $varstack = array();
protected $loopstack = array();
public function __construct(Request $request, EventDispatcherInterface $dispatcher)
{
@@ -57,13 +58,13 @@ class TheliaLoop implements SmartyPluginInterface
*
* @return \PropelModelPager
*/
public static function getPagination($loopId)
protected function getPagination($loopId)
{
if(!empty(self::$pagination[$loopId])) {
return self::$pagination[$loopId];
} else {
return null;
}
if(!empty($this->pagination[$loopId])) {
return $this->pagination[$loopId];
} else {
return null;
}
}
/**
@@ -92,13 +93,12 @@ class TheliaLoop implements SmartyPluginInterface
throw new \InvalidArgumentException("A loop named '$name' already exists in the current scope.");
}
$loop = $this->createLoopInstance(strtolower($params['type']));
$loop = $this->createLoopInstance($params);
$this->getLoopArgument($loop, $params);
$this->pagination[$name] = null;
self::$pagination[$name] = null;
$loopResults = $loop->exec($this->pagination[$name]);
$loopResults = $loop->exec(self::$pagination[$name]);
$this->loopstack[$name] = $loopResults;
} else {
@@ -130,12 +130,12 @@ class TheliaLoop implements SmartyPluginInterface
$template->assign($var, $val);
}
$repeat = true;
}
// Assign meta information
$template->assign('LOOP_COUNT', 1 + $loopResults->key());
$template->assign('LOOP_TOTAL', $loopResults->getCount());
// Assign meta information
$template->assign('LOOP_COUNT', 1 + $loopResults->key());
$template->assign('LOOP_TOTAL', $loopResults->getCount());
$repeat = $loopResults->valid();
}
// Loop is terminated. Cleanup.
if (! $repeat) {
@@ -187,6 +187,7 @@ class TheliaLoop implements SmartyPluginInterface
*/
public function theliaIfLoop($params, $content, $template, &$repeat)
{
// When encountering close tag, check if loop has results.
if ($repeat === false) {
return $this->checkEmptyLoop($params, $template) ? '' : $content;
@@ -206,41 +207,43 @@ class TheliaLoop implements SmartyPluginInterface
*/
public function theliaPageLoop($params, $content, $template, &$repeat)
{
if (empty($params['rel']))
throw new \InvalidArgumentException("Missing 'rel' parameter in page loop");
if (empty($params['rel']))
throw new \InvalidArgumentException("Missing 'rel' parameter in page loop");
$loopName = $params['rel'];
$loopName = $params['rel'];
// Find loop results in the current template vars
/* $loopResults = $template->getTemplateVars($loopName);
if (empty($loopResults)) {
throw new \InvalidArgumentException("Loop $loopName is not defined.");
}*/
// Find loop results in the current template vars
if (! isset($this->loopstack[$loopName])) {
throw new \InvalidArgumentException("Loop $loopName is not defined.");
}
// Find pagination
$pagination = self::getPagination($loopName);
if ($pagination === null) {
throw new \InvalidArgumentException("Loop $loopName : no pagination found.");
}
$loopResults = $this->loopstack[$loopName];
if ($content === null) {
$page = 1;
} else {
$page = $template->getTemplateVars('PAGE');
$page++;
}
// Find pagination
$pagination = $this->getPagination($loopName);
if ($page <= $pagination->getLastPage()) {
$template->assign('PAGE', $page);
$template->assign('CURRENT', $pagination->getPage());
$template->assign('LAST', $pagination->getLastPage());
if ($pagination === null) {
throw new \InvalidArgumentException("Loop $loopName : no pagination found.");
}
$repeat = true;
}
if ($content === null) {
$page = 1;
} else {
$page = $template->getTemplateVars('PAGE');
$page++;
}
if ($content !== null) {
return $content;
}
if ($page <= $pagination->getLastPage()) {
$template->assign('PAGE', $page);
$template->assign('CURRENT', $pagination->getPage());
$template->assign('LAST', $pagination->getLastPage());
$repeat = true;
}
if ($content !== null) {
return $content;
}
}
/**
@@ -272,27 +275,33 @@ class TheliaLoop implements SmartyPluginInterface
*
* @param string $name
* @return \Thelia\Core\Template\Element\BaseLoop
* @throws InvalidElementException
* @throws ElementNotFoundException
* @throws \Thelia\Tpex\Exception\InvalidElementException
* @throws \Thelia\Tpex\Exception\ElementNotFoundException
*/
protected function createLoopInstance($name)
protected function createLoopInstance($smartyParams)
{
if (! isset($this->loopDefinition[$name])) {
throw new ElementNotFoundException(sprintf("%s loop does not exists", $name));
$type = strtolower($smartyParams['type']);
if (! isset($this->loopDefinition[$type])) {
throw new ElementNotFoundException(sprintf("%s loop does not exists", $type));
}
$class = new \ReflectionClass($this->loopDefinition[$name]);
$class = new \ReflectionClass($this->loopDefinition[$type]);
if ($class->isSubclassOf("Thelia\Core\Template\Element\BaseLoop") === false) {
throw new InvalidElementException(sprintf("%s Loop class have to extends Thelia\Core\Template\Element\BaseLoop",
$name));
$type));
}
return $class->newInstance(
$loop = $class->newInstance(
$this->request,
$this->dispatcher
);
$loop->initializeArgs($smartyParams);
return $loop;
}
/**
@@ -304,10 +313,11 @@ class TheliaLoop implements SmartyPluginInterface
*/
protected function getLoopArgument(BaseLoop $loop, $smartyParam)
{
$faultActor = array();
$faultDetails = array();
$faultActor = array();
$faultDetails = array();
$argumentsCollection = $loop->getArgs();
foreach( $argumentsCollection as $argument ) {
$value = isset($smartyParam[$argument->name]) ? (string)$smartyParam[$argument->name] : null;
@@ -364,7 +374,7 @@ class TheliaLoop implements SmartyPluginInterface
* "myLoop" => "My\Own\Loop"
* );
*
* @param array $loopDefinition
* @param array $loops
* @throws \InvalidArgumentException if loop name already exists
*/
public function setLoopList(array $loopDefinition)