Added a new loop argument type to pass either true (1), false (0) or
both (*). Useful for visible argument for example.
This commit is contained in:
@@ -73,7 +73,7 @@ class Category extends BaseLoop
|
||||
Argument::createIntTypeArgument('parent'),
|
||||
Argument::createBooleanTypeArgument('current'),
|
||||
Argument::createBooleanTypeArgument('not_empty', 0),
|
||||
Argument::createBooleanTypeArgument('visible', 1),
|
||||
Argument::createBooleanOrBothTypeArgument('visible', 1),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
@@ -122,7 +122,8 @@ class Category extends BaseLoop
|
||||
$search->filterById($exclude, Criteria::NOT_IN);
|
||||
}
|
||||
|
||||
$search->filterByVisible($this->getVisible() ? 1 : 0);
|
||||
if ($this->getVisible() != '*')
|
||||
$search->filterByVisible($this->getVisible() ? 1 : 0);
|
||||
|
||||
$orders = $this->getOrder();
|
||||
|
||||
|
||||
53
core/lib/Thelia/Type/BooleanOrBothType.php
Normal file
53
core/lib/Thelia/Type/BooleanOrBothType.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* This filter accepts either a boolean value, or '*' which means both, true and false
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
|
||||
class BooleanOrBothType implements TypeInterface
|
||||
{
|
||||
|
||||
const ANY = '*';
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return 'Boolean or both type';
|
||||
}
|
||||
|
||||
public function isValid($value)
|
||||
{
|
||||
return $value === self::ANY || filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null;
|
||||
}
|
||||
|
||||
public function getFormattedValue($value)
|
||||
{
|
||||
if ($value === self::ANY) return $value;
|
||||
|
||||
return $value === null ? null : filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user