Skip to content

Instantly share code, notes, and snippets.

@matiasmm
Created January 17, 2011 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save matiasmm/782443 to your computer and use it in GitHub Desktop.
Save matiasmm/782443 to your computer and use it in GitHub Desktop.
Workflow Definition O2C_invoice_goods_before_payment
<?php
require_once 'configurations.php';
class WfBuilder{
private $workflow;
private $process_steps = array();
function build_workflow(){
$this->workflow = new ezcWorkflow("O2C_invoice_goods_before_payment");
//Create Process steps(blue boxs) separetly.
$this->buildProcessSteps();
//Build the relations between process steps.
$this->connectProcessSteps();
return $this->workflow;
}
function buildProcessSteps(){
/**
* Order
*/
$this->process_steps['fill_cart'] = new ezcWorkflowNodeInput(array(
'continue_from_fill_cart' => new ezcWorkflowConditionIsTrue(),
));
$this->process_steps['create_sales_order'] = new ezcWorkflowNodeInput(array(
'continue_from_create_sales_order' => new ezcWorkflowConditionIsTrue(),
));
$this->process_steps['create_invoice'] = new ezcWorkflowNodeInput(array(
'continue_from_create_invoice' => new ezcWorkflowConditionIsTrue(),
));
/**
* Payment
*/
$this->process_steps['3th_party_payment'] = new ezcWorkflowNodeInput(array(
'continue_from_3th_party_payment' => new ezcWorkflowConditionIsTrue(),
'is_payment_ok' => new ezcWorkflowConditionIsBool(),
));
$this->process_steps['notify_customer'] = new ezcWorkflowNodeInput(array(
'continue_from_notify_customer' => new ezcWorkflowConditionIsTrue(),
));
/**
* Ship
*/
$this->process_steps['prepare_in_warehouse'] = new ezcWorkflowNodeInput(array(
'continue_from_prepare_in_warehouse' => new ezcWorkflowConditionIsTrue(),
));
$this->process_steps['request_shipment_service'] = new ezcWorkflowNodeInput(array(
'continue_from_request_shipment_service' => new ezcWorkflowConditionIsTrue(),
));
$this->process_steps['ship'] = new ezcWorkflowNodeInput(array(
'continue_from_ship' => new ezcWorkflowConditionIsTrue(),
));
}
function connectProcessSteps(){
$this->workflow->startNode->addOutNode($this->process_steps['fill_cart']);
$this->process_steps['fill_cart']->addOutNode($this->process_steps['create_sales_order']);
$this->process_steps['create_sales_order']->addOutNode($this->process_steps['create_invoice']);
$merge = new ezcWorkflowNodeSimpleMerge();
$merge->addInNode($this->process_steps['create_invoice']);
$merge->addInNode($this->process_steps['notify_customer']);
$merge->addOutNode($this->process_steps['3th_party_payment']);
$this->process_steps['3th_party_payment']->addOutNode($is_payment_ok = new ezcWorkflowNodeExclusiveChoice());
$is_payment_ok->addConditionalOutNode(
new ezcWorkflowConditionVariable('is_payment_ok', new ezcWorkflowConditionIsTrue()),
$this->process_steps['prepare_in_warehouse'], //else
$this->process_steps['notify_customer']
);
$this->process_steps['prepare_in_warehouse']->addOutNode($this->process_steps['request_shipment_service']);
$this->process_steps['request_shipment_service']->addOutNode($this->process_steps['ship']);
$this->workflow->endNode->addInNode($this->process_steps['ship']);
}
/**
* After this
* in Linux: dot -Tpng -ograph.png graph.dot
*/
function toGraphViz(){
$visitor = new ezcWorkflowVisitorVisualization();
$this->workflow->accept( $visitor );
$dir = dirname(__FILE__) . '/graph.dot';
file_put_contents($dir , (string)$visitor);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment