diff --git a/core/lib/Thelia/Core/Template/Element/BaseLoop.php b/core/lib/Thelia/Core/Template/Element/BaseLoop.php index 821055204..adc406d7a 100755 --- a/core/lib/Thelia/Core/Template/Element/BaseLoop.php +++ b/core/lib/Thelia/Core/Template/Element/BaseLoop.php @@ -45,11 +45,16 @@ abstract class BaseLoop */ public $dispatcher; + public $limit; + public $page; + public $offset; + protected function getDefaultArgs() { return array( - Argument::createIntTypeArgument('offset'), - Argument::createIntTypeArgument('limit'), + Argument::createIntTypeArgument('offset', 0), + Argument::createIntTypeArgument('page'), + Argument::createIntTypeArgument('limit', 10), ); } @@ -68,6 +73,30 @@ abstract class BaseLoop return $this->defineArgs()->addArguments($this->getDefaultArgs()); } + public function search(\ModelCriteria $search) + { + if($this->page !== null) { + return $this->searchWithPagination($search); + } else { + return $this->searchWithOffset($search); + } + } + + public function searchWithOffset(\ModelCriteria $search) + { + if($this->limit >= 0) { + $search->limit($this->limit); + } + $search->offset($this->offset); + + return $search->find(); + } + + public function searchWithPagination(\ModelCriteria $search) + { + return $search->paginate($this->page, $this->limit); + } + /** * * this function have to be implement in your own loop class. diff --git a/core/lib/Thelia/Core/Template/Loop/Category.php b/core/lib/Thelia/Core/Template/Loop/Category.php index 0af81e563..2a47ac835 100755 --- a/core/lib/Thelia/Core/Template/Loop/Category.php +++ b/core/lib/Thelia/Core/Template/Loop/Category.php @@ -51,8 +51,6 @@ use Thelia\Type; * * by default results are sorting by position ascending * - random : if 1, random results. Default value is 0 * - exclude : all category id you want to exclude (as for id, an integer or a "string list" can be used) - * - limit : number of results. Default value is 10 - * - offset : at witch id start the search * * example : * @@ -76,8 +74,6 @@ class Category extends BaseLoop { public $order; public $random; public $exclude; - public $limit; - public $offset; protected function defineArgs() { @@ -130,11 +126,7 @@ class Category extends BaseLoop { $search->filterByLink($this->link); } - /*if($this->limit > -1) { - $search->limit($this->limit); - }*/ $search->filterByVisible($this->visible); - //$search->offset($this->offset); switch($this->order) { @@ -164,8 +156,7 @@ class Category extends BaseLoop { */ $search->joinWithI18n($this->request->getSession()->get('locale', 'en_US'), \Criteria::INNER_JOIN); - //$categories = $search->find(); - $categories = $search->paginate($page = 2, $maxPerPage = 2); + $categories = $this->search($search); $loopResult = new LoopResult(); diff --git a/templates/smarty-sample/index.html b/templates/smarty-sample/index.html index 9135b8867..c9d4e6842 100755 --- a/templates/smarty-sample/index.html +++ b/templates/smarty-sample/index.html @@ -84,4 +84,20 @@ An image from asset directory : {/loop} +
+

Some pagination

+

PAGE 1

+ +

PAGE 2

+ +
+ {include file="includes/footer.html"} \ No newline at end of file