new types

This commit is contained in:
Etienne Roudeix
2013-07-03 10:52:24 +02:00
parent 32f1fb3441
commit 92d15d44c7
7 changed files with 214 additions and 32 deletions

View File

@@ -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

View File

@@ -0,0 +1,48 @@
<?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\Tests\Type;
use Thelia\Type\AlphaNumStringListType;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
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€'));
}
}

View File

@@ -0,0 +1,43 @@
<?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\Tests\Type;
use Thelia\Type\AlphaNumStringType;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
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'));
}
}

View File

@@ -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')));

View File

@@ -0,0 +1,52 @@
<?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\Type;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
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;
}
}

View File

@@ -0,0 +1,47 @@
<?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\Type;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
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;
}
}

View File

@@ -1,39 +1,25 @@
{include file="included.html"}
{loop name="category0" type="category" parent="0"}
<h2>Out before - CATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)</h2>
<h2>CATEGORY : #TITLE</h2>
{loop name="category1" type="category" parent="#ID"}
<h3>Inner - SUBCATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)</h3>
<hr />
<h3>SUBCATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)</h3>
{loop name="product" type="product" category="#ID"}
<h3>PRODUCT : #REF / #TITLE</h3>
#PRICE €
{/loop}
<hr />
<hr />
{/loop}
{#myid=#ID}
{loop name="category2" type="category" parent="#ID"}
<h3>Inner 2 before - SUBCATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)</h3>
{loop name="category3" type="category" parent="#myid"}
<h3>Inner inner 2 - SUBCATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)</h3>
{/loop}
<h3>Inner 2 after - SUBCATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)</h3>
{loop name="product" type="product" category="#ID"}
<h3>PRODUCT : #REF / #TITLE</h3>
#PRICE €
{/loop}
<h2>Out after - CATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)</h2>
<hr />
{ifloop rel="category2"}
<p>Hey, y'a d'la categorie 2 !</p>
{/ifloop}
{elseloop rel="category2"}
<p>Hey, y'a PAS de categorie 2 !</p>
{/elseloop}
{loop name="category2" type="category" parent="#myid"}
<h3>Exter 2 - SUBCATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)</h3>
{/loop}
<hr />
{/loop}
{loop name="category2" type="category" parent="1"}
<h3>Final Exter 2 - SUBCATEGORY : #TITLE (#LOOP_COUNT / #LOOP_TOTAL)</h3>
<h2>PRODUCTS selected by ref</h2>
{loop name="product" type="product" ref='REF1,REF2'}
<h3>PRODUCT : #REF / #TITLE</h3>
#PRICE €
{/loop}