Permalink
Browse files

Work in progress

  • Loading branch information...
1 parent ce9c75b commit e78bbf204833797d1e0a7b0cec23b55957baec03 @jeremyFreeAgent committed Jun 14, 2012
Showing with 51 additions and 14 deletions.
  1. +6 −0 DependencyInjection/Configuration.php
  2. +38 −14 Manager/Manager.php
  3. +7 −0 README.md
@@ -28,6 +28,12 @@ public function getConfigTreeBuilder()
->prototype('array')
->children()
->scalarNode('default_step')->end()
+ ->arrayNode('actions')
+ ->prototype('scalar')->end()
+ ->end()
+ ->arrayNode('validations')
+ ->prototype('scalar')->end()
+ ->end()
->arrayNode('steps')
->useAttributeAsKey('id')
->prototype('array')
View
@@ -19,6 +19,8 @@ class Manager
protected $validationErrors = array();
protected $defaultStep;
protected $steps;
+ protected $actions = array();
+ protected $validations = array();
/**
* [__construct description]
@@ -64,6 +66,8 @@ public function configureWorkflow($workflowName)
}
$this->defaultStep = new Step($defaultStep, $this->workflow['steps'][$defaultStep]);
+ $this->actions = array_key_exists('actions', $this->workflow) ? $this->workflow['actions'] : array();
+ $this->validations = array_key_exists('validations', $this->workflow) ? $this->workflow['validations'] : array();
return $this->getSteps();
}
@@ -141,7 +145,7 @@ public function getCurrentStepName()
*/
public function reachStep($stepName, $stepComment = '', $stepAt = null)
{
- if ($this->canReachStep($stepName)){
+ if ($this->canReachStep($stepName)) {
$this->getModel()->setWorkflowStepName($stepName);
$this->getModel()->setWorkflowStepComment(trim($stepComment));
@@ -151,6 +155,8 @@ public function reachStep($stepName, $stepComment = '', $stepAt = null)
$this->canReachStep = array();
+ // TODO : Run global actions;
+
return true;
}
@@ -175,21 +181,39 @@ public function canReachStep($stepName)
if ($currentStep->hasPossibleNextStep($stepToReach->getName())) {
- if (!$stepToReach->hasValidations()) {
- $this->canReachStep[$stepToReach->getName()] = true;
- } else {
- foreach ($stepToReach->getValidations() as $validation) {
- $validation = $this->getValidation($validation);
-
- try {
- $validation->validate($this->getModel());
- $this->canReachStep[$stepToReach->getName()] = true;
- } catch (ValidationException $e) {
- $this->validationErrors[$stepToReach->getName()][] = $e->getMessage();
- $this->canReachStep[$stepToReach->getName()] = false;
+ // TODO : check this !
+ // $preValidationSuccess = true;
+ // if ($this->hasValidations()) {
+ // foreach ($this->getValidations() as $validation) {
+ // $validation = $this->getValidation($validation);
+
+ // try {
+ // $validation->validate($this->getModel());
+ // } catch (ValidationException $e) {
+ // $this->validationErrors[$stepToReach->getName()][] = $e->getMessage();
+ // $preValidationSuccess = false;
+ // }
+ // }
+ // }
+
+ // if ($preValidationSuccess) {
+ if (!$stepToReach->hasValidations()) {
+
+ $this->canReachStep[$stepToReach->getName()] = true;
+ } else {
+ foreach ($stepToReach->getValidations() as $validation) {
+ $validation = $this->getValidation($validation);
+
+ try {
+ $validation->validate($this->getModel());
+ $this->canReachStep[$stepToReach->getName()] = true;
+ } catch (ValidationException $e) {
+ $this->validationErrors[$stepToReach->getName()][] = $e->getMessage();
+ $this->canReachStep[$stepToReach->getName()] = false;
+ }
}
}
- }
+ // }
}
}
}
View
@@ -31,6 +31,13 @@ free_agent_workflow:
workflows:
example:
default_step: draft
+ validations:
+ - free_agent_workflow.validation.pre_validation
+ - free_agent_workflow.validation.pre_validation
+ actions:
+ - free_agent_workflow.action.post_action
+ - free_agent_workflow.action.post_action
+ - free_agent_workflow.action.post_action
steps:
draft:
label: Draft

0 comments on commit e78bbf2

Please sign in to comment.