From ec3ab5c3aa4a288bca6c357bbb2a3355966d970c Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Thu, 22 Aug 2013 17:47:46 +0200 Subject: [PATCH] currency loop --- .../lib/Thelia/Core/Template/Loop/Country.php | 1 - .../Thelia/Core/Template/Loop/Currency.php | 112 ++++++++++++++++++ .../Tests/Core/Template/Loop/CurrencyTest.php | 51 ++++++++ 3 files changed, 163 insertions(+), 1 deletion(-) create mode 100755 core/lib/Thelia/Core/Template/Loop/Currency.php create mode 100755 core/lib/Thelia/Tests/Core/Template/Loop/CurrencyTest.php diff --git a/core/lib/Thelia/Core/Template/Loop/Country.php b/core/lib/Thelia/Core/Template/Loop/Country.php index 73e1fd410..d25951fb8 100755 --- a/core/lib/Thelia/Core/Template/Loop/Country.php +++ b/core/lib/Thelia/Core/Template/Loop/Country.php @@ -53,7 +53,6 @@ class Country extends BaseLoop protected function getArgDefinitions() { return new ArgumentCollection( - Argument::createIntTypeArgument('limit', 500), // overwrite orginal param to increase the limit Argument::createIntListTypeArgument('id'), Argument::createIntListTypeArgument('area'), Argument::createBooleanTypeArgument('with_area'), diff --git a/core/lib/Thelia/Core/Template/Loop/Currency.php b/core/lib/Thelia/Core/Template/Loop/Currency.php new file mode 100755 index 000000000..08eacca08 --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/Currency.php @@ -0,0 +1,112 @@ +. */ +/* */ +/*************************************************************************************/ + +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; + +use Thelia\Core\Template\Loop\Argument\ArgumentCollection; +use Thelia\Core\Template\Loop\Argument\Argument; + +use Thelia\Model\Tools\ModelCriteriaTools; + +use Thelia\Model\CurrencyQuery; +use Thelia\Model\ConfigQuery; + +/** + * + * Currency loop + * + * + * Class Currency + * @package Thelia\Core\Template\Loop + * @author Etienne Roudeix + */ +class Currency extends BaseLoop +{ + /** + * @return ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createIntListTypeArgument('id'), + Argument::createIntListTypeArgument('exclude'), + Argument::createBooleanTypeArgument('default_only', false) + ); + } + + /** + * @param $pagination + * + * @return \Thelia\Core\Template\Element\LoopResult + */ + public function exec(&$pagination) + { + $search = CurrencyQuery::create(); + + /* manage translations */ + ModelCriteriaTools::getI18n($search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale(), array('NAME')); + + $id = $this->getId(); + + if (null !== $id) { + $search->filterById($id, Criteria::IN); + } + + $exclude = $this->getExclude(); + + if (!is_null($exclude)) { + $search->filterById($exclude, Criteria::NOT_IN); + } + + $default_only = $this->getDefaultOnly(); + + if ($default_only === true) { + $search->filterByByDefault(true); + } + + $search->orderByPosition(); + + /* perform search */ + $currencies = $this->search($search, $pagination); + + $loopResult = new LoopResult(); + + foreach ($currencies as $currency) { + $loopResultRow = new LoopResultRow(); + $loopResultRow->set("ID", $currency->getId()) + ->set("NAME",$currency->getVirtualColumn('i18n_NAME')) + ->set("ISOCODE", $currency->getCode()) + ->set("RATE", $currency->getRate()) + ->set("IS_DEFAULT", $currency->getByDefault()); + + $loopResult->addRow($loopResultRow); + } + + return $loopResult; + } +} diff --git a/core/lib/Thelia/Tests/Core/Template/Loop/CurrencyTest.php b/core/lib/Thelia/Tests/Core/Template/Loop/CurrencyTest.php new file mode 100755 index 000000000..95dd5a5c6 --- /dev/null +++ b/core/lib/Thelia/Tests/Core/Template/Loop/CurrencyTest.php @@ -0,0 +1,51 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Core\Template\Loop; + +use Thelia\Tests\Core\Template\Element\BaseLoopTestor; + +use Thelia\Core\Template\Loop\Currency; + +/** + * + * @author Etienne Roudeix + * + */ +class CurrencyTest extends BaseLoopTestor +{ + public function getTestedClassName() + { + return 'Thelia\Core\Template\Loop\Currency'; + } + + public function getTestedInstance() + { + return new Currency($this->request, $this->dispatcher, $this->securityContext); + } + + public function getMandatoryArguments() + { + return array(); + } +}