\ValidFormBuilderCondition

Condition class

A condition object is a set of one or more comparisons. Don't use the Condition object as a standalone, rather use the element's \ValidFormBuilder\Base::addCondition() method.

Example; Basic yes-no condition

$objCheck = $objForm->addField("yesno", "Yes or No", ValidForm::VFORM_RADIO_LIST);
$objYes = $objCheck->addField("Yes", "yes");
$objCheck->addField("No", "no");

$objText = $objForm->addField(
    "textfield",
    "Text here",
    ValidForm::VFORM_TEXT,
    array("required" => "true"),
    array("required" => "This field is required"),
    array("fielddisabled" => "disabled")
);
$objText->addCondition("enabled", true, array(
    new Comparison($objYes, ValidForm::VFORM_COMPARISON_EQUAL, "yes")
));

Example 2; Hide field when other field has predefined value

$objFirstName = $objForm->addField('firstname', 'First name', ValidForm::VFORM_STRING);
$objLastName = $objForm->addField('lastname', 'Last name', ValidForm::VFORM_STRING);
$objLastName->addCondition(
    'visible', // Last name will become
    false, // 'not visible' (visible -> false)
    array(
        // When field $objFirstName 'is equal to' Robin
        new \ValidFormBuilder\Comparison($objFirstName, ValidForm::VFORM_COMPARISON_EQUAL, 'Robin')
    )
);

Example 3; Trigger condition with comparison that doesn't need a value

$objFirstName = $objForm->addField('firstname', 'First name', ValidForm::VFORM_STRING);
$objLastName = $objForm->addField('lastname', 'Last name', ValidForm::VFORM_STRING);
$objFirstName->addCondition(
    'enabled', // First Name will be
    false, // 'disabled' (enabled -> false)
    array(
        // When field $objLastName 'is not empty'
        // (note that we cal leave out the third 'value' parameter in this case)
        new \ValidFormBuilder\Comparison($objLastName, ValidForm::VFORM_COMPARISON_NOT_EMPTY)
    )
);

Summary

Methods
Properties
Constants
__get()
__set()
__call()
__construct()
getSubject()
getProperty()
getValue()
getComparisons()
getComparisonType()
addComparison()
isMet()
jsonSerialize()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

__get()

__get(string  $property) 

Magic getter method

Parameters

string $property

Throws

\BadMethodCallException

__set()

__set(string  $property, mixed  $value) 

Magic setter method

Parameters

string $property
mixed $value

Throws

\BadMethodCallException

__call()

__call(string  $method, mixed  $values) 

Magic caller method

Parameters

string $method
mixed $values

Throws

\BadMethodCallException

__construct()

__construct(\ValidFormBuilder\Base  $objField, string  $strProperty, boolean  $blnValue = null, string  $strComparisonType = \ValidFormBuilder\ValidForm::VFORM_MATCH_ANY) 

Create new Condition

Parameters

\ValidFormBuilder\Base $objField

The target field to apply this condition on

string $strProperty

The property to trigger on the subject; enabled, visible or required

boolean $blnValue

The boolean to set the property with. E.g. when property is required and value is false, the field will become optional when the condition is met.

string $strComparisonType

The comparison type

Throws

\InvalidArgumentException

If $objField is no object or $strProperty is no predefined property.

getSubject()

getSubject() : \ValidFormBuilder\Base

Get subject value

Returns

\ValidFormBuilder\Base

Subject element

getProperty()

getProperty() : string

Get Property

Returns

string

getValue()

getValue() : boolean

Get value

Returns

boolean

getComparisons()

getComparisons() : array

Get comparisons collection

Returns

array

getComparisonType()

getComparisonType() : string

Get comparison type

Returns

string

addComparison()

addComparison(\ValidFormBuilder\Comparison|array  $varComparison) 

Add new comparison to Condition

Parameters

\ValidFormBuilder\Comparison|array $varComparison

Comparison array or Comparison object

Throws

\Exception

if Reflection couldn't initialize new Comparison object

\InvalidArgumentException

if no valid Comparison data is supplied

isMet()

isMet(integer  $intDynamicPosition) : boolean

Verify if the condition is met

Parameters

integer $intDynamicPosition

Dynamic position of the field to verify

Throws

\Exception

Returns

boolean —

True if it is met, false if not

jsonSerialize()

jsonSerialize(integer|null  $intDynamicPosition = null) : array

toJson method creates an array representation of the current condition object and all of it's comparions.

In the future this class should extend the JsonSerializable interface (http://php.net/manual/en/class.jsonserializable.php). Since this is only supported in PHP >= 5.4, we now use our own implementation.

Parameters

integer|null $intDynamicPosition

Returns

array —

An array representation of this object and it's comparisons.