* new ezcWorkflowConditionIsAnything,
* 'intVar' => new ezcWorkflowConditionAnd(
* array(
* new ezcWorkflowConditionIsInteger,
* new ezcWorkflowConditionIsGreatherThan( 0 )
* new ezcWorkflowConditionIsLessThan( 11 )
* )
* )
* );
*
* $input->addOutNode( $workflow->endNode );
* $workflow->startNode->addOutNode( $input );
* ?>
*
*
* @package Workflow
* @version 1.2rc1
*/
class ezcWorkflowNodeInput extends ezcWorkflowNode
{
/**
* Constructs a new input node.
*
* An input node accepts an array of workflow variables to accept
* and/or together with a condition on the variable if required.
*
* Each element in the configuration array must be either
* String: The name of the workflow variable to require. No conditions.
*
* or
*
* - Key: The name of the workflow variable to require.
* - Value: An object of type ezcWorkflowCondition
*
*
*
* @param mixed $configuration
* @throws ezcBaseValueException
*/
public function __construct( $configuration = '' )
{
if ( !is_array( $configuration ) )
{
throw new ezcBaseValueException(
'configuration', $configuration, 'array'
);
}
$tmp = array();
foreach ( $configuration as $key => $value )
{
if ( is_int( $key ) )
{
if ( !is_string( $value ) )
{
throw new ezcBaseValueException(
'workflow variable name', $value, 'string'
);
}
$variable = $value;
$condition = new ezcWorkflowConditionIsAnything;
}
else
{
if ( !is_object( $value ) || !$value instanceof ezcWorkflowCondition )
{
throw new ezcBaseValueException(
'workflow variable condition', $value, 'ezcWorkflowCondition'
);
}
$variable = $key;
$condition = $value;
}
$tmp[$variable] = $condition;
}
parent::__construct( $tmp );
}
/**
* Executes this node.
*
* @param ezcWorkflowExecution $execution
* @return boolean true when the node finished execution,
* and false otherwise
* @ignore
*/
public function execute( ezcWorkflowExecution $execution )
{
$variables = $execution->getVariables();
$canExecute = true;
foreach ( $this->configuration as $variable => $condition )
{
if ( !isset( $variables[$variable] ) )
{
$execution->addWaitingFor( $this, $variable, $condition );
$canExecute = false;
}
}
if ( $canExecute )
{
$this->activateNode( $execution, $this->outNodes[0] );
return parent::execute( $execution );
}
else
{
return false;
}
}
/**
* Generate node configuration from XML representation.
*
* @param DOMElement $element
* @return array
* @ignore
*/
public static function configurationFromXML( DOMElement $element )
{
$configuration = array();
foreach ( $element->getElementsByTagName( 'variable' ) as $variable )
{
$configuration[$variable->getAttribute( 'name' )] = ezcWorkflowDefinitionStorageXml::xmlToCondition( $variable->childNodes->item( 1 ) );
}
return $configuration;
}
/**
* Generate XML representation of this node's configuration.
*
* @param DOMElement $element
* @ignore
*/
public function configurationToXML( DOMElement $element )
{
foreach ( $this->configuration as $variable => $condition )
{
$xmlVariable = $element->appendChild(
$element->ownerDocument->createElement( 'variable' )
);
$xmlVariable->setAttribute( 'name', $variable );
$xmlVariable->appendChild(
ezcWorkflowDefinitionStorageXml::conditionToXml(
$condition, $element->ownerDocument
)
);
}
}
}
?>