From c0f5002db966dd654f8ab775d13a60decc212fa3 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 23 Jan 2014 17:13:48 +0100 Subject: [PATCH] create a dedicated method for count loop function --- .../Thelia/Core/Template/Element/BaseLoop.php | 22 +++++++++++++++++++ .../Template/Smarty/Plugins/TheliaLoop.php | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/core/lib/Thelia/Core/Template/Element/BaseLoop.php b/core/lib/Thelia/Core/Template/Element/BaseLoop.php index bbeb57e45..80220474b 100644 --- a/core/lib/Thelia/Core/Template/Element/BaseLoop.php +++ b/core/lib/Thelia/Core/Template/Element/BaseLoop.php @@ -333,6 +333,28 @@ abstract class BaseLoop } } + public function count() + { + $count = 0; + if ($this instanceof PropelSearchLoopInterface) { + $searchModelCriteria = $this->buildModelCriteria(); + if (null === $searchModelCriteria) { + $count = 0; + } else { + $count = $searchModelCriteria->count(); + } + } elseif ($this instanceof ArraySearchLoopInterface) { + $searchArray = $this->buildArray(); + if (null === $searchArray) { + $count = 0; + } else { + $count = count($searchArray); + } + } + + return $count; + } + /** * @param $pagination * @return LoopResult diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php index 64bce76d3..1b75f2096 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php @@ -91,7 +91,7 @@ class TheliaLoop extends AbstractSmartyPlugin $dummy = null; - return $loop->exec($dummy, true); + return $loop->count(); } /**