From 92d15d44c7d056d448531a0d07b3e74950d56ecc Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Wed, 3 Jul 2013 10:52:24 +0200 Subject: [PATCH] new types --- .../lib/Thelia/Core/Template/Loop/Product.php | 6 +++ .../Tests/Type/AlphaNumStringListTypeTest.php | 48 +++++++++++++++++ .../Tests/Type/AlphaNumStringTypeTest.php | 43 +++++++++++++++ .../lib/Thelia/Tests/Type/IntListTypeTest.php | 2 +- .../Thelia/Type/AlphaNumStringListType.php | 52 +++++++++++++++++++ core/lib/Thelia/Type/AlphaNumStringType.php | 47 +++++++++++++++++ templates/smarty-sample/category.html | 48 ++++++----------- 7 files changed, 214 insertions(+), 32 deletions(-) create mode 100755 core/lib/Thelia/Tests/Type/AlphaNumStringListTypeTest.php create mode 100755 core/lib/Thelia/Tests/Type/AlphaNumStringTypeTest.php create mode 100755 core/lib/Thelia/Type/AlphaNumStringListType.php create mode 100755 core/lib/Thelia/Type/AlphaNumStringType.php diff --git a/core/lib/Thelia/Core/Template/Loop/Product.php b/core/lib/Thelia/Core/Template/Loop/Product.php index 38d6d9b75..c4447d4c6 100755 --- a/core/lib/Thelia/Core/Template/Loop/Product.php +++ b/core/lib/Thelia/Core/Template/Loop/Product.php @@ -95,6 +95,7 @@ class Product extends BaseLoop new Argument( 'ref', new TypeCollection( + new Type\AlphaNumStringType(), new Type\JsonType() ) ), @@ -139,6 +140,11 @@ class Product extends BaseLoop } if (!is_null($this->category)) { + + if(null !== $this->depth) { + + } + $search->filterByCategory( CategoryQuery::create()->filterById($this->category, \Criteria::IN)->find(), \Criteria::IN diff --git a/core/lib/Thelia/Tests/Type/AlphaNumStringListTypeTest.php b/core/lib/Thelia/Tests/Type/AlphaNumStringListTypeTest.php new file mode 100755 index 000000000..22d1c52ce --- /dev/null +++ b/core/lib/Thelia/Tests/Type/AlphaNumStringListTypeTest.php @@ -0,0 +1,48 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Type; + +use Thelia\Type\AlphaNumStringListType; + +/** + * + * @author Etienne Roudeix + * + */ +class AlphaNumStringListTypeTest extends \PHPUnit_Framework_TestCase +{ + public function testAlphaNumStringListType() + { + $type = new AlphaNumStringListType(); + $this->assertTrue($type->isValid('FOO1,FOO_2,FOO-3')); + $this->assertFalse($type->isValid('FOO.1,FOO$_2,FOO-3')); + } + + public function testFormatAlphaNumStringListType() + { + $type = new AlphaNumStringListType(); + $this->assertTrue(is_array($type->getFormatedValue('FOO1,FOO_2,FOO-3'))); + $this->assertNull($type->getFormatedValue('5€')); + } +} diff --git a/core/lib/Thelia/Tests/Type/AlphaNumStringTypeTest.php b/core/lib/Thelia/Tests/Type/AlphaNumStringTypeTest.php new file mode 100755 index 000000000..46526715b --- /dev/null +++ b/core/lib/Thelia/Tests/Type/AlphaNumStringTypeTest.php @@ -0,0 +1,43 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Type; + +use Thelia\Type\AlphaNumStringType; + +/** + * + * @author Etienne Roudeix + * + */ +class AlphaNumStringTypeTest extends \PHPUnit_Framework_TestCase +{ + public function testAlphaNumStringType() + { + $type = new AlphaNumStringType(); + $this->assertTrue($type->isValid('azs_qs-0-9ds')); + $this->assertFalse($type->isValid('3.3')); + $this->assertFalse($type->isValid('3 3')); + $this->assertFalse($type->isValid('3€3')); + } +} diff --git a/core/lib/Thelia/Tests/Type/IntListTypeTest.php b/core/lib/Thelia/Tests/Type/IntListTypeTest.php index bbe410bd1..6f9cc1e99 100755 --- a/core/lib/Thelia/Tests/Type/IntListTypeTest.php +++ b/core/lib/Thelia/Tests/Type/IntListTypeTest.php @@ -40,7 +40,7 @@ class IntListTypeTest extends \PHPUnit_Framework_TestCase $this->assertFalse($intListType->isValid('1,2,3.3')); } - public function testFormatJsonType() + public function testFormatIntListType() { $intListType = new IntListType(); $this->assertTrue(is_array($intListType->getFormatedValue('1,2,3'))); diff --git a/core/lib/Thelia/Type/AlphaNumStringListType.php b/core/lib/Thelia/Type/AlphaNumStringListType.php new file mode 100755 index 000000000..1fa210cba --- /dev/null +++ b/core/lib/Thelia/Type/AlphaNumStringListType.php @@ -0,0 +1,52 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Type; + +/** + * + * @author Etienne Roudeix + * + */ + +class AlphaNumStringListType implements TypeInterface +{ + public function getType() + { + return 'Alphanumeric string list type'; + } + + public function isValid($values) + { + foreach(explode(',', $values) as $value) { + if(!preg_match('#^[a-zA-Z0-9\-_]+$#', $value)) + return false; + } + + return true; + } + + public function getFormatedValue($values) + { + return $this->isValid($values) ? explode(',', $values) : null; + } +} diff --git a/core/lib/Thelia/Type/AlphaNumStringType.php b/core/lib/Thelia/Type/AlphaNumStringType.php new file mode 100755 index 000000000..b893f8a46 --- /dev/null +++ b/core/lib/Thelia/Type/AlphaNumStringType.php @@ -0,0 +1,47 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Type; + +/** + * + * @author Etienne Roudeix + * + */ + +class AlphaNumStringType implements TypeInterface +{ + public function getType() + { + return 'Alphanumeric string type'; + } + + public function isValid($value) + { + return preg_match('#^[a-zA-Z0-9\-_]+$#', $value) ? true : false; + } + + public function getFormatedValue($value) + { + return $this->isValid($value) ? $value : null; + } +} diff --git a/templates/smarty-sample/category.html b/templates/smarty-sample/category.html index 14c4757d6..0055dee99 100755 --- a/templates/smarty-sample/category.html +++ b/templates/smarty-sample/category.html @@ -1,39 +1,25 @@ -{include file="included.html"} - {loop name="category0" type="category" parent="0"} -

Out before - CATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)

+

CATEGORY : #TITLE

{loop name="category1" type="category" parent="#ID"} -

Inner - SUBCATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)

+
+

SUBCATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)

+ {loop name="product" type="product" category="#ID"} +

PRODUCT : #REF / #TITLE

+ #PRICE € + {/loop} +
+
{/loop} - {#myid=#ID} - - {loop name="category2" type="category" parent="#ID"} -

Inner 2 before - SUBCATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)

- - {loop name="category3" type="category" parent="#myid"} -

Inner inner 2 - SUBCATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)

- {/loop} - -

Inner 2 after - SUBCATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)

+ {loop name="product" type="product" category="#ID"} +

PRODUCT : #REF / #TITLE

+ #PRICE € {/loop} - -

Out after - CATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)


- - {ifloop rel="category2"} -

Hey, y'a d'la categorie 2 !

- {/ifloop} - - {elseloop rel="category2"} -

Hey, y'a PAS de categorie 2 !

- {/elseloop} - - {loop name="category2" type="category" parent="#myid"} -

Exter 2 - SUBCATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)

- {/loop} +
{/loop} - -{loop name="category2" type="category" parent="1"} -

Final Exter 2 - SUBCATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)

+

PRODUCTS selected by ref

+{loop name="product" type="product" ref='REF1,REF2'} +

PRODUCT : #REF / #TITLE

+ #PRICE € {/loop}